Definition of ARP struct

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.