TCP数据报的报文格式

下图显示了TCP数据报的报文格式。

TCP数据报的报文格式

用 C++ 语言定义它的源代码如下:

typedef struct tcp_hdr		// 定义 TCP 首部
{
	USHORT	th_sport;		// 16 位源端口
	USHORT	th_dport;		// 16 位目的端口
	unsigned int th_seq;	// 32 位序列号
	unsigned int th_ack;	// 32 位确认号
	unsigned char th_lenres;	// 4 位首部长度,6 位保留字
	unsigned char th_flag;		// 6 位标志位
	USHORT th_win;				// 16 位窗口大小 
	USHORT th_sum;				// 16 位校验和
	USHORT th_urp;				// 16 位紧急数据偏移量
} TCPHEADER;

Add comment

Loading