Hello,
I have been trying to serialize and deserialize an ARP packet encapsulated in VLAN tagged Ethernet frame. While serialization seems to be working correctly I have been struggling with deserialization bit.
Please have a look at the code snipped below. After deserialization the pArp pointer is NULL. Could you please point out what I am doing wrong?
Many thanks in advance,
Daniel B
-------------------------------------------------------------------------------------
Ethernet ethHeader;
ethHeader.SetDestinationMAC("01:01:01:01:01:01");
ethHeader.SetSourceMAC("02:02:02:02:02:02");
Dot1Q vlan;
vlan.SetDEI(0);
vlan.SetPCP(0);
vlan.SetVID(1000);
ARP arp;
arp.SetHardwareType(1);
arp.SetProtocolType(IP::PROTO);
arp.SetHardwareLength(6);
arp.SetProtocolLength(4);
arp.SetOperation(ARP::Reply);
arp.SetSenderMAC("03:03:03:03:03:03");
arp.SetSenderIP("4.4.4.4");
arp.SetTargetMAC("05:05:05:05:05:05");
arp.SetTargetIP("6.6.6.6");
Packet packetA;
packetA.PushLayer(ethHeader);
packetA.PushLayer(vlan);
packetA.PushLayer(arp);
unsigned char buf[100];
packetA.Craft();
unsigned short len = packetA.GetData(buf);
Packet packetB;
packetB.PacketFromEthernet(buf, len);
Ethernet* pEth = packetB.GetLayer<Ethernet>();
Dot1Q* pVlan = packetB.GetLayer<Dot1Q>();
ARP* pArp = packetB.GetLayer<ARP>();
unsigned short vid = pVlan->GetVID();
string ip = pArp->GetTargetIP();
-------------------------------------------------------------------------------------