tcp校验和
2016-03-10 22:51
549 查看
伪首部(pseudo header),通常指TCP伪首部和UDP伪首部
TCP的校验和是必需的,而UDP的校验和是可选的
TCP校验是需要校验包头和数据的
伪首部是一个虚拟的数据结构,仅仅是为计算校验和
接收方计算检验和错误,IP就丢弃收到的数据报
RFC 793的TCP校验和定义
The checksum field is the 16 bit one’s complement of the one’s complement sum of all 16-bit words in the header and text.
If a segment contains an odd number of header and text octets to be checksummed, the last octet is padded on the right
with zeros to form a 16-bit word for checksum purposes. The pad is not transmitted as part of the segment. While computing
the checksum, the checksum field itself is replaced with zeros
如果总长度为奇数个字节,则在最后增添一位都为0的字节
首先,把TCP报头中的校验和字段置为0
其次,用反码相加法累加所有的16位字
最后,对计算结果取反
详细计算方法见ip校验和:
/article/11667198.html
举例
注:tcpl指的是tcp包头和数据的总长度(网络字节序)
TCP的校验和是必需的,而UDP的校验和是可选的
TCP校验是需要校验包头和数据的
//共12字节 typedef struct { unsigned long saddr; //源IP地址 unsigned long daddr; //目的IP地址 unsigned char mbz; // mbz = must be zero, 用于填充对齐 unsigned char protocal; //8位协议号 unsigned short tcpl; //TCP包长度 }psdheader_t;
伪首部是一个虚拟的数据结构,仅仅是为计算校验和
接收方计算检验和错误,IP就丢弃收到的数据报
RFC 793的TCP校验和定义
The checksum field is the 16 bit one’s complement of the one’s complement sum of all 16-bit words in the header and text.
If a segment contains an odd number of header and text octets to be checksummed, the last octet is padded on the right
with zeros to form a 16-bit word for checksum purposes. The pad is not transmitted as part of the segment. While computing
the checksum, the checksum field itself is replaced with zeros
如果总长度为奇数个字节,则在最后增添一位都为0的字节
首先,把TCP报头中的校验和字段置为0
其次,用反码相加法累加所有的16位字
最后,对计算结果取反
详细计算方法见ip校验和:
/article/11667198.html
举例
本地IP: 0xc0 0xa8 0x9f 0x01 对方IP: 0xc0 0xa8 0x9f 0x82 TCP字段: 0x04 0xc6 0x87 0x01 0x4b 0xd7 0x89 0x9f 0x4e 0x3b 0x90 0xae 0x50 0x18 0xff 0xff 0xeb 0x69 0x00 0x00 (0xc0a8 + 0x9f01 + 0xc0a8 + 0x9f82 + 0x0006 + 0x0017) + 0x04c6 + 0x8701 + 0x4bd7 + 0x899f + 0x4e3b + 0x90ae + 0x5018 + 0xffff + 0x0000 + 0x0000 + 0x6162 + 0x6300 = 0x7148f 0x0007 + 0x148f = 0x1496 ~0x1496 = 0xeb69
注:tcpl指的是tcp包头和数据的总长度(网络字节序)
相关文章推荐
- 结合网页排名来做社会网络分析,挖掘核心人物
- 阻塞,非阻塞connect()和accept()
- AFNetworking3.0 如何取消单个网络请求
- 对计算机网络的一些认识
- OSI(Open System Interconnection)网络模型
- 火狐浏览器中添加httprequest的方法
- 学习UNITY3D网络插件photon pun和PhotonServer<三>
- 学习UNITY3D网络插件photon pun和PhotonServer<一>
- 学习UNITY3D网络插件photon pun和PhotonServer<二>
- Php和httpd.conf的配置
- 网络架构 :七层协议解读
- 第五天 HttpClient(get post)多线程下载 (xutils)
- 图解HTTP学习(3):返回结果的HTTP状态码
- 卷积神经网络
- 图解HTTP学习(2):简单的HTTP协议
- 网络流量监控与分析工具 ntop
- Android检测手机是否有网络连接可用
- 图解HTTP学习(1):Web及网络基础
- Nginx为什么比Apache Httpd高效:原理篇
- tcpdump:网络数据采集分析工具