Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

From the Wikipedia page:

The checksum field is the 16 bit one's complement of the one's complement sum of all 16-bit words in the header and text.

Why, after summing the 16-bits in the header and text, is the one's complement taken to compute the TCP checksum?

share|improve this question
2  
I suspect you'll have to ask Vint Cerf. –  Michael Hampton May 16 '13 at 21:39
1  
Why is this even a SF question - how can we know what was in the mind of the designers of the TCP protocol ? –  Iain May 16 '13 at 21:57
2  
@randomblue: You have forgotten about the line in our faq which says that questions should be of a practical, answerable, nature. In many years of working in the industry I've never needed to worry about the TCP checksum (except when interviewing) and I don't see how your question has any practical application today. –  Iain May 17 '13 at 6:14
    
@randomblue Why do you need to know? –  Dan May 17 '13 at 9:44

4 Answers 4

up vote 4 down vote accepted

The complement is taken to make checksum validation simpler — instead of calculating the checksum again and then comparing the calculated value with the checksum field in the header (which is in the middle of the summed data), it is possible to sum (using one's complement arithmetic) all 16-bit words in the header (including the checksum word) and compare the result with zero.

share|improve this answer

It might be because a value of all zeros is meaningful (from RFC 793):

While computing the checksum, the checksum field itself is replaced with zeros.

so it can preserve this meaning against the unlikely event that the checksum really is zero.

share|improve this answer

Checksumming for the result to be ZEROs is problematic as all ZEROs is also generated by a powered off device or something not having power. With the result being ALL ONES there is more assurance that the hardware is properly functioning.

One's complement is more complicated term for analyzing the bits one-by-one and not as an entire unit (i.e. AND/OR/XOR/NOT).

share|improve this answer

One's complement arithmetic was used because TCP was designed in the 1970s for 1970s computers, most of which used one's complement arithmetic. The rise of two's complement arithmetic, which modern computers use, didn't really begin in earnest until the personal computers of the late 1970s and 1980s.

share|improve this answer
    
I'm talking about the inversion, not the summing. –  Randomblue May 16 '13 at 22:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.