tcp头部分析

tcp头部如下图 

依次是
源端口号:16位
目标端口号:16位
seq号:32位, seq, 这个报文对应的序列号。
ack号:32位, ack_seq, 告诉对端自己下一个接收的新包的开始序列号。
首部长度(doff):4位,最大值为15。单位为4字节,即首部最大长度为60字节.
保留字段(res1):4位
标志位:
   CWR: Congestion Window Reduced (the sender reduced its sending rate)
   ECE: ECN Echo (the sender received an earlier congestion notification)
   URG: Urgent (the Urgent Pointer field is valid—rarely used)
   ACK: Acknowledgment (the Acknowledgment Number field is valid—always on after a
connection is established)
   PSH: Push (the receiver should pass this data to the application as soon as possible—not
reliably implemented or used)
   RST: Reset the connection (connection abort, usually because of an error)
   SYN: Synchronize sequence numbers to initiate a connection; 
   FIN: The sender of the segment is finished sending data to its peer;
窗口大小(windown):16位,最大值为65535。单位为字节,即最大窗口为65535字节
检验和(check):16位。检验和覆盖了整个tcp报文,是一个强制性字段,一定是由发送端计算和存储,并由接收端进行验证。
紧急指针(urg_ptr):16位。当标志位URG为1时,紧急指针表示一个正的偏移量,加上seq表示紧急数据的最后一个字节。

linux中定义如下。

// linux-4.14 include/uapi/linux/tcp.h
struct tcphdr {
	__be16	source;
	__be16	dest;
	__be32	seq;
	__be32	ack_seq;
#if defined(__LITTLE_ENDIAN_BITFIELD)
	__u16	res1:4,
		doff:4,
		fin:1,
		syn:1,
		rst:1,
		psh:1,
		ack:1,
		urg:1,
		ece:1,
		cwr:1;
#elif defined(__BIG_ENDIAN_BITFIELD)
	__u16	doff:4,
		res1:4,
		cwr:1,
		ece:1,
		urg:1,
		ack:1,
		psh:1,
		rst:1,
		syn:1,
		fin:1;
#else
#error	"Adjust your <asm/byteorder.h> defines"
#endif	
	__be16	window;
	__sum16	check;
	__be16	urg_ptr;
};

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值