UDP 最大数据包大小 [英] UDP maximum packet size

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

问题描述

我检查了最大 UDP 数据包大小,发现它是 65507 字节的数据.
这是 65535-8(udp 标头)- 20(ip 标头).
UDP 长度标头长度为 2 个字节,限制为 65535.
我知道我们从中减去 8,因为它是 UDP 标头的大小但如果它总是 8 为什么我们需要减去它.
对于 20 的 ip 标头长度,同样的问题.

I checked the maximum UDP packet size and saw it is 65507 bytes of data.
Which is 65535-8 (udp headers) - 20 (ip headers).
The UDP length header is 2 bytes long which is 65535 limit.
I understand that we substract 8 from it because its the size of the UDP header but if it is always 8 why do we need to substract it.
Same question for the 20 of the ip headers length.

谢谢

推荐答案

UDP 数据报封装在 IP 数据包中.如果您使用 20 作为 IP 数据包标头大小,那么您的意思是 IPv4,而 最小 IPv4 标头大小为 20.IPv4 的理论最大数据包大小为 65,535(16 位的总长度字段)IPv4 标头),但真正的 IPv4 最大数据包大小将是链路上的 MTU.此大小包括 IPv4 标头和 IPv4 有效负载,这将是 UDP 数据报,包括 UDP 标头和 UDP 有效负载.

UDP datagrams are encapsulated inside IP packets. If you are using 20 as the IP packet header size then you mean IPv4, and the minimum IPv4 header size is 20. IPv4 has a theoretical maximum packet size of 65,535 (a 16-bit total length field in the IPv4 header), but the real IPv4 maximum packet size will be the MTU on the link. This size includes the IPv4 header and the IPv4 payload, which will be the UDP datagram, including the UDP header and UDP payload.

由于UDP数据报是IPv4数据报的数据,而IPv4数据报的整个长度,包括IPv4头,是IPv4头的16位Total Length字段,整个IPv4数据包,包括IPv4标头最多为 65,535 个八位字节.这在 IPv4 的定义中进行了详细说明,RFC 971 Internet 协议部分3.1 Internet Header 格式:

Since the UDP datagram is the data of the IPv4 datagram, and the entire length of the IPv4 datagram, including the IPv4 header, is a 16-bit Total Length field of the IPv4 header, the entire IPv4 packet, including the IPv4 header is a maximum of 65,535 octets. This is detailed in the definition of IPv4, RFC 971 Internet protocol, Section 3.1 Internet Header Format:

3.1.互联网标题格式

3.1. Internet Header Format

互联网标头内容摘要如下:

A summary of the contents of the internet header follows:

 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Version|  IHL  |Type of Service|          Total Length         |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|         Identification        |Flags|      Fragment Offset    |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|  Time to Live |    Protocol   |         Header Checksum       |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                       Source Address                          |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                    Destination Address                        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                    Options                    |    Padding    |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Total Length 字段的定义是:

The definition of the Total Length field is:

总长度:16 位

Total Length 是数据报的长度,以八位字节为单位,包括互联网标题和数据.该字段允许一个数据报最长为 65,535 个八位字节.这么长的数据报对于大多数主机和网络来说是不切实际的.所有主机都必须准备好接受最多 576 个八位字节的数据报(无论它们是完整的还是在片段中).建议主机只发送数据报大于 576 个八位字节,如果他们确信目的地是准备接受更大的数据报.

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.

选择数字 576 以允许合理大小的数据块除了所需的标头信息外,还可以传输.为了例如,此大小允许 512 个八位字节加上 64 个标头的数据块八位字节以适合数据报.最大 Internet 标头为 60八位字节,一个典型的互联网标头是 20 个八位字节,允许留有余量用于更高级别协议的标头.

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.

这意味着您必须从最大值 65,535 中减去 IPv4 报头长度,才能得出最大 UDP 数据报长度,其中包括 8 个八位字节的 UDP 报头.

That means you must subtract the IPv4 header length from the maximum of 65,535 to arrive at the maximum UDP datagram length, which includes the 8 octet UDP header.

这篇关于UDP 最大数据包大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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