下面这些TCP/IP数据包是我在进行Socket及Wipcap网络编程过程中曾经用到过的数据包结构体, 这些东西平时看起来不起眼,真正用到的时候就会觉得非常有用......
以太帧头格式结构体,共14个字节:
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;
TCP/IP各种数据包结构体
最新推荐文章于 2024-07-18 11:45:32 发布
原文地址:TCP/IP各种数据包结构体
作者:tota2004