Hello. I've just started using libpcap lib and been following some tutorials.
Code:
#include <pcap.h>
#include <stdlib.h>
#include <stdio.h>
void dump(const unsigned char *data_buffer, const unsigned int length);
void pcap_fatal(const char *failed_in, const char *errbuf);
int main() {
struct pcap_pkthdr header;
const u_char *packet;
char errbuf[PCAP_ERRBUF_SIZE];
char *device;
pcap_t *pcap_handle;
int i;
pcap_handle = pcap_open_live(device, 4096, 1, 0, errbuf);
if(pcap_handle == NULL)
pcap_fatal("pcap_open_live", errbuf);
for(i=0; i < 3; i++) {
packet = pcap_next(pcap_handle, &header);
printf("Got a %d byte packet\n", header.len);
dump(packet, header.len);
}
pcap_close(pcap_handle);
}
Code:
xyz@ubuntu:~/Desktop/Programs$ gcc -o sniff libpcap.c -l pcap
xyz@ubuntu:~/Desktop/Programs$ ./sniff
Fatal Error in pcap_open_live: socket: Operation not permitted
xyz@ubuntu:~/Desktop/Programs$ sudo ./sniff
Fatal Error in pcap_open_live: SIOCGIFHWADDR: No such device
Apparently pcap_live_open() keeps returning NULL, therefore the error I don't quite understand. I went over dozens of topics searching for solution, but couldn't quite find it.
As far as I get it, SIOCGIFHWADDR is an interface hardware address but I'm not sure what it's all about.
Thanks in advance,
Mercurial