从IPv6数据包获取ICMPV6标头
get ICMPv6 header from IPv6 packet
嗨,我坚持从IPv6数据包获取ICMPV6标头。
size = sizeof(sockaddr_in6);
if ((lenght = recvfrom(socd, buffer, BUFSIZE, 0, (sockaddr *)&receiveSockAddr, &size)) < 0) {
cerr << "recvfrom error" << endl;
}
ip = (ip6_hdr *) buffer;
cout << "Payload length: " << ip->ip6_ctlun.ip6_un1.ip6_un1_plen << endl;
cout << "Payload length ntohs: " << ntohs(ip->ip6_ctlun.ip6_un1.ip6_un1_plen) << endl;
//icmpRec = (icmp6_hdr *) (buffer + ???offset???);
我需要找出如何设置偏移。我知道的唯一方法是获得有效载荷长度,然后是:数据包长度 - 有效载荷长度=我的偏移。但是在> ip-> ip6_ctlun.ip6_un1.ip6_un1_plen 是一些怪异的数字。
从上面的代码中接收:
Payload length: 25332
Payload length ntohs: 62562
将icmp6_echo_request发送到ipv6.google.com
但是,如果我在Wireshark中查看有效载荷长度为8个字节。如何从 uint16_t 正确解码有效载荷号以纠正小数号 8 ?以及如何使IPv6数据包的全尺寸计算偏移?为什么IPv6没有IHL为IPv4?我认为这使工作变得非常复杂。
这可能是问题,尽管我很难消化。
似乎在使用recvFrom()时自动裁剪IPv6标头。
QUOTE
发出的数据包自动将ipv6标头备份给他们(基于目标地址)。插座上的传入数据包带有IPv6标头和任何扩展标头接收。
ipv6人页
因此,基本上您的缓冲区从数据开始,而您要抵消的字节包含一些随机的高层数据。
相关文章:
- g++ 说函数不存在,即使包含正确的标头
- spdlog标头仅与外部fmt一起使用.spdlog错误:'内部':不是'fmt'
- 在CMake中使用find_package时,是否会显式包含标头
- 错误"Could not find Boost"(缺少:上下文标头)
- 如何在标头中声明(或定义)函数的问题
- 如何避免在仅标头库中C++类/变量重定义
- C++算法标头中,为什么要使用 "!(val < *first)" ?
- C++标头错误 C2238 意外标记";"
- std::initializer_list,大括号初始化和标头
- 在 c++ 中拆分类和标头中的继承,错误
- 如何确定哪个标头调用 c++ 中的另一个标头
- 如何在生成文件中添加多个标头 (HDR) 和对象?
- 我可以在运行时重新定义在 OpenCascade/OCCT 标头中定义的 c++ 静态常量吗?
- GCC,CMake,预编译标头和维护依赖项
- VisualStudio:使用 Suse Enterprise Server 12 SP5 时,不会下载远程库标头
- 一个标头库中的错误
- 可视化 Bazel C++预编译标头实现
- 如何在 CMake 中添加预编译标头用于 Visual Studio 生成器
- 使用 GN 构建预编译标头
- 从IPv6数据包获取ICMPV6标头