UDP数据包的数据长度有什么实际限制? [英] What's the practical limit for the data length of UDP packet?

查看:2755
本文介绍了UDP数据包的数据长度有什么实际限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是维基百科对UDP标题长度字段的解释:

This is wikipedia's explanation of the length field of the UDP header:


长度

指定的字段UDP头
和UDP数据的字节长度。最小长度为8个字节,因为这是标头的长度
。对于UDP数据报,字段大小为理论限制设置了65,535字节
(8字节标题+ 65,527字节数据)。基础
IPv4协议强加的数据长度的
实际限制为65,507字节(65,535 - 8字节UDP标头 - 20字节IP
标头)。

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).

数据长度的实际限制应减去20字节的IP标头,为什么会这样?

The practical limit for the data length should minus 20 byte IP header, why is that?

推荐答案

在此链接上仔细查看IP标头的说明:
https://www.ietf.org/rfc/rfc791.txt

Take a good look at the explanation of the IP header at this link : https://www.ietf.org/rfc/rfc791.txt

我引用:
总长度: 16位

I quote : Total Length: 16 bits


总长度是数据报的长度,以八位字节为单位,包括互联网标题和数据。该字段允许数据报的长度达到65,535个八位字节。对于大多数主机和网络而言,这种长数据报是不切实际的。所有主机必须准备好接受最多576个八位字节的数据报(无论它们是全部还是碎片)。如果主机确保目标已准备好接受较大的数据报,则建议主机仅发送大于576个八位字节的数据报。
选择数字576以允许除了所需的标题信息之外还传输合理大小的数据块。例如,此大小允许512个八位字节的数据块加上64个头八位字节适合数据报。最大互联网标题是60个八位字节,典型的互联网标题是20个八位字节,允许更高级别协议标题的保证金。

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.

所以最大总长度是65535,但这包括IP头本身。
因此,你有一个IP有效载荷,可以是65535 - 20 = 65515。

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.

但是你的IP的有效载荷是UDP,UDP的头部是它自己的是8个字节。因此,您将获得UDP数据包有效负载的理论限制:65,535 - 8字节UDP标头 - 20字节IP标头

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

注意使用理论而不是实际。 UDP分组的实际限制考虑了分段的概率,因此考虑了网络层的mtu。上面的链接也有一个有趣的句子,其中包含值576. 576 - 20 - 8 = 548这不是534但接近。这可以解释这个实际限制。

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数据包的数据长度有什么实际限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆