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