'How to receive headers of the internet/transport layers?
In a program written in C and running on Linux, I use a socket to receive data sent using the IPv4 UDP protocol. In this setup, when performing the recv system call, I currently receive the payload portion of the UDP messages. I would like to receive not only that payload but also the UDP header and the IPv4 header portions (as they are received on the wire).
I am aware that the system call recvmsg can provide access to some of the information located in those headers but that's not what I am looking for. I am also aware of raw sockets (here) as well as packet sockets (here), I am fine with a solution using such sockets as long as it does not require special privileges (like CAP_NET_RAW for example). I am fine with any solution which also includes the header of the link layer protocol (Ethernet, WiFi, ...).
I am working with a piece of code that was designed to receive entire IP packets. I am trying to get a suitable input for that piece of code. I could try to prefix the UDP payloads I am currently receiving with forged headers (using info from recvmsg) but I am not entierely sure that this can be done without creating issues downstream and I was hoping to find a better/simpler/safer alternative. Raw sockets look great but they seem to require special privileges even for this particular use case (reception of UDP messages)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
