0

I am trying to get an ICMP packet using the recvfrom() function. The function receives a packet including the IP header, I only need the ICMP portion.

Is it possible to somehow configure the socket so that recvfrom() receives only an ICMP packet through it, without the IP header?

I create socket like this:

int sock_fd;
if ((sock_fd = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP)) == -1) {
    perror("socket");
    return ERROR;
}

UPDATE: I got an answer that this is impossible. So, if I make the buffer large, since the length of the IP header can be different, will recvfrom() write only one packet to the buffer, or can it be that the beginning of the next packet will be written to the end of the buffer?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Ivan Ivanovich
  • 880
  • 1
  • 6
  • 15
  • 1
    No. It is not... – user253751 Apr 19 '21 at 17:24
  • understandable, thanks. – Ivan Ivanovich Apr 19 '21 at 17:34
  • 1
    Per the [raw()](https://man7.org/linux/man-pages/man7/raw.7.html) documentation: "*The IPv4 layer generates an IP header when sending a packet unless the `IP_HDRINCL` socket option is enabled on the socket. When it is enabled, the packet must contain an IP header. **For receiving, the IP header is always included in the packet.***" – Remy Lebeau Apr 19 '21 at 21:12
  • thank you, Could it be that recvfrom() will write a packet to the buffer, and part of the next packet, if the buffer size is too large? – Ivan Ivanovich Apr 20 '21 at 08:37

0 Answers0