Question

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

Was it helpful?

Solution

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.

OTHER TIPS

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.

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.

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.

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

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top