udp - 通过Wireshark验证Checksum值

标签 udp wireshark checksum

我试图通过使用 Wireshark 检查数据包来验证 UDP 数据包校验和值的有效性。 在我正在查看的这个特定数据包中,UDP header 的值如下:

源端口:53 (0000 0000 0011 0101)

目标端口:64992 (1111 1101 1110 0000)

长度:64 (0000 0000 0100 0000)

现在,如果将这些值相加,总和为 65109 (1111 1110 0101 0101)

因此,我希望校验和值为 426 (0001 1010 1010),它是总和的 1 补码。

但是在Wireshark中,校验和值为0x63c7,并且它表示这个校验和是正确的。

我想知道我哪里错了。 任何帮助或插入正确的方向将不胜感激。

提前致谢。

最佳答案

如果您引用RFC 768 ,您将找到正确计算校验和所需的详细信息:

Checksum is the 16-bit one's complement of the one's complement sum of a
pseudo header of information from the IP header, the UDP header, and the
data,  padded  with zero octets  at the end (if  necessary)  to  make  a
multiple of two octets.

The pseudo  header  conceptually prefixed to the UDP header contains the
source  address,  the destination  address,  the protocol,  and the  UDP
length.   This information gives protection against misrouted datagrams.
This checksum procedure is the same as is used in TCP.

                  0      7 8     15 16    23 24    31
                 +--------+--------+--------+--------+
                 |          source address           |
                 +--------+--------+--------+--------+
                 |        destination address        |
                 +--------+--------+--------+--------+
                 |  zero  |protocol|   UDP length    |
                 +--------+--------+--------+--------+

If the computed  checksum  is zero,  it is transmitted  as all ones (the
equivalent  in one's complement  arithmetic).   An all zero  transmitted
checksum  value means that the transmitter  generated  no checksum  (for
debugging or for higher level protocols that don't care).

如果你想了解Wireshark的UDP解析器是如何处理的,可以查看packet-udp.c的源代码。基本上,正确设置数据输入后,它实际上只是调用 in_cksum.c 中的 in_cksum() 函数。文件来计算它。

您可能还想查看RFC 1071 ,“计算互联网校验和”。

关于udp - 通过Wireshark验证Checksum值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55577568/

相关文章:

java - 检查两个图像文件是否相同..校验和或哈希?

java - 用于保持时间戳完整性的校验和

HTTPS/TLS 连接初始化

ssl - 试图了解 SSLKEYLOGFILE 环境变量输出格式

java - 将 UDP 从 Java 发送到 Python 不起作用

networking - Julia - 无法在 Wireshark 中捕获环回 UDP 数据包

linux - tshark 中 pcap 的明文输出(使用 wireshark 的选项?)

algorithm - Triple-CRC-32 对于生成非安全均匀分布哈希来说是一个坏(或不是)主意吗?

udp - 与 char 数组相比,在 boost ASIO 中使用可变缓冲区对象有什么优势?

c++ - 多个 Boost::ASIO async_send_to 一口气