Today, we use Winpcap to intercept ARP packets. As a result, the IP address output by ARP and the MAC address format are always faulty.
The structure of ARP is defined as follows:
Struct ARP <br/>{< br/> unsigned short htype; <br/> unsigned short ptype; <br/> unsigned char hlen; <br/> unsigned char Plen; <br/> unsigned short regular; <br/> unsigned char destmac [6]; <br/> unsigned long spa; <br/> unsigned char sourcemac [6]; <br/> unsigned long TPA; <br/> };
Use printf ("% d/N", sizeof (struct ARP ));
The size of the output struct is 32 instead of 28, so an error occurs when the MAC address and IP address are output.
I checked a lot online and finally usedForced structure compact space allocation
InProgramStart, add
# Pragma pack (1)
Then, the size of the ARP structure is 28, and the Mac and IP addresses of ARP are output. The result is correct!