IP protocol parsing header checksum

Source: Internet
Author: User

650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M02/88/98/wKiom1f8lxHzbolaAACOMlQ6yj8242.png-wh_500x0-wm_3 -wmp_4-s_626947345.png "title=" 818159893d1a4de44cf4d18f75e7a8cf.png "alt=" Wkiom1f8lxhzbolaaacomlq6yj8242.png-wh_ "/>

3. The field is fully populated with 0 when the checksum field is initially computed;
The above is how the checksum is computed for the sender, and the validation is simple for the receiver:
1. The header of the received IP packet is summed in 16-bit units;
2. If the result is 1, the checksum is correct, otherwise the error is discarded;
The principle is very simple, the receiver's calculation object is a and a inverse of the XOR, the result is of course 1!
Examples of specific program implementations are as follows:
Short checksum (ushort* buffer, int size)
{
unsigned long cksum = 0;
while (size>1)
{
Cksum + = *buffer++;
Size-= sizeof (USHORT);
}
if (size)
{
Cksum + = * (uchar*) buffer;
}
Cksum = (cksum>>16) + (CKSUM&0XFFFF);
Cksum + = (cksum>>16);
Return (USHORT) (~cksum);
}
IP header:
4500 0046
17d9 0000
4011 ec1d (check field)
AC1C 0f3b
AC1C 0F3D
Calculation:
4500 + 0046 +17d9 + 0000 + 4011+ EC1D +ac1c + 0f3b + ac1c + 0f3d
The checksum to be filled is the sum of the removed and added
When the IP packet is received, to check the IP header is correct, the IP header is inspected, the same way:
Calculation:
44500 + 0046 +17d9 + 0000 + 4011+ EC1D +ac1c + 0f3b + ac1c + 0f3d again with their sum and add a number again to FFFF, the results are all one, correct.

IP protocol parsing header checksum

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.