summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjasper <jasper@openbsd.org>2016-04-06 08:02:56 +0000
committerjasper <jasper@openbsd.org>2016-04-06 08:02:56 +0000
commit1f92dbfe5a38a2eadf576107d632c69c09705def (patch)
treedfedd3c32b761d8dd3c226ff68342aea18904130
parentcompare pointer to NULL instead of 0 (diff)
downloadwireguard-openbsd-1f92dbfe5a38a2eadf576107d632c69c09705def.tar.xz
wireguard-openbsd-1f92dbfe5a38a2eadf576107d632c69c09705def.zip
add two functions from libpcap-1.7.4 which are required by at least gopacket
ok lteo@ "go for it" dlg@
-rw-r--r--lib/libpcap/pcap.320
-rw-r--r--lib/libpcap/pcap.c37
-rw-r--r--lib/libpcap/pcap.h5
-rw-r--r--lib/libpcap/shlib_version2
4 files changed, 57 insertions, 7 deletions
diff --git a/lib/libpcap/pcap.3 b/lib/libpcap/pcap.3
index 9ddc2072430..57931973a94 100644
--- a/lib/libpcap/pcap.3
+++ b/lib/libpcap/pcap.3
@@ -1,4 +1,4 @@
-.\" $OpenBSD: pcap.3,v 1.43 2015/11/15 23:59:21 jmc Exp $
+.\" $OpenBSD: pcap.3,v 1.44 2016/04/06 08:02:56 jasper 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: November 15 2015 $
+.Dd $Mdocdate: April 6 2016 $
.Dt PCAP_OPEN_LIVE 3
.Os
.Sh NAME
@@ -64,6 +64,7 @@
.Nm pcap_setnonblock ,
.Nm pcap_set_datalink ,
.Nm pcap_list_datalinks ,
+.Nm pcap_free_datalinks ,
.Nm pcap_open_dead ,
.Nm pcap_fopen_offline ,
.Nm pcap_lib_version ,
@@ -78,7 +79,8 @@
.Nm pcap_set_timeout ,
.Nm pcap_set_buffer_size ,
.Nm pcap_activate ,
-.Nm pcap_statustostr
+.Nm pcap_statustostr ,
+.Nm pcap_offline_filter
.Nd Packet Capture library
.Sh SYNOPSIS
.In pcap.h
@@ -164,6 +166,8 @@
.Fn pcap_set_datalink "pcap_t *p" "int dlt"
.Ft int
.Fn pcap_list_datalinks "pcap_t *p" "int **dlt_buffer"
+.Ft void
+.Fn pcap_free_datalinks "int *dlt_list"
.Ft pcap_t
.Fn pcap_open_dead "int linktype" "int snaplen"
.Ft pcap_t
@@ -194,6 +198,8 @@
.Fn pcap_activate "pcap_t *p"
.Ft const char *
.Fn pcap_statustostr "int errnum"
+.Ft int
+.Fn pcap_offline_filter "const struct bpf_program *" "const struct pcap_pkthdr *" "const u_char *"
.Sh DESCRIPTION
.Nm
provides a high level interface to packet capture systems.
@@ -530,7 +536,10 @@ to be captured.
.Fn pcap_list_datalinks
returns an array of the supported datalink types for an opened live capture
device as a \-1 terminated array.
-It is the caller's responsibility to free this list.
+It is the caller's responsibility to free this list with
+.Fn pcap_free_datalinks ,
+which frees the list of link-layer header types pointed to by
+.Dv dlt_list .
.Pp
.Fn pcap_breakloop
safely breaks out of a
@@ -613,6 +622,9 @@ being in effect.
.Fn pcap_statustostr
converts a PCAP_ERROR_ or PCAP_WARNING_ value returned by a libpcap
routine to an error string.
+.Pp
+.Fn pcap_offline_filter
+checks wether a filter matches a packet.
.Sh SEE ALSO
.Xr pcap-filter 3 ,
.Xr tcpdump 8
diff --git a/lib/libpcap/pcap.c b/lib/libpcap/pcap.c
index 4372e22ead7..0a41bc43b88 100644
--- a/lib/libpcap/pcap.c
+++ b/lib/libpcap/pcap.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pcap.c,v 1.18 2016/04/05 21:24:02 krw Exp $ */
+/* $OpenBSD: pcap.c,v 1.19 2016/04/06 08:02:56 jasper Exp $ */
/*
* Copyright (c) 1993, 1994, 1995, 1996, 1997, 1998
@@ -278,6 +278,23 @@ pcap_list_datalinks(pcap_t *p, int **dlt_buffer)
}
}
+/*
+ * In Windows, you might have a library built with one version of the
+ * C runtime library and an application built with another version of
+ * the C runtime library, which means that the library might use one
+ * version of malloc() and free() and the application might use another
+ * version of malloc() and free(). If so, that means something
+ * allocated by the library cannot be freed by the application, so we
+ * need to have a pcap_free_datalinks() routine to free up the list
+ * allocated by pcap_list_datalinks(), even though it's just a wrapper
+ * around free().
+ */
+void
+pcap_free_datalinks(int *dlt_list)
+{
+ free(dlt_list);
+}
+
struct dlt_choice {
const char *name;
const char *description;
@@ -622,6 +639,24 @@ pcap_open_dead(int linktype, int snaplen)
return p;
}
+/*
+ * Given a BPF program, a pcap_pkthdr structure for a packet, and the raw
+ * data for the packet, check whether the packet passes the filter.
+ * Returns the return value of the filter program, which will be zero if
+ * the packet doesn't pass and non-zero if the packet does pass.
+ */
+int
+pcap_offline_filter(const struct bpf_program *fp, const struct pcap_pkthdr *h,
+ const u_char *pkt)
+{
+ struct bpf_insn *fcode = fp->bf_insns;
+
+ if (fcode != NULL)
+ return (bpf_filter(fcode, pkt, h->len, h->caplen));
+ else
+ return (0);
+}
+
const char *
pcap_lib_version(void)
{
diff --git a/lib/libpcap/pcap.h b/lib/libpcap/pcap.h
index f2b15b56c63..f5ff8a109b8 100644
--- a/lib/libpcap/pcap.h
+++ b/lib/libpcap/pcap.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: pcap.h,v 1.17 2016/04/02 08:49:49 dlg Exp $ */
+/* $OpenBSD: pcap.h,v 1.18 2016/04/06 08:02:56 jasper Exp $ */
/*
* Copyright (c) 1993, 1994, 1995, 1996, 1997
@@ -198,9 +198,12 @@ int pcap_compile(pcap_t *, struct bpf_program *, char *, int,
int pcap_compile_nopcap(int, int, struct bpf_program *,
char *, int, bpf_u_int32);
void pcap_freecode(struct bpf_program *);
+int pcap_offline_filter(const struct bpf_program *,
+ const struct pcap_pkthdr *, const u_char *);
int pcap_datalink(pcap_t *);
int pcap_list_datalinks(pcap_t *, int **);
int pcap_set_datalink(pcap_t *, int);
+void pcap_free_datalinks(int *);
int pcap_datalink_name_to_val(const char *);
const char *pcap_datalink_val_to_name(int);
const char *pcap_datalink_val_to_description(int);
diff --git a/lib/libpcap/shlib_version b/lib/libpcap/shlib_version
index d0f0988b418..00604e64e7d 100644
--- a/lib/libpcap/shlib_version
+++ b/lib/libpcap/shlib_version
@@ -1,2 +1,2 @@
major=8
-minor=0
+minor=1