本文主要是介绍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;
};
这篇关于tcp头部分析的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!