格式错误的 DNS 请求数据包

Malformed DNS Request Packet

我一直在从事一个项目,该项目涉及发送 DNS 请求,其中包含问题中的信息(不是实际域)(其中 2 个)。我一直在用 wireshark 跟踪数据包。

这是创建的数据包的 tcp 转储。

00000000 00 02 01 00 00 02 00 00 00 00 00 00 01 32 03 65

00000010 6e 64 03 63 6f 6d 00 00 01 00 01 01 32 04 73 61

00000020 76 65 03 63 6f 6d 00 00 01 00 01

........ .....2.e

nd.com.. ....2.sa

ve.com.. ...

i.d.qdcount 应该是 2,需要递归,显示的域是正确的。 Wireshark 表示这是一个格式错误的 DNS 数据包。知道数据包有什么问题吗?

好的,所以:

  • 如果您自己进行 transport-layer 联网,您的代码将通过在创建用于发送数据包的套接字时指定它是 UDP 还是 TCP 来确定它是通过 UDP 还是 TCP TCP 套接字;
  • 如果数据包不适合 maximum-sized UDP 数据包,则使用 TCP;
  • 如果您通过 TCP 发送它,您需要在它前面加上一个 header,根据 RFC 1035.
  • 中的第 4.2.2 节“TCP 使用”

"Maximum-sized" 有点含糊。 RFC 791,IPv4 规范在第 3.1 节“Internet Header 格式”中说:

Total Length:  16 bits

  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.

然而,如今,将最大数据包大小限制低至 576 字节的旧网络硬件即使没有完全消失,也已基本消失,real-world“最大数据包大小”通常是以太网数据包大小——总长度为 1518 字节,其中 14 字节的以太网 header 和 4 字节的 FCS,剩下 1500 字节的有效载荷。对于 UDP,典型的 IPv4 header 长度为 20 个字节,UDP header 长度为 8 个字节,即 1472 个字节的数据,因此对于更大的 DNS 消息,使用 TCP 而不是 UDP 可能就足够了超过 1472 字节(如果网络路由中的任何一跳无法处理 1500 字节的 IPv4 数据包,就会发生 IP 分段和重组;这确实增加了数据包无法通过的机会,因为如果一个分段通过但另一个分段通过没有,整个数据包都没有通过。