]> The Tcpdump Group git mirrors - libpcap/commitdiff
Just use install_bpf_program as the setfilter operation.
authorGuy Harris <[email protected]>
Sun, 23 Dec 2018 19:19:38 +0000 (11:19 -0800)
committerGuy Harris <[email protected]>
Sun, 23 Dec 2018 19:19:38 +0000 (11:19 -0800)
That's how to do it for modules that do filtering in the module itself;
there's no need for a wrapper.

pcap-septel.c
pcap-snf.c
pcap-tc.c

index beb1cb3825739f34b50711d863471ba0dfc92ad7..8ea26d7f9340826c3f8041ae36ac8bead5e0ac12 100644 (file)
@@ -41,7 +41,6 @@
 
 #include "pcap-septel.h"
 
-static int septel_setfilter(pcap_t *p, struct bpf_program *fp);
 static int septel_stats(pcap_t *p, struct pcap_stat *ps);
 static int septel_getnonblock(pcap_t *p);
 static int septel_setnonblock(pcap_t *p, int nonblock);
@@ -218,7 +217,7 @@ static pcap_t *septel_activate(pcap_t* handle) {
 
   handle->read_op = septel_read;
   handle->inject_op = septel_inject;
-  handle->setfilter_op = septel_setfilter;
+  handle->setfilter_op = install_bpf_program;
   handle->set_datalink_op = NULL; /* can't change data link type */
   handle->getnonblock_op = septel_getnonblock;
   handle->setnonblock_op = septel_setnonblock;
@@ -284,28 +283,6 @@ septel_findalldevs(pcap_if_list_t *devlistp, char *errbuf)
 }
 
 
-/*
- * Installs the given bpf filter program in the given pcap structure.  There is
- * no attempt to store the filter in kernel memory as that is not supported
- * with Septel cards.
- */
-static int septel_setfilter(pcap_t *p, struct bpf_program *fp) {
-  if (!p)
-    return -1;
-  if (!fp) {
-    strncpy(p->errbuf, "setfilter: No filter specified",
-           sizeof(p->errbuf));
-    return -1;
-  }
-
-  /* Make our private copy of the filter */
-
-  if (install_bpf_program(p, fp) < 0)
-    return -1;
-
-  return (0);
-}
-
 /*
  * We don't support non-blocking mode.  I'm not sure what we'd
  * do to support it and, given that we don't support select()/
index c030cd097d24e1f006a94441a307ff3832902831..5f2e950dd37c06ef2a49af4cd2766b20ef80c3dc 100644 (file)
@@ -193,25 +193,6 @@ snf_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
        return (n);
 }
 
-static int
-snf_setfilter(pcap_t *p, struct bpf_program *fp)
-{
-       if (!p)
-               return -1;
-       if (!fp) {
-               strncpy(p->errbuf, "setfilter: No filter specified",
-                       sizeof(p->errbuf));
-               return -1;
-       }
-
-       /* Make our private copy of the filter */
-
-       if (install_bpf_program(p, fp) < 0)
-               return -1;
-
-       return (0);
-}
-
 static int
 snf_inject(pcap_t *p, const void *buf _U_, int size _U_)
 {
@@ -327,7 +308,7 @@ snf_activate(pcap_t* p)
        p->linktype = DLT_EN10MB;
        p->read_op = snf_read;
        p->inject_op = snf_inject;
-       p->setfilter_op = snf_setfilter;
+       p->setfilter_op = install_bpf_program;
        p->setdirection_op = NULL; /* Not implemented.*/
        p->set_datalink_op = snf_set_datalink;
        p->getnonblock_op = snf_getnonblock;
index b4a5593feeb77b2019083098893bceb3cc65d7c2..759f7a297bbb30639110f13b697782622fc94538 100644 (file)
--- a/pcap-tc.c
+++ b/pcap-tc.c
@@ -126,7 +126,6 @@ static void TcCleanup(pcap_t *p);
 static int TcInject(pcap_t *p, const void *buf, int size);
 static int TcRead(pcap_t *p, int cnt, pcap_handler callback, u_char *user);
 static int TcStats(pcap_t *p, struct pcap_stat *ps);
-static int TcSetFilter(pcap_t *p, struct bpf_program *fp);
 #ifdef _WIN32
 static struct pcap_stat *TcStatsEx(pcap_t *p, int *pcap_stat_size);
 static int TcSetBuff(pcap_t *p, int dim);
@@ -663,7 +662,7 @@ TcActivate(pcap_t *p)
        }
 
        p->read_op = TcRead;
-       p->setfilter_op = TcSetFilter;
+       p->setfilter_op = install_bpf_program;
        p->setdirection_op = NULL;      /* Not implemented. */
        p->set_datalink_op = TcSetDatalink;
        p->getnonblock_op = TcGetNonBlock;
@@ -1100,27 +1099,6 @@ TcStats(pcap_t *p, struct pcap_stat *ps)
 }
 
 
-/*
- * We filter at user level, since the kernel driver does't process the packets
- */
-static int
-TcSetFilter(pcap_t *p, struct bpf_program *fp)
-{
-       if(!fp)
-       {
-               strncpy(p->errbuf, "setfilter: No filter specified", sizeof(p->errbuf));
-               return -1;
-       }
-
-       /* Install a user level filter */
-       if (install_bpf_program(p, fp) < 0)
-       {
-               return -1;
-       }
-
-       return 0;
-}
-
 #ifdef _WIN32
 static struct pcap_stat *
 TcStatsEx(pcap_t *p, int *pcap_stat_size)