gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 08:44:57 27 4
gpt4 key购买 nike

在 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-bitintegers, and the 1's complement sum of these 16-bit integers isformed.

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

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

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

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com