在 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/