recvfrom icmp packet without ip header

252 Views Asked by At

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?

0

There are 0 best solutions below