How do I validate the ICMPv6 checksum? (Why am do I keep getting a checksum of 0x3fff?)

前端 未结 3 1784
不知归路
不知归路 2021-01-13 05:05

I\'m working on a Linux userspace program that receives IPv6 router advertisement packets. As part of RFC4861 I need to verify the ICMPv6 checksum. Based on my research, mos

3条回答
  •  逝去的感伤
    2021-01-13 05:58

    I found my bug: I had a 256 byte input buffer and assumed the iov_len element of msg_iov on recvmsg() was modified to return length of data received. Since the length of my router advertisements where a constant 64 bytes, the difference between this lengths resulted in a constant error in the checksum. I did not need to change the byte order to verify the checksum (although I have not had an odd length ICMPv6 packet to verify my handling of the final byte in the odd length case.

    Also, the final NOT of the checksum is only necessary to calculate the checksum, not to verify it. With the above code checksum() will return 0 if the checksum is valid.

提交回复
热议问题