This imports pcap_set_immediate_mode() from mainline libpcap, which allows
a libpcap-based program to process packets as soon as they arrive.
ok?
Index: pcap-bpf.c
===
RCS file: /cvs/src/lib/libpcap/pcap-bpf.c,v
retrieving revision 1.34
diff -u -p -r1.34 pcap-bpf.c
--- pcap-bpf.c 8 May 2016 08:20:50 - 1.34
+++ pcap-bpf.c 5 Oct 2016 02:33:50 -
@@ -565,6 +565,16 @@ pcap_activate(pcap_t *p)
}
}
+ if (p->opt.immediate) {
+ v = 1;
+ if (ioctl(p->fd, BIOCIMMEDIATE, ) < 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 *er
pcap_set_snaplen(p, 65535); /* max packet size */
p->opt.promisc = 0;
p->opt.buffer_size = 0;
+ p->opt.immediate = 0;
return (p);
}
Index: pcap-int.h
===
RCS file: /cvs/src/lib/libpcap/pcap-int.h,v
retrieving revision 1.13
diff -u -p -r1.13 pcap-int.h
--- pcap-int.h 11 Apr 2014 04:08:58 - 1.13
+++ pcap-int.h 5 Oct 2016 02:34:37 -
@@ -48,6 +48,7 @@ struct pcap_opt {
char*source;
int promisc;
int rfmon;
+ int immediate; /* immediate mode - deliver packets as soon as
they arrive */
};
/*
Index: pcap.3
===
RCS file: /cvs/src/lib/libpcap/pcap.3,v
retrieving revision 1.45
diff -u -p -r1.45 pcap.3
--- pcap.3 6 Apr 2016 09:10:28 - 1.45
+++ pcap.3 5 Oct 2016 02:39:24 -
@@ -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"
@@ -613,6 +616,13 @@ sets the buffer size that will be used o
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
Index: pcap.c
===
RCS file: /cvs/src/lib/libpcap/pcap.c,v
retrieving revision 1.19
diff -u -p -r1.19 pcap.c
--- pcap.c 6 Apr 2016 08:02:56 - 1.19
+++ pcap.c 5 Oct 2016 02:24:57 -
@@ -223,6 +223,15 @@ pcap_set_timeout(pcap_t *p, int timeout_
}
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))
Index: pcap.h
===
RCS file: /cvs/src/lib/libpcap/pcap.h,v
retrieving revision 1.18
diff -u -p -r1.18 pcap.h
--- pcap.h 6 Apr 2016 08:02:56 - 1.18
+++ pcap.h 5 Oct 2016 02:44:34 -
@@ -168,6 +168,7 @@ int pcap_set_promisc(pcap_t *, int);
intpcap_can_set_rfmon(pcap_t *);
intpcap_set_rfmon(pcap_t *, int);
intpcap_set_timeout(pcap_t *, int);
+intpcap_set_immediate_mode(pcap_t *, int);
intpcap_set_buffer_size(pcap_t *, int);
intpcap_activate(pcap_t *);
Index: shlib_version
===
RCS file: /cvs/src/lib/libpcap/shlib_version,v
retrieving revision 1.15
diff -u -p -r1.15 shlib_version
--- shlib_version 6 Apr 2016 08:02:56 - 1.15
+++ shlib_version 5 Oct 2016 02:41:15 -
@@ -1,2 +1,2 @@
major=8
-minor=1
+minor=2