www.pudn.com > getNic_p.rar > constDefine.h
# include# ifndef __CONSTDEFINE_H__ # define __CONSTDEFINE_H__ const int MAX_STRING_SIZE = 256 ; // 最大的字符串长度 const int MAX_PACKET_SIZE = 68 ; // 所捕获的最大包长度 #define ARP 0x0806 #define ICMP 1 #define IP 0x0800 #define RARP 0x8035 #define TCP 6 #define UDP 17 #define UNKNOWN 0 struct eth_hdr // 以太网包结构 { u_char eth_dhost[6]; /*以太网目的地址*/ u_char eth_shost[6]; /*以太网源地址*/ u_short eth_type; /*类型字段*/ }; struct ip_addr{ u_char addr[4]; }; struct ip_hdr{ u_char ip_ver_len ; /*version */ // u_char ip_hdr_len:4; /* header length*/ u_char ip_tos; /*type of service*/ u_short ip_len; /*数据部分的长度*/ u_short ip_id; /*数据包ID*/ u_short ip_off; /*偏移量*/ u_char ip_ttl; /*生存时*/ u_char ip_protocol; /*type of protocol*/ u_short ip_checksum; /*校验和*/ struct ip_addr ip_saddr; struct ip_addr ip_daddr; };//ip_hdr定义了一个IP报的格式 struct arp_hdr { u_short arp_hrd ; // 硬件类型 u_short arp_pro ; // 协议类型 u_char arp_hln ; // 硬件地址长度 u_char arp_pln ; // 协议地址长度 u_short arp_optr ; // 操作 u_char arp_sha[6] ; // 源硬件地址 ip_addr arp_spa ; // 源协议地址 u_char arp_tha[6]; // 目标硬件地址 ip_addr arp_tpa ; // 目标协议地址 } ; struct tcp_hdr { u_short tcp_sport; //源端口号 u_short tcp_tport;//目的端口号 u_int tcp_seq;//32位序列号 u_int tcp_ack;//32位确认序号 u_char tcp_hln_res ; // 4比特的首部长度,6比特的保留字段 u_char tcp_flags;// Flag (低6比特 ) u_short tcp_win;//窗口大小 u_short tcp_check;//校验和 u_short tcp_urgent;//紧急指针 } ; # endif