Are UDP Packets dropped when UDP header checksum is incorrect?

14,429

Solution 1

Yes they would be dropped. If you need more reliable communication you're much better off using TCP.

for more information, take a look at this: http://www.diffen.com/difference/TCP_vs_UDP

UDP there's no guarantee that the packets will even be sent, let alone received. If they are in fact received though, they are checked. If they fail checksum they are dropped.

EDIT: also to add to that, udp does not by default order the packets as they are sent, that has to be done at the application level. Bear this in mind if you still intend on using UDP.

Solution 2

If comes packet with wrong checksum, OS will drop it before passing it to the socket.

Destination application cannot determine if packet was lost or comes with wrong checksum. I think that it also cannot force else behavior.

Share:
14,429
innosam
Author by

innosam

Updated on June 11, 2022

Comments

  • innosam
    innosam almost 2 years

    If i open a raw socket, and send udp packets with a wrong checksum, would the packets be dropped other side by the tcp/ip stack?

  • innosam
    innosam over 10 years
    Can i disable UDP header checksum validation while opening the socket??
  • Gabi Turliu
    Gabi Turliu over 10 years
    Yes, the UDP header checksum is optional. Just set it to 0 (means unused)
  • user2366842
    user2366842 over 10 years
    Be careful with this, because according to the wikipedia article ( en.wikipedia.org/wiki/User_Datagram_Protocol ) it states that in ipv6 it's no longer able to send the packet without checksum. Here's the ipv6 spec from which the wikipedia stuff was sourced from... tools.ietf.org/html/rfc2460
  • user2366842
    user2366842 over 10 years
    you can force it to ignore, at least in ipv4. In ipv6 this is no longer the case.
  • innosam
    innosam over 10 years
    @user2366842 how can i force it to ignore the UDP header checksum?
  • user2366842
    user2366842 over 10 years
    binarytides.com/raw-udp-sockets-c-linux have a look at this, and where it's calculating out the checksum, just set it equal to 0.... Once again, note, both sending and receiving machines MUST be ipv4 or else this will fail. Specifically the function from lines 28 to 51