关于 UDP 数据报大小的注意事项


【Note about UDP datagram size】

IPv4/IPv6 数据报的最大大小取决于 MTU(最大传输单元)以及 Payload Length 字段的大小。

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

  • Payload Length 字段的宽度为 16 位,这意味着普通负载(包括互联网头和数据)不能超过 64K 字节(65,507 字节 = 65,535 − 8 字节 UDP 头 − 20 字节 IP 头);这对回环接口通常是正确的,但对于大多数主机和网络而言,这样长的数据报是不实际的。

  • MTU 是给定链路层技术能够支持的数据报消息的最大尺寸。对于任何链路,IPv4 规定的最小 MTU 为 68 个字节,而 IPv4 的推荐 MTU 为 576(通常推荐作为拨号类型应用的 MTU),无论数据报是完整到达还是分片到达。

    对于 IPv6,最小的 MTU 是 1280 字节。然而,强制性的最小分片重组缓冲区大小是 1500 字节。68 字节的值非常小,因为大多数当前的链路层技术,如以太网,最小 MTU 都是 1500。

事先不可能知道数据包可能经过的每个链路的最大传输单元(MTU)。发送大于接收方 MTU 的数据报是行不通的,因为数据包会被悄无声息地丢弃,而不会通知源端数据没有到达预期的接收方。

【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.】