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
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.