2016-11-20 00:31:45 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <pcap.h>
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
|
2016-11-20 05:15:43 +00:00
|
|
|
char *device_name,errbuf[PCAP_ERRBUF_SIZE];
|
2016-11-20 00:31:45 +00:00
|
|
|
|
2016-12-01 02:27:34 +00:00
|
|
|
pcap_t *handle;
|
|
|
|
|
2016-11-20 05:15:43 +00:00
|
|
|
device_name=pcap_lookupdev(errbuf);
|
|
|
|
if (device_name==NULL) {
|
2016-12-01 02:27:34 +00:00
|
|
|
fprintf(stderr,"Can't find default device %s\n",errbuf);
|
2016-11-20 05:15:43 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("Using device: %s\n", device_name);
|
2016-11-20 00:31:45 +00:00
|
|
|
|
2016-12-01 02:27:34 +00:00
|
|
|
handle=pcap_open_live(device_name, BUFSIZ, 1, 1000, errbuf);
|
|
|
|
if (handle==NULL) {
|
|
|
|
fprintf(stderr,"Couldn't open device %s: %s\n",
|
|
|
|
device_name,errbuf);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-11-20 00:31:45 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|