As part of a homework assignment, I have to write a C开发者_JS百科 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?
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.
精彩评论