以太帧头格式结构体,共14个字节:
typedef struct ether_header {
unsigned char ether_dhost[6]; //目的MAC地址
unsigned char ether_shost[6]; //源MAC地址
unsigned short ether_type; //协议类型
}ETHHEADER,*PETHHEADER;
IPv4报头格式结构体,共20个字节:
typedef struct ipv4_header {
unsigned char ver_ihl; //版本 (4 bits) + 首部长度 (4 bits)
unsigned char tos; //服务类型
unsigned short tlen; //数据报总长度
unsigned short identification; //标识
unsigned short flags_fo; //标志 (3 bits) + 片偏移 (13 bits)
unsigned char ttl; //生存时间
unsigned char proto; //协议
unsigned short crc; //首部校验和
u_char ip_src[4]; //源IP地址
u_char ip_dst[4]; //目的IP地址
}IPHEADER,*PIPHEADER;
IPv6报头格式结构体,共40个字节:
typedef struct ipv6_header {
u_char ver_tf; //版本号(4 bit)
u_char traffic; //优先级(8 bit)
u_short label; //流标识(20 bit)
u_char length[2]; //报文长度(16 bit)
u_char next_header; //下一头部(8 bit)
u_char limits; //跳数限制(8 bit)
u_char Srcv6[16]; //源IPv6地址(128 bit)
u_char Destv6[16]; //目的IPv6地址(128 bit)
}IPv6_HEADER,*PIPv6_HEADER;
TCP报头格式结构体,共20个字节:
typedef struct tcp_header {
WORD SourPort; //源端口号
WORD DestPort; //目的端口号
DWORD SeqNo; //序号
DWORD AckNo; //确认序号
BYTE HLen; //首部长度(保留位)
BYTE Flag; //标识(保留位)
WORD Window; //窗口大小
WORD ChkSum; //校验和
WORD UrgPtr; //紧急指针
}TCPHEADER,*PTCPHEADER;
UDP报头格式结构体,共8个字节:
typedef struct udp_header {
u_short sport; //源端口号
u_short dport; //目的端口号
u_short len; //数据报长度
u_short crc; //校验和
}UDPHEADER,*PUDPHEADER;
typedef struct ether_header {
unsigned char ether_dhost[6];
unsigned char ether_shost[6];
unsigned short ether_type;
}ETHHEADER,*PETHHEADER;
IPv4报头格式结构体,共20个字节:
unsigned char ver_ihl;
unsigned char tos;
unsigned short tlen;
unsigned short identification;
unsigned short flags_fo;
unsigned char proto;
unsigned short crc;
u_char ip_src[4];
u_char ip_dst[4];
IPv6报头格式结构体,共40个字节:
typedef struct ipv6_header {
u_char ver_tf;
u_char traffic;
u_short label;
u_char length[2];
u_char next_header;
u_char limits;
u_char Srcv6[16];
u_char Destv6[16];
}IPv6_HEADER,*PIPv6_HEADER;
TCP报头格式结构体,共20个字节:
typedef struct tcp_header {
WORD SourPort;
WORD DestPort;
DWORD SeqNo;
DWORD AckNo;
BYTE HLen;
BYTE Flag;
WORD Window;
WORD ChkSum;
WORD UrgPtr;
}TCPHEADER,*PTCPHEADER;
UDP报头格式结构体,共8个字节:
typedef struct udp_header {
u_short sport;
u_short dport;
u_short len;
u_short crc;
}UDPHEADER,*PUDPHEADER;