This is wikipedia's explanation of the length field of the UDP header:
这是*对UDP标头长度字段的解释:
Length
A field that specifies the length in bytes of the UDP header and UDP data. The minimum length is 8 bytes because that is the length of the header. The field size sets a theoretical limit of 65,535 bytes (8 byte header + 65,527 bytes of data) for a UDP datagram. The practical limit for the data length which is imposed by the underlying IPv4 protocol is 65,507 bytes (65,535 − 8 byte UDP header − 20 byte IP header).Length一个字段,指定UDP头和UDP数据的字节长度。最小长度为8个字节,因为这是标头的长度。对于UDP数据报,字段大小设置理论限制为65,535字节(8字节标题+ 65,527字节数据)。由基础IPv4协议强加的数据长度的实际限制是65,507字节(65,535-8字节UDP报头--20字节IP报头)。
The practical limit for the data length should minus 20 byte IP header, why is that?
数据长度的实际限制应该减去20字节的IP头,为什么呢?
3 个解决方案
#1
Take a good look at the explanation of the IP header at this link : https://www.ietf.org/rfc/rfc791.txt
请仔细阅读此链接中IP标头的说明:https://www.ietf.org/rfc/rfc791.txt
I quote : Total Length: 16 bits
我引用:总长度:16位
Total Length is the length of the datagram, measured in octets, including internet header and data. This field allows the length of a datagram to be up to 65,535 octets. Such long datagrams are impractical for most hosts and networks. All hosts must be prepared to accept datagrams of up to 576 octets (whether they arrive whole or in fragments). It is recommended that hosts only send datagrams larger than 576 octets if they have assurance that the destination is prepared to accept the larger datagrams. The number 576 is selected to allow a reasonable sized data block to be transmitted in addition to the required header information. For example, this size allows a data block of 512 octets plus 64 header octets to fit in a datagram. The maximal internet header is 60 octets, and a typical internet header is 20 octets, allowing a margin for headers of higher level protocols.
Total Length是数据报的长度,以八位字节为单位,包括互联网标题和数据。该字段允许数据报的长度达到65,535个八位字节。对于大多数主机和网络而言,这种长数据报是不切实际的。所有主机必须准备接受最多576个八位字节的数据报(无论它们是全部还是碎片到达)。如果主机确保目标已准备好接受较大的数据报,则建议主机仅发送大于576个八位字节的数据报。选择数字576以允许除了所需的标题信息之外还发送合理大小的数据块。例如,该大小允许512个八位字节的数据块加上64个头部八位字节以适合数据报。最大互联网标题是60个八位字节,典型的互联网标题是20个八位字节,允许更高级别协议的标题的余量。
So the maximum total length is 65535 but this includes the IP header itself. Therefore you have an IP payload that can be 65535 - 20 = 65515.
所以最大总长度是65535,但这包括IP头本身。因此,您的IP有效负载可以是65535 - 20 = 65515。
But the payload of IP in your case is UDP and UDP has a header of its own which is 8 bytes. Hence you get to the theoretical
limit of the payload of a UDP packet : 65,535 − 8 byte UDP header − 20 byte IP header
但在你的情况下IP的有效载荷是UDP和UDP有自己的头,这是8字节。因此,您达到UDP数据包的有效载荷的理论极限:65,535 - 8字节UDP报头 - 20字节IP报头
Note the use of theoretical instead of practical. The practical limit of a UDP packet takes into account the probability of fragmentation and thus considers the mtu of the network layer. The link above also has an interesting sentence containing the value 576. 576 - 20 - 8 = 548 which is not quite 534 but getting close. This might explain this practical limit.
注意使用理论而不是实际。 UDP分组的实际限制考虑了分段的可能性,因此考虑了网络层的mtu。上面的链接也有一个有趣的句子,包含值576. 576 - 20 - 8 = 548这不是很好534但接近。这可以解释这个实际限制。
#2
Because UDP packets are encapsulated in IP packets which headers are 20 bytes. You can't send UDP packets without a encapsulated IP packet. Usually the actual limit is way less and it depends on the MTU of the routers between the two endpoints transmitting the UDP packet.
因为UDP数据包封装在IP数据包中,其头部是20个字节。没有封装的IP数据包,您无法发送UDP数据包。通常实际限制较少,并且它取决于传输UDP数据包的两个端点之间的路由器的MTU。
#3
Because the IP header has to be (a) sent and (b) counted in the 16-bit length word. See RFC 791 #3.1.
因为IP报头必须(a)发送并且(b)在16位长度字中计数。请参阅RFC 791#3.1。
However the real practical limit is generally accepted to be 534 bytes, to avoid fragmentation at the IP layer, which increases the risk of datagram loss.
然而,实际的实际限制通常被接受为534字节,以避免IP层的碎片,这增加了数据报丢失的风险。
#1
Take a good look at the explanation of the IP header at this link : https://www.ietf.org/rfc/rfc791.txt
请仔细阅读此链接中IP标头的说明:https://www.ietf.org/rfc/rfc791.txt
I quote : Total Length: 16 bits
我引用:总长度:16位
Total Length is the length of the datagram, measured in octets, including internet header and data. This field allows the length of a datagram to be up to 65,535 octets. Such long datagrams are impractical for most hosts and networks. All hosts must be prepared to accept datagrams of up to 576 octets (whether they arrive whole or in fragments). It is recommended that hosts only send datagrams larger than 576 octets if they have assurance that the destination is prepared to accept the larger datagrams. The number 576 is selected to allow a reasonable sized data block to be transmitted in addition to the required header information. For example, this size allows a data block of 512 octets plus 64 header octets to fit in a datagram. The maximal internet header is 60 octets, and a typical internet header is 20 octets, allowing a margin for headers of higher level protocols.
Total Length是数据报的长度,以八位字节为单位,包括互联网标题和数据。该字段允许数据报的长度达到65,535个八位字节。对于大多数主机和网络而言,这种长数据报是不切实际的。所有主机必须准备接受最多576个八位字节的数据报(无论它们是全部还是碎片到达)。如果主机确保目标已准备好接受较大的数据报,则建议主机仅发送大于576个八位字节的数据报。选择数字576以允许除了所需的标题信息之外还发送合理大小的数据块。例如,该大小允许512个八位字节的数据块加上64个头部八位字节以适合数据报。最大互联网标题是60个八位字节,典型的互联网标题是20个八位字节,允许更高级别协议的标题的余量。
So the maximum total length is 65535 but this includes the IP header itself. Therefore you have an IP payload that can be 65535 - 20 = 65515.
所以最大总长度是65535,但这包括IP头本身。因此,您的IP有效负载可以是65535 - 20 = 65515。
But the payload of IP in your case is UDP and UDP has a header of its own which is 8 bytes. Hence you get to the theoretical
limit of the payload of a UDP packet : 65,535 − 8 byte UDP header − 20 byte IP header
但在你的情况下IP的有效载荷是UDP和UDP有自己的头,这是8字节。因此,您达到UDP数据包的有效载荷的理论极限:65,535 - 8字节UDP报头 - 20字节IP报头
Note the use of theoretical instead of practical. The practical limit of a UDP packet takes into account the probability of fragmentation and thus considers the mtu of the network layer. The link above also has an interesting sentence containing the value 576. 576 - 20 - 8 = 548 which is not quite 534 but getting close. This might explain this practical limit.
注意使用理论而不是实际。 UDP分组的实际限制考虑了分段的可能性,因此考虑了网络层的mtu。上面的链接也有一个有趣的句子,包含值576. 576 - 20 - 8 = 548这不是很好534但接近。这可以解释这个实际限制。
#2
Because UDP packets are encapsulated in IP packets which headers are 20 bytes. You can't send UDP packets without a encapsulated IP packet. Usually the actual limit is way less and it depends on the MTU of the routers between the two endpoints transmitting the UDP packet.
因为UDP数据包封装在IP数据包中,其头部是20个字节。没有封装的IP数据包,您无法发送UDP数据包。通常实际限制较少,并且它取决于传输UDP数据包的两个端点之间的路由器的MTU。
#3
Because the IP header has to be (a) sent and (b) counted in the 16-bit length word. See RFC 791 #3.1.
因为IP报头必须(a)发送并且(b)在16位长度字中计数。请参阅RFC 791#3.1。
However the real practical limit is generally accepted to be 534 bytes, to avoid fragmentation at the IP layer, which increases the risk of datagram loss.
然而,实际的实际限制通常被接受为534字节,以避免IP层的碎片,这增加了数据报丢失的风险。