From 991d444f7116bef16893826b46f3950f62281507 Mon Sep 17 00:00:00 2001 From: guy Date: Tue, 4 Nov 2003 07:05:32 +0000 Subject: Add a "pcap_breakloop()" API to break out of the loop in "pcap_dispatch()" and "pcap_loop()". --- pcap-nit.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'pcap-nit.c') diff --git a/pcap-nit.c b/pcap-nit.c index 44db9af..b5fbb42 100644 --- a/pcap-nit.c +++ b/pcap-nit.c @@ -20,7 +20,7 @@ */ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/libpcap/pcap-nit.c,v 1.49 2003-07-25 05:32:04 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/libpcap/pcap-nit.c,v 1.50 2003-11-04 07:05:35 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -126,6 +126,26 @@ pcap_read_nit(pcap_t *p, int cnt, pcap_handler callback, u_char *user) n = 0; ep = bp + cc; while (bp < ep) { + /* + * Has "pcap_breakloop()" been called? + * If so, return immediately - if we haven't read any + * packets, clear the flag and return -2 to indicate + * that we were told to break out of the loop, otherwise + * leave the flag set, so that the *next* call will break + * out of the loop without having read any packets, and + * return the number of packets we've processed so far. + */ + if (p->break_loop) { + if (n == 0) { + p->break_loop = 0; + return (-2); + } else { + p->cc = ep - bp; + p->bp = bp; + return (n); + } + } + nh = (struct nit_hdr *)bp; cp = bp + sizeof(*nh); -- cgit v1.2.3