UDP 数据传输时是否会损坏?

发布于 2024-07-04 01:49:40 字数 40 浏览 7 评论 0原文

发送给您的 UDP 数据是否有可能已损坏? 我知道它可能会丢失。

Is it possible for UDP data to come to you corrupted? I know it is possible for it to be lost.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

梦途 2024-07-11 01:49:41

UDP 数据包也可能会无序传送,因此如果您在 UDP 之上设计协议,您也必须考虑到这一点。

UDP packets can also be delivered out of order, so if you are devising a protocol on top of UDP you have to take that into account as well.

诗酒趁年少 2024-07-11 01:49:41

影响毫无戒心的程序员的一种常见“损坏”形式是数据报截断。 有关详细信息,请参阅 Stevens 的“Unix Network Planning”(第 2 版第 539 页)。

您可以检查 MSG_TRUNC 标志...

A common form of "corruption" that affects unsuspecting programmers is datagram truncation. See "Unix Network Programming" by Stevens for more information (page 539 in 2nd ed.)

You might check the MSG_TRUNC flag...

策马西风 2024-07-11 01:49:41

简短回答:是的。

详细答案:

大约7年前(也许2011年?)我们发现,当中国的一台计算机和韩国的另一台计算机之间交换UDP数据报时,UDP数据报会被无意中更改。 当然,UDP数据包头中的校验和也会根据有效负载的变化而重新计算。 两台计算机中没有恶意软件。

我们发现,只有当这些条件匹配时,才会发生无意的变化:

  • 数据报的前几个字节与前一个数据报相似
  • 仅当 UDP 数据报从一个国家传输到另一个国家时才会发生

我不知道确切的原因,但我粗略地猜测它是 < a href="https://en.wikipedia.org/wiki/Golden_Shield_Project" rel="nofollow noreferrer">中国金盾。

所以我们在我们的ProudNet软件中添加了数据报乱码算法,问题就消失了。 实施起来并不困难。 只需对数据报的前几个字节进行编码或混淆即可。

Short answer: YES.

Detailed answer:

About 7 years ago(maybe 2011?) We found that UDP datagrams are unintentionally changed when a UDP datagram is exchanged between a computer in China and another one in Korea. Of course, Checksum in UDP packet header is also reculculated regarding to the payload change. There were no malware software in two computers.

We found that the unintentional change only occurs when these conditions match:

  • First several bytes of datagrams are similar to the previous datagram
  • Only occurse when UDP datagrams go from one nation to another

I don't the cause exactly, but I roughly guess it is China Golden Shield.

So we added datagram garbling algorithm into out software ProudNet and the problem went away. It is not difficult to implement. Just encode or obfuscate first several bytes of your datagram.

[浮城] 2024-07-11 01:49:40

UDP 数据包使用 16 位校验和。 UDP 数据包损坏并非不可能,但可能性很小。 无论如何,它并不比 TCP 更容易受到损坏。

UDP packets use a 16 bit checksum. It is not impossible for UDP packets to have corruption, but it's pretty unlikely. In any case it is not more susceptible to corruption than TCP.

马蹄踏│碎落叶 2024-07-11 01:49:40

首先,上面提到的“IP校验和”只是IP头校验和。 它不保护有效负载。 参见 RFC 791

其次,UDP 允许传输无校验和,这意味着 16 位校验和设置为 0(即无)。 请参阅 RFC 768。(全零传输的校验和值意味着发送器未生成校验和)

第三,正如其他人提到的,UDP 有一个 16 位 checkSUM,这不是检测多位错误的最佳方法,但不错。 未检测到的错误当然有可能潜入,但可能性很小。

First of all, the "IP checksum" referenced above is only an IP header checksum. It does not protect the payload. See RFC 791

Secondly, UDP allows transport with NO checksum, which means that the 16-bit checksum is set to 0 (ie, none). See RFC 768. (An all zero transmitted checksum value means that the transmitter generated no checksum)

Thirdly, as others have mentioned, UDP has a 16-bit checkSUM, which is not the best way to detect a multi-bit error, but is not bad. It is certainly possible for an undetected error to sneak in, but very unlikely.

云仙小弟 2024-07-11 01:49:40

可能的? 绝对地。 未被发现? 不太可能,因为 UDP 使用的校验和需要多位错误才能显得有效。 如果检测到错误,系统可能会丢弃数据包 - 这就是使用 UDP 的风险。

Possible? Absolutely. Undetected? Unlikely, since UDP employs a checksum that would require multiple-bit errors to appear valid. If an error is detected, the system will likely drop the packet - such are the risks of using UDP.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文