Question

So I've got a socket like the following:

sock = socket.socket(socket.AF_INET6, socket.SOCK_RAW, socket.getprotobyname("icmp"))

and when i send out a properly constructed ICMP6 ECHO REQUEST per RFC4443 with type 128 and code 0 (also validated checksum) the packet is dropped by the destination's stack because the packet is malformed, obviously, since the 'next header' byte in the IPv6 header is set to 1 per RFC (# for ICMP).

Two things: 1. I know socket.getprotobyname("icmp") makes the socket ICMP compatible with IPv4 (right?)... 2. Wireshark reads the packet as IPv6 but the protocol as ICMP not ICMPv6...

EITHER set the socket to use protocolbyname("icmpv6") (which is invalid, apparently. unless someone knows the proper string... I've tried "icmp6" "icmpv6" but there's probably some tries with an underscore I could make).

OR change the 'next header' byte before I send the packet to 58.

LAST RESORT construct the packet by hand.

Anyone have an idea? I'm not the most experienced in Python, obviously.

Was it helpful?

Solution 2

For anyone that comes across this, socket.getprotobyname('<proto>') returns an integer corresponding to a protocol listed in a flat file in /etc/protocols (Unix) and /c/windows/system32/drivers/etc/protocols (Windows). Check them out! That's the only byte in an IP header that is specific the the data within its payload. The list on a Unix machine contains ALL the protocols, well, at least on a mac, and Windows contains just the most common. You can edit this file too.

OTHER TIPS

This should do it:

socket.getprotobyname('ipv6-icmp')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top