TCP协议详解-IPv4

TCP协议简介:https://blog.csdn.net/hzp666/article/details/73480514

数据包报文结构:https://www.jianshu.com/p/19e8e93665af

UDP包:如果有分包,主包和从包的结构不同。例:如果使用以太网,主包会有UDP包头,从包不会有。主包和从包的ID相同。

WinPcap(捕获网络数据包)说明文档:http://www.ferrisxu.com/WinPcap/html/index.html

C++调用WinPcap :https://www.cnblogs.com/luxiaoxun/archive/2012/08/05/2623641.html

 

/* 4字节的IP地址 */
typedef struct ip_address {
	u_char byte1;
	u_char byte2;
	u_char byte3;
	u_char byte4;
}ip_address;

/* IPv4 首部 */
typedef struct ip_header {
	u_char  ver_ihl;        // 版本 (4 bits) + 首部长度 (4 bits)
	u_char  tos;            // 服务类型(Type of service) 
	u_short tlen;           // 总长(Total length) 
	u_short identification; // 标识(Identification)
	u_short flags_fo;       // 标志位(Flags) (3 bits) + 段偏移量(Fragment offset) (13 bits)
	u_char  ttl;            // 存活时间(Time to live)
	u_char  proto;          // 协议(Protocol)
	u_short crc;            // 首部校验和(Header checksum)
	ip_address  saddr;      // 源地址(Source address)
	ip_address  daddr;      // 目的地址(Destination address)
	u_int   op_pad;         // 选项与填充(Option + Padding)
}ip_header;

/* UDP 首部*/
typedef struct udp_header {
	u_short sport;          // 源端口(Source port)
	u_short dport;          // 目的端口(Destination port)
	u_short len;            // UDP数据包长度(Datagram length)
	u_short crc;            // 校验和(Checksum)
}udp_header;

  

posted on 2021-10-19 09:45  林西索  阅读(224)  评论(0编辑  收藏  举报