30 #define NUM_CLIENTS 128 42 char errbuf[PCAP_ERRBUF_SIZE];
44 bpf_u_int32 netmask, network;
45 struct bpf_program filter_prog;
48 for (i = 0; (i < (
NUM_CLIENTS - 1)) && (pcaps[i]); i++)
59 iface = pcap_lookupdev (errbuf);
61 ret = pcap_open_live (iface, 1500, 0, 1, errbuf);
68 if (pcap_lookupnet (iface, &network, &netmask, 0) < 0)
75 if (pcap_compile (ret, &filter_prog, filter, 1, netmask) < 0)
77 pcap_perror (ret,
"pcap_compile");
82 if (pcap_setnonblock (ret, 1, NULL) == -1)
84 pcap_perror (ret,
"pcap_setnonblock");
86 (
"call to pcap_setnonblock failed, some plugins/scripts will" 87 " hang/freeze. Upgrade your version of libcap!");
90 if (pcap_setfilter (ret, &filter_prog) < 0)
92 pcap_perror (ret,
"pcap_setfilter\n");
97 pcap_freecode (&filter_prog);
107 struct pcap_pkthdr head;
110 gettimeofday (&timeout, NULL);
111 timeout.tv_sec += tv->tv_sec;
112 timeout.tv_usec += tv->tv_usec;
113 while (timeout.tv_usec >= 1000000)
116 timeout.tv_usec -= 1000000;
121 p = (u_char *) pcap_next (pcaps[bpf], &head);
122 *caplen = head.caplen;
125 gettimeofday (&now, NULL);
128 ((now.tv_sec > timeout.tv_sec)
129 || (now.tv_sec == timeout.tv_sec && now.tv_usec >= timeout.tv_usec)));
139 struct timeval tv = { 0, 100000 };
148 return pcap_datalink (pcaps[bpf]);
155 pcap_close (pcaps[bpf]);
void log_legacy_write(const char *format,...)
Legacy function to write a log message.
int bpf_datalink(int bpf)
int bpf_open_live(char *iface, char *filter)
struct timeval timeval(unsigned long val)
u_char * bpf_next(int bpf, int *caplen)
u_char * bpf_next_tv(int bpf, int *caplen, struct timeval *tv)