UDP 正在向数据报的末尾添加字节?
UDP is adding bytes to end of datagram?
我有一个用 C 编写的 Linux UDP 服务器,我正在发送一个 16 字节的 UDP 数据报。客户端正确接收了所有数据,但 wireshark 日志显示正在添加两个额外的字节:
00 16 00 00 c8 44 01 14 01 01 02 01 02 00 00 10 00 00
这两个字节都是零,我不确定它们来自哪里,我的 sendto() 函数中发送了 16 个字节的数据。
这些必须从 Linux 内核层的填充中添加?有没有办法阻止这种情况发生?
wireshark 的屏幕截图,显然这是以太网填充字节...为什么会在这里?
以太网帧至少需要 64 个八位字节,包括 屏幕截图中未显示的帧校验序列 (FCS) 的 4 个八位字节。如果没有这 2 个零填充八位字节,该帧将只有 62 个八位字节长。另请注意,它们不是 in UDP 数据包,它们在 outside。 outside 的 UDP 帧长度为 24,这包括您发送的数据的 16 个八位字节;其余 8 个八位字节是 4 个 16 位数字:源端口、目标端口、长度和校验和。以太网填充字节在 UDP 和 IP 帧之外。
最小 64 八位字节帧长度的原因由来已久 - 以太网最初是为总线拓扑设计的,其中媒体访问是通过一种称为 carrier-sense multiple access with collision detection (CSMA/CD) 的方法进行调节的。当总线空闲时,任何设备都可以随时在总线上进行传输,但它们必须监视总线以进行同步传输。如果发生冲突,则每个当前发送方都会后退一段随机延迟。设置了 64 字节的最小值,以便发送设备在完成发送帧之前注意到数百米长的电缆 运行 上的冲突。
从 Wireshark documentation 通过 Google 搜索 "wireshark 最小以太网帧":
Ethernet packets with less than the minimum 64 bytes for an Ethernet packet (header + user data + FCS) are padded to 64 bytes, which means that if there's less than 64-(14+4) = 46 bytes of user data, extra padding data is added to the packet.
Beware: the minimum Ethernet packet size is commonly mentioned at 64 bytes, which is including the FCS. This can be confusing as the FCS is often not shown by Wireshark, simply because the underlying mechanisms simply don't supply it. [...]
顺便说一下,这与 C 编程语言没有任何关系。
我有一个用 C 编写的 Linux UDP 服务器,我正在发送一个 16 字节的 UDP 数据报。客户端正确接收了所有数据,但 wireshark 日志显示正在添加两个额外的字节:
00 16 00 00 c8 44 01 14 01 01 02 01 02 00 00 10 00 00
这两个字节都是零,我不确定它们来自哪里,我的 sendto() 函数中发送了 16 个字节的数据。
这些必须从 Linux 内核层的填充中添加?有没有办法阻止这种情况发生?
wireshark 的屏幕截图,显然这是以太网填充字节...为什么会在这里?
以太网帧至少需要 64 个八位字节,包括 屏幕截图中未显示的帧校验序列 (FCS) 的 4 个八位字节。如果没有这 2 个零填充八位字节,该帧将只有 62 个八位字节长。另请注意,它们不是 in UDP 数据包,它们在 outside。 outside 的 UDP 帧长度为 24,这包括您发送的数据的 16 个八位字节;其余 8 个八位字节是 4 个 16 位数字:源端口、目标端口、长度和校验和。以太网填充字节在 UDP 和 IP 帧之外。
最小 64 八位字节帧长度的原因由来已久 - 以太网最初是为总线拓扑设计的,其中媒体访问是通过一种称为 carrier-sense multiple access with collision detection (CSMA/CD) 的方法进行调节的。当总线空闲时,任何设备都可以随时在总线上进行传输,但它们必须监视总线以进行同步传输。如果发生冲突,则每个当前发送方都会后退一段随机延迟。设置了 64 字节的最小值,以便发送设备在完成发送帧之前注意到数百米长的电缆 运行 上的冲突。
从 Wireshark documentation 通过 Google 搜索 "wireshark 最小以太网帧":
Ethernet packets with less than the minimum 64 bytes for an Ethernet packet (header + user data + FCS) are padded to 64 bytes, which means that if there's less than 64-(14+4) = 46 bytes of user data, extra padding data is added to the packet.
Beware: the minimum Ethernet packet size is commonly mentioned at 64 bytes, which is including the FCS. This can be confusing as the FCS is often not shown by Wireshark, simply because the underlying mechanisms simply don't supply it. [...]
顺便说一下,这与 C 编程语言没有任何关系。