Hi i'm stuck on getting ICMPv6 header from IPv6 packet.
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???);
I need find out how to set the offset. Only way I know is to get payload length and then the: packet length - payload length = my offset. But in ip->ip6_ctlun.ip6_un1.ip6_un1_plen are some weird numbers.
From the code above im receiving:
Payload length: 25332
Payload length ntohs: 62562
after sending ICMP6_ECHO_REQUEST to ipv6.google.com
But if I look in wireshark the Payload length is 8 bytes. How to correctly decode the payload number from uint16_t to correct decimal number 8? And how get the whole size of IPv6 packet to calculate the offset? Why IPv6 haven't IHL as IPv4? This very complicate the work aroud IPv6 I think.