int main(int argc, char **argv) { capdev_t interfaces[32]; int numdev, i; /* Try loading the DLL. */ #ifdef _WIN32 pcap_handle = dynld_module("wpcap.dll", pcap_imports); #else pcap_handle = dynld_module("libpcap.so", pcap_imports); #endif if (pcap_handle == NULL) { #ifdef _WIN32 fprintf(stderr, "Unable to load WinPcap DLL !\n"); #else fprintf(stderr, "Unable to load libpcap.so !\n"); #endif return(1); } /* Get the list. */ numdev = get_devlist(interfaces); if (argc == 1) { /* No arguments, just show the list. */ show_devs(interfaces, numdev); dynld_close(pcap_handle); return(numdev); } /* Assume argument to be the interface number to listen on. */ i = atoi(argv[1]); if (i < 0 || i > numdev) { fprintf(stderr, "Invalid interface number %d !\n", i); dynld_close(pcap_handle); return(1); } /* Looks good, go and listen.. */ i = start_cap(interfaces[i-1].device); dynld_close(pcap_handle); return(i); }
/* Close up shop. */ void network_pcap_close(void) { pcap_t *pc; if (pcap != NULL) { pclog("Closing WinPcap\n"); /* Tell the polling thread to shut down. */ pc = pcap; pcap = NULL; #if 1 /* Terminate the polling thread. */ if (poll_tid != NULL) { thread_kill(poll_tid); poll_tid = NULL; } #else /* Wait for the polling thread to shut down. */ while (poll_tid != NULL) ; #endif /* OK, now shut down WinPcap itself. */ f_pcap_close(pc); /* Unload the DLL if possible. */ if (pcap_handle != NULL) { dynld_close(pcap_handle); pcap_handle = NULL; } } poll_rx = NULL; poll_arg = NULL; }