diff options
author | 2018-04-05 03:47:27 +0000 | |
---|---|---|
committer | 2018-04-05 03:47:27 +0000 | |
commit | 346f594f33ee3e8eaab18406f620d914faf99259 (patch) | |
tree | 7b31fa44bdafbf73a20b58b9d9e55bec15c032b2 | |
parent | Zap the obsolete PF_TRANS_ALTQ. (diff) | |
download | wireguard-openbsd-346f594f33ee3e8eaab18406f620d914faf99259.tar.xz wireguard-openbsd-346f594f33ee3e8eaab18406f620d914faf99259.zip |
Import pcap_set_immediate_mode() from mainline libpcap which allows a
libpcap-based program to process packets as soon as they arrive.
feedback from jasper@
ok jca@
(a long time ago)
-rw-r--r-- | lib/libpcap/pcap-bpf.c | 13 | ||||
-rw-r--r-- | lib/libpcap/pcap-int.h | 3 | ||||
-rw-r--r-- | lib/libpcap/pcap.3 | 14 | ||||
-rw-r--r-- | lib/libpcap/pcap.c | 11 | ||||
-rw-r--r-- | lib/libpcap/pcap.h | 3 | ||||
-rw-r--r-- | lib/libpcap/shlib_version | 2 |
6 files changed, 39 insertions, 7 deletions
diff --git a/lib/libpcap/pcap-bpf.c b/lib/libpcap/pcap-bpf.c index 1b3388835a0..c2b4a83f4a9 100644 --- a/lib/libpcap/pcap-bpf.c +++ b/lib/libpcap/pcap-bpf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pcap-bpf.c,v 1.35 2017/04/19 05:36:12 natano Exp $ */ +/* $OpenBSD: pcap-bpf.c,v 1.36 2018/04/05 03:47:27 lteo Exp $ */ /* * Copyright (c) 1993, 1994, 1995, 1996, 1998 @@ -565,6 +565,16 @@ pcap_activate(pcap_t *p) } } + if (p->opt.immediate) { + v = 1; + if (ioctl(p->fd, BIOCIMMEDIATE, &v) < 0) { + snprintf(p->errbuf, PCAP_ERRBUF_SIZE, + "BIOCIMMEDIATE: %s", pcap_strerror(errno)); + status = PCAP_ERROR; + goto bad; + } + } + if (p->opt.promisc) { /* set promiscuous mode, just warn if it fails */ if (ioctl(p->fd, BIOCPROMISC, NULL) < 0) { @@ -846,6 +856,7 @@ pcap_create(const char *device, char *errbuf) pcap_set_snaplen(p, 65535); /* max packet size */ p->opt.promisc = 0; p->opt.buffer_size = 0; + p->opt.immediate = 0; return (p); } diff --git a/lib/libpcap/pcap-int.h b/lib/libpcap/pcap-int.h index 079db9828f2..eeb08860243 100644 --- a/lib/libpcap/pcap-int.h +++ b/lib/libpcap/pcap-int.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pcap-int.h,v 1.13 2014/04/11 04:08:58 lteo Exp $ */ +/* $OpenBSD: pcap-int.h,v 1.14 2018/04/05 03:47:27 lteo Exp $ */ /* * Copyright (c) 1994, 1995, 1996 @@ -48,6 +48,7 @@ struct pcap_opt { char *source; int promisc; int rfmon; + int immediate; /* immediate mode - deliver packets as soon as they arrive */ }; /* diff --git a/lib/libpcap/pcap.3 b/lib/libpcap/pcap.3 index 51521a9a8ed..ededd6d7ce8 100644 --- a/lib/libpcap/pcap.3 +++ b/lib/libpcap/pcap.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: pcap.3,v 1.46 2016/10/17 02:54:40 lteo Exp $ +.\" $OpenBSD: pcap.3,v 1.47 2018/04/05 03:47:27 lteo Exp $ .\" .\" Copyright (c) 1994, 1996, 1997 .\" The Regents of the University of California. All rights reserved. @@ -19,7 +19,7 @@ .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. .\" -.Dd $Mdocdate: October 17 2016 $ +.Dd $Mdocdate: April 5 2018 $ .Dt PCAP_OPEN_LIVE 3 .Os .Sh NAME @@ -78,6 +78,7 @@ .Nm pcap_set_rfmon , .Nm pcap_set_timeout , .Nm pcap_set_buffer_size , +.Nm pcap_set_immediate_mode , .Nm pcap_activate , .Nm pcap_statustostr , .Nm pcap_offline_filter @@ -195,6 +196,8 @@ .Ft int .Fn pcap_set_buffer_size "pcap_t *p" "int buffer_size" .Ft int +.Fn pcap_set_immediate_mode "pcap_t *p" "int immediate" +.Ft int .Fn pcap_activate "pcap_t *p" .Ft const char * .Fn pcap_statustostr "int errnum" @@ -614,6 +617,13 @@ handle is activated to .Fa buffer_size , which is in units of bytes. .Pp +.Fn pcap_set_immediate_mode +sets whether immediate mode should be set on a capture handle when +the handle is activated. +If +.Fa immediate +is non-zero, immediate mode will be set, otherwise it will not be set. +.Pp .Fn pcap_activate is used to activate a packet capture handle to look at packets on the network, with the options that were set on the handle diff --git a/lib/libpcap/pcap.c b/lib/libpcap/pcap.c index 4a31a043218..1de88199031 100644 --- a/lib/libpcap/pcap.c +++ b/lib/libpcap/pcap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pcap.c,v 1.22 2018/02/06 02:55:48 dlg Exp $ */ +/* $OpenBSD: pcap.c,v 1.23 2018/04/05 03:47:27 lteo Exp $ */ /* * Copyright (c) 1993, 1994, 1995, 1996, 1997, 1998 @@ -223,6 +223,15 @@ pcap_set_timeout(pcap_t *p, int timeout_ms) } int +pcap_set_immediate_mode(pcap_t *p, int immediate) +{ + if (pcap_check_activated(p)) + return PCAP_ERROR_ACTIVATED; + p->opt.immediate = immediate; + return 0; +} + +int pcap_set_buffer_size(pcap_t *p, int buffer_size) { if (pcap_check_activated(p)) diff --git a/lib/libpcap/pcap.h b/lib/libpcap/pcap.h index f5ff8a109b8..04b8334bd4e 100644 --- a/lib/libpcap/pcap.h +++ b/lib/libpcap/pcap.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pcap.h,v 1.18 2016/04/06 08:02:56 jasper Exp $ */ +/* $OpenBSD: pcap.h,v 1.19 2018/04/05 03:47:27 lteo Exp $ */ /* * Copyright (c) 1993, 1994, 1995, 1996, 1997 @@ -168,6 +168,7 @@ int pcap_set_promisc(pcap_t *, int); int pcap_can_set_rfmon(pcap_t *); int pcap_set_rfmon(pcap_t *, int); int pcap_set_timeout(pcap_t *, int); +int pcap_set_immediate_mode(pcap_t *, int); int pcap_set_buffer_size(pcap_t *, int); int pcap_activate(pcap_t *); diff --git a/lib/libpcap/shlib_version b/lib/libpcap/shlib_version index f7b871cfc1e..e5cc0268000 100644 --- a/lib/libpcap/shlib_version +++ b/lib/libpcap/shlib_version @@ -1,2 +1,2 @@ major=8 -minor=3 +minor=4 |