]> The Tcpdump Group git mirrors - libpcap/blobdiff - pcap-bpf.c
From Pawel Pokrywka: add support for requesting that only received
[libpcap] / pcap-bpf.c
index 491d4ed2c2e250f7b961669f8391f34ec1d1565a..42318a1dc481572fb4ef207df9e69903fe6f2c83 100644 (file)
@@ -20,7 +20,7 @@
  */
 #ifndef lint
 static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/libpcap/pcap-bpf.c,v 1.88 2005-04-21 02:41:12 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/libpcap/pcap-bpf.c,v 1.89 2005-05-03 18:53:58 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -105,6 +105,7 @@ static int odmlockid = 0;
 #include "gencode.h"   /* for "no_optimize" */
 
 static int pcap_setfilter_bpf(pcap_t *p, struct bpf_program *fp);
+static int pcap_setdirection_bpf(pcap_t *, direction_t);
 static int pcap_set_datalink_bpf(pcap_t *p, int dlt);
 
 static int
@@ -1019,6 +1020,7 @@ pcap_open_live(const char *device, int snaplen, int promisc, int to_ms,
        p->read_op = pcap_read_bpf;
        p->inject_op = pcap_inject_bpf;
        p->setfilter_op = pcap_setfilter_bpf;
+       p->setdirection_op = pcap_setdirection_bpf;
        p->set_datalink_op = pcap_set_datalink_bpf;
        p->getnonblock_op = pcap_getnonblock_fd;
        p->setnonblock_op = pcap_setnonblock_fd;
@@ -1088,6 +1090,42 @@ pcap_setfilter_bpf(pcap_t *p, struct bpf_program *fp)
        return (0);
 }
 
+/*
+ * Set direction flag: Which packets do we accept on a forwarding
+ * single device? IN, OUT or both?
+ */
+static int
+pcap_setdirection_bpf(pcap_t *p, direction_t d)
+{
+#ifdef BIOCSSEESENT
+       u_int seesent;
+#endif
+
+       /*
+        * We don't support D_OUT.
+        */
+       if (d == D_OUT) {
+               snprintf(p->errbuf, sizeof(p->errbuf),
+                   "Setting direction to D_OUT is not supported on BPF");
+               return -1;
+       }
+#ifdef BIOCSSEESENT
+       seesent = (d == D_INOUT);
+       if (ioctl(p->fd, BIOCSSEESENT, &seesent) == -1) {
+               (void) snprintf(p->errbuf, sizeof(p->errbuf),
+                   "Cannot set direction to %s: %s",
+                       (d == D_INOUT) ? "D_INOUT" : "D_IN",
+                       strerror(errno));
+               return (-1);
+       }
+       return (0);
+#else
+       (void) snprintf(p->errbuf, sizeof(p->errbuf),
+           "This system doesn't support BIOCSSEESENT, so the direction can't be set");
+       return (-1);
+#endif
+}
+
 static int
 pcap_set_datalink_bpf(pcap_t *p, int dlt)
 {