Calculating UDP Checksum - HOW?

Eddie Kohler kohler at icir.org
Tue Jul 23 17:38:34 EDT 2002


Hi Filip,

> I understand now the fact that SetTCPChecksum corrupts the UDP/RTP packet.
> But what I still don't understand is that after this SetTCPChecksum
> operation the UDP Checksum seems to be correct (i.e. this is what a tool
> like Ethereal tells me... but of course, it can also be a tool problem)
> although the UDP Checksum hasn't changed (See also the example I posted
> before). Is this explainable from what you know from TCP and/or UDP
> checksums?

Yes, it is.

The IP checksum is a function C of some amount of data. The checksum field
is given a value so that C(packet data) == 0. But when someone _checks_ the
checksum, they don't care about the value of the field -- or even where the
field is. They just calculate C(packet data) and see whether it is zero.
Furthermore, the checksum function C is indifferent to the ordering of
halfwords in the data.

The TCP and UDP checksums are calculated using the exact same data (the IP
payload plus a couple fields of the IP header), although they use different
checksum fields. Therefore, changing a portion of the _data_ to match the
existing _checksum_ field, which is effectively what SetTCPChecksum did to
your UDP packet, will result in a valid UDP checksum.

Eddie




More information about the click mailing list