2

ICMP messages contain checksums: https://www.rfc-editor.org/rfc/rfc792

Does ping validate the checksums when receiving an echo reply message?

I don't see a note about it in the man page.

I'm using Fedora 27.

FGreg
  • 135
  • TBH the reason I'm asking is because I'm writing a program that needs to compute the checksum but I don't know how to check if I'm doing it right. – FGreg Feb 13 '18 at 08:14

1 Answers1

2

Yes, it does.

From the source code:

csfailed = in_cksum((unsigned short *)icp, cc, 0);

Although it does not seem to check the csfailed when the icp->type == ICMP_ECHOREPLY.

If you just want to see the algorithm for the checksum, check the source code for unsigned short in_cksum and following.

Stefan M
  • 1,616
  • so does that mean if the checksum is not valid, there is no indication? – FGreg Feb 13 '18 at 08:18
  • There is a part that checks whether the ICMP type is "Parameter Problems", but this looks like the incoming packet has this information in the header. You should just give it a try, with the source code you can simply forge a "wrong" checksum to be sent. – Stefan M Feb 13 '18 at 08:30