ARP C数据结构
2023-07-19
5
0
使用C/C++语言,我们可以定义ARP的数据结构如下:
#pragma pack(1)
//以太网头
#define ETH_ALEN (6)
typedef struct _ETH_HEADER
{
unsigned char DstAddr[ETH_ALEN];
unsigned char SrcAddr[ETH_ALEN];
unsigned short EthType;
} ETH_HEADER, *PETH_HEADER;
typedef struct _ARP_HDR
{
ETH_HEADER;//根据实际使用习惯可选择注释掉
unsigned short hwtype;
unsigned short protype;
unsigned char hwsize;
unsigned char prosize;
unsigned short opcode;
}ARP_HDR, *PARP_HDR;
#pragma pack()
这里的
#pragma pack(1)
强制结构体进行一字节对齐,结构体定义完毕后,使用#pragma pack()
恢复默认字节对齐。