summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordlg <dlg@openbsd.org>2020-05-27 04:24:01 +0000
committerdlg <dlg@openbsd.org>2020-05-27 04:24:01 +0000
commitc5e4be465a16a5443f18a26b06c2477e1d4700f7 (patch)
tree7aac3a62a3b280b5ac345138f7f34d266a11d375
parentset up rx so packets end up at the end of the mbuf cluster. (diff)
downloadwireguard-openbsd-c5e4be465a16a5443f18a26b06c2477e1d4700f7.tar.xz
wireguard-openbsd-c5e4be465a16a5443f18a26b06c2477e1d4700f7.zip
add support for pcap_breakloop when reading packets from files.
djm pulled support in for pcap_breakloop on the bpf side of things, this makes it work when reading files too. from Caspar Schutijser lteo@ seems keen ok djm@
-rw-r--r--lib/libpcap/savefile.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/lib/libpcap/savefile.c b/lib/libpcap/savefile.c
index 2e6283939f7..fdbd0bbb8e3 100644
--- a/lib/libpcap/savefile.c
+++ b/lib/libpcap/savefile.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: savefile.c,v 1.16 2015/12/22 19:51:04 mmcc Exp $ */
+/* $OpenBSD: savefile.c,v 1.17 2020/05/27 04:24:01 dlg Exp $ */
/*
* Copyright (c) 1993, 1994, 1995, 1996, 1997
@@ -307,6 +307,23 @@ pcap_offline_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
while (status == 0) {
struct pcap_pkthdr h;
+ /*
+ * 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 (PCAP_ERROR_BREAK);
+ } else
+ return (n);
+ }
+
status = sf_next_packet(p, &h, p->buffer, p->bufsize);
if (status) {
if (status == 1)