Question

in ICMP header they are filling the checksum with the following statement

i found ICMP_ECHO value as 8

 icmp->checksum = htons(~(ICMP_ECHO << 8));

can anyone tell me what exactly it will do and how it will fill the details of checksum

Was it helpful?

Solution

The ICMP checksum is an RFC 1071 checksum:

(1) Adjacent octets to be checksummed are paired to form 16-bit integers, and the 1's complement sum of these 16-bit integers is formed.

(2) To generate a checksum, the checksum field itself is cleared, the 16-bit 1's complement sum is computed over the octets concerned, and the 1's complement of this sum is placed in the checksum field.

The type and code field should be 0x08 0x00 for an ICMP_ECHO message (type 8, code 0), and if this is all the data the message contains then this is also the sum of the 16 bit integers that should form the checksum.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top