As part of a homework assignment, I have to write a C program in Linux that generates ICMP replies to ICMP Echo requests using raw sockets. Does the data in the ICMP Packet have to be included in the checksum as well? Or should I calculate the checksum for only the header?
Asked
Active
Viewed 5,405 times
2
-
Removing `c` tag and adding `networking` tag since there is no C code in the question. =) – mpontillo Feb 06 '11 at 02:59
1 Answers
10
It must be calculated from HEADER + DATA. When performing the calculation, let the checksum be zero, then replace it afterwards.
Quoting page 14 (Echo or Echo Reply Message) from the RFC 792:
The checksum is the 16-bit ones's complement of the one's complement sum of the ICMP message starting with the ICMP Type. For computing the checksum , the checksum field should be zero. If the total length is odd, the received data is padded with one octet of zeros for computing the checksum. This checksum may be replaced in the future.