summaryrefslogtreecommitdiff
path: root/lib/libpcap/pcap.c
diff options
context:
space:
mode:
authorJasper Lievisse Adriaanse <jasper@cvs.openbsd.org>2016-04-06 08:02:57 +0000
committerJasper Lievisse Adriaanse <jasper@cvs.openbsd.org>2016-04-06 08:02:57 +0000
commit33366b20bccbcb71b6f38e9e42753643e4042d53 (patch)
tree2941d29e61a5895c16dc380c864a5b7ed6149750 /lib/libpcap/pcap.c
parent3d71de99a99edd6cce44b3c66be8af26ac0ba7e7 (diff)
add two functions from libpcap-1.7.4 which are required by at least gopacket
ok lteo@ "go for it" dlg@
Diffstat (limited to 'lib/libpcap/pcap.c')
-rw-r--r--lib/libpcap/pcap.c37
1 files changed, 36 insertions, 1 deletions
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)
{