宏定义
#define EPT_IP 0x0800 /* type: IP */
#define EPT_ARP 0x0806 /* type: ARP */
#define EPT_RARP 0x8035 /* type: RARP */
#define ARP_HARDWARE 0x0001 /* Dummy type for 802.3 frames */
#define ARP_REQUEST 0x0001 /* ARP request */
#define ARP_REPLY 0x0002 /* ARP reply */
定义以太网首部
typedef struct ehhdr
{
unsigned char eh_dst[6];
unsigned char eh_src[6];
unsigned short eh_type;
}EHHDR, *PEHHDR;
定义以太网arp字段
typedef struct arphdr
{
unsigned short arp_hrd;
unsigned short arp_pro;
unsigned char arp_hln;
unsigned char arp_pln;
unsigned short arp_op;
unsigned char arp_sha[6];
unsigned long arp_spa;
unsigned char arp_tha[6];
unsigned long arp_tpa;
}ARPHDR, *PARPHDR;
定义整个arp报文包,总长度42字节
typedef struct arpPacket
{
EHHDR ehhdr;
ARPHDR arphdr;
} ARPPACKET, *PARPPACKET;
定义ip报头数据结构
typedef struct _iphdr
{
byte ver_len;
byte type;
byte length[2];
byte id[2];
byte flag_offset[2];
byte time;
byte protocol;
byte crc_val[2];
byte src_addr[4];
byte tar_addr[4];
byte options[4];
}IP_HEADER;
定义TCP报头
typedef struct _tcphdr
{
byte source_port[2];
byte dest_port[2];
byte sequence_no[4];
byte ack_no[4];
byte offset_reser_con[2];
byte window[2];
byte checksum[2];
byte urgen_pointer[2];
byte options[3];
}TCP_HEADER;
定义伪首部
struct{
unsigned long saddr;
unsigned long daddr;
char mbz;
char ptcl;
unsigned short tcpl;
}psd_header;