summaryrefslogtreecommitdiffstats
path: root/lib/libpcap/pcap.c
diff options
context:
space:
mode:
authordjm <djm@openbsd.org>2006-03-26 20:58:50 +0000
committerdjm <djm@openbsd.org>2006-03-26 20:58:50 +0000
commitc1bf12094404ebc3b7ccf06bb14f4f887336dff8 (patch)
treeba1f6b420de7e59477065b9f8a9ce455ad4cb23e /lib/libpcap/pcap.c
parentExplain a bit more about the usage of isagpio(4). (diff)
downloadwireguard-openbsd-c1bf12094404ebc3b7ccf06bb14f4f887336dff8.tar.xz
wireguard-openbsd-c1bf12094404ebc3b7ccf06bb14f4f887336dff8.zip
add remaining tcpdump.org libpcap 0.9 APIs, most notably
pcap_setdirection() (which depends on the kernel-side bpf changes committed yesterday); ok canacar@
Diffstat (limited to 'lib/libpcap/pcap.c')
-rw-r--r--lib/libpcap/pcap.c72
1 files changed, 71 insertions, 1 deletions
diff --git a/lib/libpcap/pcap.c b/lib/libpcap/pcap.c
index 30f58292718..6c516f39e32 100644
--- a/lib/libpcap/pcap.c
+++ b/lib/libpcap/pcap.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pcap.c,v 1.9 2005/11/18 11:05:39 djm Exp $ */
+/* $OpenBSD: pcap.c,v 1.10 2006/03/26 20:58:51 djm Exp $ */
/*
* Copyright (c) 1993, 1994, 1995, 1996, 1997, 1998
@@ -111,6 +111,70 @@ pcap_next(pcap_t *p, struct pcap_pkthdr *h)
return (s.pkt);
}
+struct pkt_for_fakecallback {
+ struct pcap_pkthdr *hdr;
+ const u_char **pkt;
+};
+
+static void
+pcap_fakecallback(u_char *userData, const struct pcap_pkthdr *h,
+ const u_char *pkt)
+{
+ struct pkt_for_fakecallback *sp = (struct pkt_for_fakecallback *)userData;
+
+ *sp->hdr = *h;
+ *sp->pkt = pkt;
+}
+
+int
+pcap_next_ex(pcap_t *p, struct pcap_pkthdr **pkt_header,
+ const u_char **pkt_data)
+{
+ struct pkt_for_fakecallback s;
+
+ s.hdr = &p->pcap_header;
+ s.pkt = pkt_data;
+
+ /* Saves a pointer to the packet headers */
+ *pkt_header= &p->pcap_header;
+
+ if (p->sf.rfile != NULL) {
+ int status;
+
+ /* We are on an offline capture */
+ status = pcap_offline_read(p, 1, pcap_fakecallback,
+ (u_char *)&s);
+
+ /*
+ * Return codes for pcap_offline_read() are:
+ * - 0: EOF
+ * - -1: error
+ * - >1: OK
+ * The first one ('0') conflicts with the return code of
+ * 0 from pcap_read() meaning "no packets arrived before
+ * the timeout expired", so we map it to -2 so you can
+ * distinguish between an EOF from a savefile and a
+ * "no packets arrived before the timeout expired, try
+ * again" from a live capture.
+ */
+ if (status == 0)
+ return (-2);
+ else
+ return (status);
+ }
+
+ /*
+ * Return codes for pcap_read() are:
+ * - 0: timeout
+ * - -1: error
+ * - -2: loop was broken out of with pcap_breakloop()
+ * - >1: OK
+ * The first one ('0') conflicts with the return code of 0 from
+ * pcap_offline_read() meaning "end of file".
+ */
+ return (pcap_read(p, 1, pcap_fakecallback, (u_char *)&s));
+}
+
/*
* Force the loop in "pcap_read()" or "pcap_read_offline()" to terminate.
*/
@@ -271,6 +335,12 @@ pcap_perror(pcap_t *p, char *prefix)
fprintf(stderr, "%s: %s\n", prefix, p->errbuf);
}
+int
+pcap_get_selectable_fd(pcap_t *p)
+{
+ return (p->fd);
+}
+
char *
pcap_geterr(pcap_t *p)
{