c++ - 在 ICMP 报头校验和计算中?

标签 c++ c networking packet icmp

在 ICMP header 中,他们用以下语句填充校验和

我发现 ICMP_ECHO 值为 8

 icmp->checksum = htons(~(ICMP_ECHO << 8));

谁能告诉我它到底会做什么以及如何填充校验和的细节

最佳答案

ICMP校验和是 RFC 1071 checksum :

(1) Adjacent octets to be checksummed are paired to form 16-bit integers, and the 1's complement sum of these 16-bit integers is formed.

(2) To generate a checksum, the checksum field itself is cleared, the 16-bit 1's complement sum is computed over the octets concerned, and the 1's complement of this sum is placed in the checksum field.

对于 ICMP_ECHO 消息(类型 8,代码 0),类型和代码字段应为 0x08 0x00,如果这是消息包含的所有数据,那么这也是 16应构成校验和的位整数。

关于c++ - 在 ICMP 报头校验和计算中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22066650/

相关文章:

c++ - 基于模板参数递归重载

c++ - 使用 SFINAE 但不要产生编译错误

c++ - 如何将 boost::Makevariantover 转换为 vector

c - 实现忙循环的最佳方式?

C编程: Replacing if statements

c++ - 在 tcp 中提升 asio 异步处理程序

c++ - 令人费解的非尾随参数包行为

c - 后面添加一个链表

java - 以编程方式发现本地网络设备和 IO

c++ - 文件同步库