获取IPv6标头的确切大小,包括扩展标头 [英] Get exact size of IPv6 header including the extenstion headers

查看:113
本文介绍了获取IPv6标头的确切大小,包括扩展标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果IPv4存在问题,并且我想从std :: istream中提取IP和ICMP标头,则首先获取初始20个字节,然后按顺序检查IPv4标头中提供的标头长度是否大于20个字节提取任何选项.接下来的字节是ICMP数据包.使用IPv4标头中携带的标头长度值,我可以看到IP标头的预期大小.

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.

但是如何获取IPv6标头的确切大小? IPv6标头中有一个有效负载值,其中包括标头扩展的大小以及更高级别的数据(例如ICMP).我需要知道IPv6标头的大小(包括标头扩展名,但没有更高级别的数据),以便知道ICMPv6标头在std :: istream中从哪个位置开始.

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.

谢谢!

推荐答案

IPv6标头的大小固定为40个字节-尽管您知道,初始IPv6标头后面可能会有一些扩展名,这些扩展名不属于传输层数据报.要确定是否在IPv6标头后面加上标头扩展名,请检查下一个标头"字段.存储在此字段中的值将告诉您下一个标头是传输级标头(IE TCP/UDP标头),IP级标头扩展(IE ICMP)还是两者之间的任何内容. 此列表给出了下一个标头字段的所有可能值的列表.

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.

一旦确定了下一个标头的类型,就可以对其进行相应处理-所有扩展标头的第一个字节应为下一个标头"字段,以便可以将它们链接在一起,并且如果扩展标头是可变长度,其第二个字节应为"hdr ext字段",可用于确定其大小.

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.

这篇关于获取IPv6标头的确切大小,包括扩展标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆