Skip to contentSkip to conversation

IPv6 raw socket and recvfrom

DISCUSSION Paul Rolland 2 participants 2 messages Aug 17, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hello,

I'd like someone to clarify the behavior I can expect from a RAW IPv6 socket _in Linux_ :
- Raw IPv4 sockets : recvfrom() payload contain all the IP header, including src ip, dst ip, etc...

- Raw IPv6 sockets : so far, recvfrom returns me only the payload. I've added the HDRINCL options, but it seems that this is a no-op in IPv6-land.

I've reviewed RFC 3542, which states that I'm not to expect ip6 header, but often "there is more than one way to do it", and I'd like to be sure I'm not missing something obvious

Paul

PS : I'm not subscribed to netdev, so please answer directly...

#1 lore raw
Quoted 8 lines · Paul Rolland

I'd like someone to clarify the behavior I can expect from a RAW IPv6 socket _in Linux_ :
- Raw IPv4 sockets : recvfrom() payload contain all the IP header, including src ip, dst ip, etc...

- Raw IPv6 sockets : so far, recvfrom returns me only the payload. I've added the HDRINCL options, but it seems that this is a no-op in IPv6-land.

Yes and no. You get the packet size from the return value of recvfrom(). You can also get the source address from the recvfrom() address parameter. And you can additionally get the hop limit, destination address and type of service as ancillary data with recvmsg(). Finally, you can have the kernel verify the checksum field for you (and discard broken packets), and of course the IP version. In the end, the only unknown field is the flow information, for which there is no standardized API that I know.

Quoted 3 lines

I've reviewed RFC 3542, which states that I'm not to expect ip6 header, but often "there is more than one way to do it", and I'd like to be sure I'm not missing something obvious

On Linux, you should use AF_PACKET sockets if you want to receive (or send) raw packets including the network header. Alternatively, you can use libpcap (which really is a wrapper around AF_PACKET anyway).

Signature · 3 lines
Rémi Denis-Courmont
http://www.remlab.net
http://fi.linkedin.com/in/remidenis