关于 UDP 数据报大小的说明


IPv4/v6 数据包的最大尺寸取决于 MTU(Maximum Transmission Unit,最大传输单元)与 Payload Length 字段大小。

  • Payload Length 字段有 16 位 宽,指一个超过 64K 的包含 IP 头部和数据的负载 (65,507 字节 = 65,535 − 8 字节 UDP 头 − 20 字节 IP 头)。 通常对于环回地址来说是这样,但这个长度的数据包对于大多数的主机和网络来说不切实际。

  • MTU 指的是数据链路层为数据包提供的最大大小。 对于任意链路, IPv4 所托管的 MTU 最小为 68 个字节,推荐为 576(典型地,作为拨号上网应用的推荐值),无论它们是完整地还是分块地抵达。

    对于 IPv6MTU 的最小值是 1280 个字节,然而,受托管的最小的碎片重组缓冲大小为 1500 个字节。 现今大多数的数据链路层技术(如以太网),都有 1500MTU 最小值,因而 68 个字节显得非常小。

要提前知道数据包可能经过的每个链路的 MTU 是不可能的。 发送大于接受者 MTU 大小的数据包将不会起作用,因为数据包会被静默地丢失,而不会通知发送者该包未抵达目的地。

The maximum size of an IPv4/v6 datagram depends on the MTU (Maximum Transmission Unit) and on the Payload Length field size.

  • The Payload Length field is 16 bits wide, which means that a normal payload exceed 64K octets including the internet header and data (65,507 bytes = 65,535 − 8 bytes UDP header − 20 bytes IP header); this is generally true for loopback interfaces, but such long datagram messages are impractical for most hosts and networks.

  • The MTU is the largest size a given link layer technology can support for datagram messages. For any link, IPv4 mandates a minimum MTU of 68 octets, while the recommended MTU for IPv4 is 576 (typically recommended as the MTU for dial-up type applications), whether they arrive whole or in fragments.

    For IPv6, the minimum MTU is 1280 octets, however, the mandatory minimum fragment reassembly buffer size is 1500 octets. The value of 68 octets is very small, since most current link layer technologies, like Ethernet, have a minimum MTU of 1500.

It is impossible to know in advance the MTU of each link through which a packet might travel. Sending a datagram greater than the receiver MTU will not work because the packet will get silently dropped without informing the source that the data did not reach its intended recipient.