UDP 数据传输时是否会损坏?
发送给您的 UDP 数据是否有可能已损坏? 我知道它可能会丢失。
Is it possible for UDP data to come to you corrupted? I know it is possible for it to be lost.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
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.
影响毫无戒心的程序员的一种常见“损坏”形式是数据报截断。 有关详细信息,请参阅 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...
简短回答:是的。
详细答案:
大约7年前(也许2011年?)我们发现,当中国的一台计算机和韩国的另一台计算机之间交换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:
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.
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.
首先,上面提到的“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.
可能的? 绝对地。 未被发现? 不太可能,因为 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.