简体   繁体   中英

Receiving Full modified icmp packet in Linux raw socket

I have a specific network card (NetFPGA) which is adding a 8 byte timestamp in the end of the ICMP Echo Reply packet (checksum is ignored). When I tried to read the packet in raw socket this way:

recvsock = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);

I got only the IP + ICMP data without the added timestamp. I tried:

recvsock = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_IP));

This way I get everything and I can't bind any address. Also tried:

recvsock = socket(AF_INET, SOCK_RAW, htons(ETH_P_IP));

But nothing was caught..

Any idea how can I open a raw socket which will catch only the specific ICMP echo reply packets but will not omit the added 8 byte timestamp?

Thanks
Ido

From what I have found apparently there is no way to catch the full packet in the raw socket and still make the socket do the filtering for you. What I had to do is opening a socket this way:

recvsock = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_IP));

For catching all the incoming IP packets and then filtering out my ICMP packets based on libpcap filtering capabilities.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM