Get exact size of IPv6 header including the extenstion headers
Asked Answered
C

1

0

If IPv4 is in question and I want to extract IP and ICMP header out of std::istream, first I get the initial 20 bytes, then check if the header lenght provided in the IPv4 header is larger than 20 bytes in order to extract any options. The next bytes are the ICMP packet. Using the header lenght value carried inside the IPv4 header I can see the expect size of the IP header.

However how to get the exact size of IPv6 header? There is a payload value inside IPv6 header that includes the size of header extensions plus higher level data such as ICMP. I need to know the size of IPv6 header including the header extensions but without higher level data, in order to know at what position the ICMPv6 header starts in the std::istream.

Thank you!

Cutpurse answered 7/2, 2013 at 22:23 Comment(0)
F
12

The size of the IPv6 header is fixed at 40 bytes - though as you know there may be extensions that follow the initial IPv6 header that aren't part of the transport layer datagram. To determine whether the IPv6 header is followed by header extensions, check the 'next header' field. The value stored in this field will tell you whether the next header is a transport level header (IE TCP/UDP header), a IP level header extension (IE ICMP), or anything in between. This list gives a list of all the possible values for the next header field.

Once you determine the type of the next header, you can then deal with it accordingly - the first byte of all extension headers should be the 'next header' field so that they can be chained together, and if the extension header is variable length its second byte should be the 'hdr ext field' which can be used to determine its size.

Felafel answered 8/2, 2013 at 0:8 Comment(1)
Ahh thanks. The link is a good one. I thought the ICMP part is not considered as IPv6 extension header. The only question left is whether in a case of ICMP echo reply IP packet, there can be more extension headers next or after the ICMP header? Or ICMP header always comes after the first 40 bytes?Cutpurse

© 2022 - 2024 — McMap. All rights reserved.