Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Linux中使用SOCK_RAW接收IPv4数据包?_C_Linux_Ip_Packet - Fatal编程技术网

如何在Linux中使用SOCK_RAW接收IPv4数据包?

如何在Linux中使用SOCK_RAW接收IPv4数据包?,c,linux,ip,packet,C,Linux,Ip,Packet,在Linux中如何接收网络层(OSI第3层)数据包?更具体地说,IPv4数据包与传输层协议(UDP、TCP等)无关。最好是C语言,没有库 使用套接字(AF_INET、SOCK_RAW、IPPROTO_RAW),我只能发送IPv4数据包;未接收。是否尝试从套接字库中使用recvfrom。如本例所示: sock_raw = socket(AF_INET , SOCK_RAW , protocol); while(1) { data_size = recvfrom(sock_raw , buf

在Linux中如何接收网络层(OSI第3层)数据包?更具体地说,IPv4数据包与传输层协议(UDP、TCP等)无关。最好是C语言,没有库


使用
套接字(AF_INET、SOCK_RAW、IPPROTO_RAW)
,我只能发送IPv4数据包;未接收。

是否尝试从套接字库中使用
recvfrom
。如本例所示:

sock_raw = socket(AF_INET , SOCK_RAW , protocol);
while(1)
{
    data_size = recvfrom(sock_raw , buffer , 65536 , 0 , &addr , &addr_size);
}

“我只能发送IPv4数据包,不能接收”。请出示你的密码。如果看不到它,我们就不能指出任何问题。也可以看到,以及“不考虑传输层协议(UDP、TCP等)”。OP希望接收所有IP数据包。你的代码能做到这一点吗?@Victor Fonne我认为你的答案是正确的,但重点不正确(所以可能只需要编辑一下)。钥匙是
SOCK\u RAW