Welcome to the CSC Q&A.
Get help and give help!
Write great code!
It is our choices... that show what we truly are, far more than our abilities.


+18 votes

I thought I understood this, but after watching the videos and talking with people I'm just really confused. Could someone explain how you get the checksum from adding together all the data, and give some kind of example?

asked in CSC335_Spring2019 by (2.1k points)

1 Answer

+12 votes
Best answer

To obtain the UDP checksum, add up all the words of the packet using one's complement addition. What makes one's complement addition different from other binary addition we have done is what the computer does with the overflow bit and there is an additional final step. If the leftmost bit gets an overflow, that overflow bit gets added into the rightmost bit. For example, 1000+1000 = 0001 for that step of one's complement. Finally, at the end of the one's complement addition, we invert the final sum.

To check the checksum, we add the checksum to the the non inverted sum of the words and check to make sure it is all ones.

If we are sending the packet 1011 1001 0001, this is how we would compute the checksum

1011+1001=0101 -> In this step, we had to carry the overflow bit, to the rightmost bit
1001 is the checksum

The sum is all ones, so the message is correct

answered by (4.2k points)
selected by