views:

1027

answers:

6

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

+4  A: 

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.

Kyle Cronin
+11  A: 

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

Leon Timmermans
Technically the checksum is optional. From RFC 768: "An all zero transmitted checksum value means that the transmitter generated no checksum (for debugging or for higher level protocols that don't care)."
Andrew Johnson
+4  A: 

UDP packets contain a simple 16-bit checksum.

The enclosing IP packet also contains a very similar checksum calculated in essentially the same way. Unfortunately this means that a corrupt packet that happens to have a correct UDP checksum likely has a corrupt IP checksum. There is very little value in the UDP checksum. A checksum of zero means don't check the checksum, so at least having a duplicated checksum can detect this case.

Corruption is chaotic in nature. This means that if you have at least one error in a packet, you are disproportionately likely to have more than one. Because the checksum algorithm is so weak there is a real chance of the errors going undetected.

Some routers have been observed to fix incorrect checksums.

Tom Hawtin - tackline
The IP checksum doesn't contain the data, only the IP header!
Eli Bendersky
+3  A: 

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.

Rob Walker
A: 

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

ceretullis
+2  A: 

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.

If the datagram arrives with no checksum, can the application ask for that information?
benc