当前位置: 技术问答>linux和unix
如何获取某网络接口上的所有IP包?
来源: 互联网 发布时间:2015-09-24
本文导语: 我写了下面的程序,但是好像收不到数据包,请问问题出在哪儿? int sockfd = socket(AF_INET, SOCK_RAW, htons(ETH_P_IP)); struct ifreq ethreq; strcpy(ethreq.ifr_name, "eth1"); if (ioctl(sockfd, SIOCGIFFLAGS, ðreq) != 0) { perror("ioctl"); exit...
我写了下面的程序,但是好像收不到数据包,请问问题出在哪儿?
int sockfd = socket(AF_INET, SOCK_RAW, htons(ETH_P_IP));
struct ifreq ethreq;
strcpy(ethreq.ifr_name, "eth1");
if (ioctl(sockfd, SIOCGIFFLAGS, ðreq) != 0)
{
perror("ioctl");
exit(1);
}
ethreq.ifr_flags |= IFF_PROMISC;
if (ioctl(sockfd, SIOCSIFFLAGS, ðreq) != 0)
{
perror("ioctl");
exit(2);
}
struct sockaddr_in from;
int fromlen;
char recv_buff[1024];
memset(recv_buff, 0, 1024);
for (int i = 0; i
int sockfd = socket(AF_INET, SOCK_RAW, htons(ETH_P_IP));
struct ifreq ethreq;
strcpy(ethreq.ifr_name, "eth1");
if (ioctl(sockfd, SIOCGIFFLAGS, ðreq) != 0)
{
perror("ioctl");
exit(1);
}
ethreq.ifr_flags |= IFF_PROMISC;
if (ioctl(sockfd, SIOCSIFFLAGS, ðreq) != 0)
{
perror("ioctl");
exit(2);
}
struct sockaddr_in from;
int fromlen;
char recv_buff[1024];
memset(recv_buff, 0, 1024);
for (int i = 0; i