How can I compute the checksum of an ICMP echo request or reply when the checksum should include the data portion, the data portion can be variable sized, and there's no way to anticipate the data size?
Here's documentation on how to compute the checksum of an ICMP header.
ICMP Header Checksum. 16 bits. The 16-bit one's complement of the one's complement sum of the ICMP message, starting with the ICMP Type field. When the checksum is computed, the checksum field should first be cleared to 0. When the data packet is transmitted, the checksum is computed and inserted into this field. When the data packet is received, the checksum is again computed and verified against the checksum field. If the two checksums do not match then an error has occurred.