Reading from the Ethernet card.
Hello to all.
I'm developing a simple sniffer using, for now, the library set: libpcap. I'm using this functions to open the socket for reading.
Code:
int sock;
char *dev;
char errbuf[PCAP_ERRBUF_SIZE];
/*Find the Ethernet interface*/
dev = pcap_lookupdev(errbuf));
/*Show the interface name found*/
printf("Reading from: %s\n",dev);
/* Open the socket to read only Ethernet frames*/
sock=socket(PF_PACKET,SOCK_RAW,htons(ETH_P_ALL));
/* Associate the socket to the interface found */
setsockopt(sock,SOL_SOCKET,SO_BINDTODEVICE,dev,strlen(dev));
This is working fine, but the problem is that my PC has two interface cards (eth0 and eth1). I would like to choose the card I want to sniff and function pcap_lookupdev() only returns the first one it finds to be up.
Is there another way to achieve this?
Thanks!