
In the interests of consistency, the implementations described here prefer normal zero over negative zero in all cases (even where the data is all zeros). It would not feasible for an incremental algorithm to replicate this idiosyncrasy.

Pad the data to an even number of bytes.The checksum can be calculated using the following algorithm:

Given the message to be sent, you wish to calculate the required checksum. Like all ICMP messages this contains a checksum that is calculated using the algorithm described above. Suppose that you wish to send an ICMP echo request using a raw socket. Implementation techniques are discussed in RFC 1071, RFC 1141 and RFC 1624. The same algorithm is used by a number of other IP-based protocols including TCP, UDP and ICMP. For purposes of computing the checksum, the value of the checksum field is zero. RFC 791 defines the following checksum algorithm for use when constructing the header of an IPv4 datagram: The checksum field is the 16 bit one's complement of the one's complement sum of all 16 bit words in the header. To calculate an Internet Protocol checksum in C Background
