I'm trying to parse IPv6 packet received through raw socket and decide if it is ICMPv6 or not. I can process the Ethernet and IPv6 header, but then there are optional extension headers. If the Next Header
field of IPv6 header is not ICMPv6, I have to iterate through any extensions that might precede.
The iteration itself is not a problem as each extension header carry its length. However, I can't find a good way to differentiate between extension header that might follow and other upper-level protocols such as TCP and UDP. I can either check if the Next Header
is one of known extension headers (in which case I can iterate) or if the Next Header
is upper-layer protocol (in which case I have to stop, there won't be any ICMP..).
In both approaches I'm relying on some self-built list of constants against which I'm checking Next Header
and that list might change in future. Isn't there a better way to tell when I'm at the end of extension headers and upper-layer header (or nothing) follows?