2 * Focused test app to enable checking of libpcap with valgrind
4 * Build with: $ gcc -W -Wall -g test-libpcap.c -lpcap -o test-libpcap
11 #include <netinet/in.h>
13 int main(int argc, char **argv) {
15 char *dev = NULL, *device="eth1";
16 pcap_if_t *this_dev, *alldevsp;
17 char *pcap_filter = "tcp port 80";
18 char errbuf[PCAP_ERRBUF_SIZE];
19 struct bpf_program fp;
21 printf("Starting %s with %d arguments\n", argv[0], argc );
22 printf("Using %s\n", pcap_lib_version());
23 printf("Device %s wanted\n", device);
25 printf("calling pcap_findalldevs()\n");
26 if (pcap_findalldevs(&alldevsp, errbuf) == 0) {
27 printf("pcap_findalldevs() done.\n");
30 while (this_dev != NULL) {
31 printf("device %s\n",this_dev->name);
32 if (strcmp(device, this_dev->name) == 0) {
36 this_dev = this_dev->next;
40 fprintf(stderr, "Error: pcap_findalldevs()\n");
43 pcap_freealldevs(alldevsp); // free list memory
45 dev = pcap_lookupdev(errbuf);
46 printf("pcap_lookupdev() done\n");
48 descr = pcap_open_live(dev, BUFSIZ, 0, 1024, errbuf);
49 printf("pcap_open_live() done\n");
51 if(pcap_compile(descr, &fp, pcap_filter, 0, htonl(0xFFFF0000)) != -1) {
52 printf("pcap_compile() done\n");
53 if(pcap_setfilter(descr, &fp) == 0) {
54 printf("pcap_setfilter() done\n");