请任何人都可以帮助解决这个问题.请
在下面的示例代码中,我们将原始sock绑定到eth0.但是在运行程序时,原始sock的recvfrom正在同一台机器(xx_86)上从eth0和eth1接收数据包.我不清楚为什么,可以在这个问题上帮助一个人.我希望setsockopt不能正常运行OS:Fedora core 6(2.6.18-1.2798.fc6)
Sampe代码:
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <linux/if_ether.h>
#include <net/if.h>
#include <linux/filter.h>
#include <sys/ioctl.h>
#include <string.h>
#include <arpa/inet.h>
int main(int argc, char **argv) {
int sock, i;
unsigned char buffer[2048];
unsigned char tbuff[2048];
unsigned char *iphead, *ethhead,*phead;
struct ifreq ethreq;
// NOTE: use TCPDUMP to build the filter array.
// set filter to sniff only port 443
// $ sudo tcpdump -dd port 443
// raw for recvfrom eth0 …Run Code Online (Sandbox Code Playgroud)