summaryrefslogtreecommitdiffstats
path: root/contrib/libpcap/pcap.c
diff options
context:
space:
mode:
authorfenner <fenner@FreeBSD.org>2002-06-21 01:36:27 +0000
committerfenner <fenner@FreeBSD.org>2002-06-21 01:36:27 +0000
commit1e8ea467791f99f6068888787c27fd8b6b923d2c (patch)
tree4bf19d614b784f03cdea171c65cf7b2e9f63715c /contrib/libpcap/pcap.c
parenta6bce8883c0f9dd7fee0eb03667f57b40b1d9dab (diff)
downloadFreeBSD-src-1e8ea467791f99f6068888787c27fd8b6b923d2c.zip
FreeBSD-src-1e8ea467791f99f6068888787c27fd8b6b923d2c.tar.gz
Import libpcap 0.7.1, from
http://www.tcpdump.org/release/libpcap-0.7.1.tar.gz
Diffstat (limited to 'contrib/libpcap/pcap.c')
-rw-r--r--contrib/libpcap/pcap.c63
1 files changed, 62 insertions, 1 deletions
diff --git a/contrib/libpcap/pcap.c b/contrib/libpcap/pcap.c
index 9f32721..6b82453 100644
--- a/contrib/libpcap/pcap.c
+++ b/contrib/libpcap/pcap.c
@@ -33,7 +33,7 @@
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/libpcap/pcap.c,v 1.36 2000/12/16 10:43:31 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/pcap.c,v 1.38 2001/12/29 21:55:32 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
@@ -46,6 +46,8 @@ static const char rcsid[] =
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
#ifdef HAVE_OS_PROTO_H
#include "os-proto.h"
@@ -169,6 +171,65 @@ pcap_geterr(pcap_t *p)
}
/*
+ * NOTE: in the future, these may need to call platform-dependent routines,
+ * e.g. on platforms with memory-mapped packet-capture mechanisms where
+ * "pcap_read()" uses "select()" or "poll()" to wait for packets to arrive.
+ */
+int
+pcap_getnonblock(pcap_t *p, char *errbuf)
+{
+ int fdflags;
+
+ if (p->sf.rfile != NULL) {
+ /*
+ * This is a savefile, not a live capture file, so
+ * never say it's in non-blocking mode.
+ */
+ return (0);
+ }
+ fdflags = fcntl(p->fd, F_GETFL, 0);
+ if (fdflags == -1) {
+ snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "F_GETFL: %s",
+ pcap_strerror(errno));
+ return (-1);
+ }
+ if (fdflags & O_NONBLOCK)
+ return (1);
+ else
+ return (0);
+}
+
+int
+pcap_setnonblock(pcap_t *p, int nonblock, char *errbuf)
+{
+ int fdflags;
+
+ if (p->sf.rfile != NULL) {
+ /*
+ * This is a savefile, not a live capture file, so
+ * ignore requests to put it in non-blocking mode.
+ */
+ return (0);
+ }
+ fdflags = fcntl(p->fd, F_GETFL, 0);
+ if (fdflags == -1) {
+ snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "F_GETFL: %s",
+ pcap_strerror(errno));
+ return (-1);
+ }
+ if (nonblock)
+ fdflags |= O_NONBLOCK;
+ else
+ fdflags &= ~O_NONBLOCK;
+ if (fcntl(p->fd, F_SETFL, fdflags) == -1) {
+ snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "F_SETFL: %s",
+ pcap_strerror(errno));
+ return (-1);
+ }
+ return (0);
+}
+
+/*
* Not all systems have strerror().
*/
char *
OpenPOWER on IntegriCloud