aboutsummaryrefslogtreecommitdiffstats
path: root/pcap-nit.c
diff options
context:
space:
mode:
authorguy <guy>2003-11-04 07:05:32 +0000
committerguy <guy>2003-11-04 07:05:32 +0000
commit991d444f7116bef16893826b46f3950f62281507 (patch)
treea6e3cc271bc1560beb89dcc0d0c3893297bbba0b /pcap-nit.c
parent4246a40e00fd598e3af4ab8e4251749968b086c1 (diff)
Add a "pcap_breakloop()" API to break out of the loop in
"pcap_dispatch()" and "pcap_loop()".
Diffstat (limited to 'pcap-nit.c')
-rw-r--r--pcap-nit.c22
1 files changed, 21 insertions, 1 deletions
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);