A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

#1 2018-04-24 03:55 AM

Registered: 2018-04-24
Posts: 1

Getting IP header from UDP recvfrom call

Getting IP header from UDP recvfrom call

Is there any way to get the IP and UDP header when calling recvfrom with a UDP socket, or do I have to receive the UDP packet using raw sockets to get these details (like a sniffer)?

I'm kinda wondering if there is some socket option I can set in such a way that I could read this information out of the "buf" parameter in recvfrom (such that in a IPv4 standard header the first byte would be 0x45, etc). Preferably I'm looking to do this on BSD and Linux.

Thanks in advance.


#2 2018-04-24 01:33 PM

From: Boston, MA
Registered: 2002-06-12
Posts: 3,839

Re: Getting IP header from UDP recvfrom call

If you really need the full headers, then I think the only choice is to use a raw or packet socket...  If you're only doing this to get at the destination IP from the header, then you may be able to use something like IP_PKTINFO or IP_RECVORIGDSTADDR instead...


Board footer

Powered by FluxBB