]> The Tcpdump Group git mirrors - libpcap/commitdiff
Add a "set_datalink" function pointer to the pcap_t structure, whichhandles
authorguy <guy>
Fri, 25 Jul 2003 05:07:01 +0000 (05:07 +0000)
committerguy <guy>
Fri, 25 Jul 2003 05:07:01 +0000 (05:07 +0000)
setting a filter for a pcap_t.  Have "pcap_set_datalink()" call it,
rather than explicitly calling "pcap_set_datalink_platform()".

13 files changed:
pcap-bpf.c
pcap-dag.c
pcap-dlpi.c
pcap-int.h
pcap-linux.c
pcap-nit.c
pcap-null.c
pcap-pf.c
pcap-snit.c
pcap-snoop.c
pcap-win32.c
pcap.c
savefile.c

index 8b4091c4ee0ccb906290d122431fdc94a25a2287..eeda8500cd8d058c1765854f3a740ef24781e22c 100644 (file)
@@ -20,7 +20,7 @@
  */
 #ifndef lint
 static const char rcsid[] =
  */
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/libpcap/pcap-bpf.c,v 1.64 2003-07-25 04:42:02 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/libpcap/pcap-bpf.c,v 1.65 2003-07-25 05:07:01 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -104,6 +104,7 @@ static int odmlockid = 0;
 #include "gencode.h"   /* for "no_optimize" */
 
 static int pcap_setfilter_bpf(pcap_t *p, struct bpf_program *fp);
 #include "gencode.h"   /* for "no_optimize" */
 
 static int pcap_setfilter_bpf(pcap_t *p, struct bpf_program *fp);
+static int pcap_set_datalink_bpf(pcap_t *p, int dlt);
 
 static int
 pcap_stats_bpf(pcap_t *p, struct pcap_stat *ps)
 
 static int
 pcap_stats_bpf(pcap_t *p, struct pcap_stat *ps)
@@ -733,6 +734,7 @@ pcap_open_live(const char *device, int snaplen, int promisc, int to_ms,
 #endif
 
        p->setfilter_op = pcap_setfilter_bpf;
 #endif
 
        p->setfilter_op = pcap_setfilter_bpf;
+       p->set_datalink_op = pcap_set_datalink_bpf;
        p->stats_op = pcap_stats_bpf;
        p->close_op = pcap_close_bpf;
 
        p->stats_op = pcap_stats_bpf;
        p->close_op = pcap_close_bpf;
 
@@ -777,15 +779,9 @@ pcap_setfilter_bpf(pcap_t *p, struct bpf_program *fp)
        return (0);
 }
 
        return (0);
 }
 
-int
-pcap_set_datalink_platform(pcap_t *p, int dlt)
+static int
+pcap_set_datalink_bpf(pcap_t *p, int dlt)
 {
 {
-#ifdef HAVE_DAG_API
-       if (p->md.is_dag) {
-               return dag_set_datalink_platform(p, dlt);
-       }
-#endif /* HAVE_DAG_API */
-
 #ifdef BIOCSDLT
        if (ioctl(p->fd, BIOCSDLT, &dlt) == -1) {
                (void) snprintf(p->errbuf, sizeof(p->errbuf),
 #ifdef BIOCSDLT
        if (ioctl(p->fd, BIOCSDLT, &dlt) == -1) {
                (void) snprintf(p->errbuf, sizeof(p->errbuf),
index 1d0243b9e3ed6afc662a3182875539f4c86c1c1e..d4536597a13079286c0f1b6ae95bfc940ddab071 100644 (file)
@@ -19,7 +19,7 @@
 
 #ifndef lint
 static const char rcsid[] =
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/libpcap/pcap-dag.c,v 1.4 2003-07-25 04:42:02 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/libpcap/pcap-dag.c,v 1.5 2003-07-25 05:07:01 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -62,11 +62,11 @@ static int atexit_handler_installed = 0;
 #define dag_read pcap_read
 #define dag_open_live pcap_open_live
 #define dag_platform_finddevs pcap_platform_finddevs
 #define dag_read pcap_read
 #define dag_open_live pcap_open_live
 #define dag_platform_finddevs pcap_platform_finddevs
-#define dag_set_datalink_platform pcap_set_datalink_platform
 #endif /* DAG_ONLY */
 
 static int dag_setfilter(pcap_t *p, struct bpf_program *fp);
 static int dag_stats(pcap_t *p, struct pcap_stat *ps);
 #endif /* DAG_ONLY */
 
 static int dag_setfilter(pcap_t *p, struct bpf_program *fp);
 static int dag_stats(pcap_t *p, struct pcap_stat *ps);
+static int dag_set_datalink(pcap_t *p, int dlt);
 
 static void delete_pcap_dag(pcap_t *p) {
   pcap_dag_node_t *curr = NULL, *prev = NULL;
 
 static void delete_pcap_dag(pcap_t *p) {
   pcap_dag_node_t *curr = NULL, *prev = NULL;
@@ -387,6 +387,7 @@ pcap_t *dag_open_live(const char *device, int snaplen, int promisc, int to_ms, c
   }
 
   handle->setfilter_op = dag_setfilter;
   }
 
   handle->setfilter_op = dag_setfilter;
+  handle->set_datalink_op = dag_set_datalink;
   handle->stats_op = dag_stats;
   handle->close_op = dag_platform_close;
 
   handle->stats_op = dag_stats;
   handle->close_op = dag_platform_close;
 
@@ -529,8 +530,8 @@ static int dag_setfilter(pcap_t *p, struct bpf_program *fp) {
   return (0);
 }
 
   return (0);
 }
 
-int
-dag_set_datalink_platform(pcap_t *p, int dlt)
+static int
+dag_set_datalink(pcap_t *p, int dlt)
 {
        return (0);
 }
 {
        return (0);
 }
index 1d3ae022f71082bc2d81004acdf9eaaccc0f58b4..0b6f06f9c76c117ea7a2e9a3795bfe8457b8a2ff 100644 (file)
@@ -38,7 +38,7 @@
 
 #ifndef lint
 static const char rcsid[] =
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/libpcap/pcap-dlpi.c,v 1.88 2003-07-25 04:42:02 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/libpcap/pcap-dlpi.c,v 1.89 2003-07-25 05:07:01 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -673,6 +673,7 @@ pcap_open_live(const char *device, int snaplen, int promisc, int to_ms,
        }
 
        p->setfilter_op = install_bpf_program;  /* no kernel filtering */
        }
 
        p->setfilter_op = install_bpf_program;  /* no kernel filtering */
+       p->set_datalink_op = NULL;      /* can't change data link type */
        p->stats_op = pcap_stats_dlpi;
        p->close_op = pcap_close_dlpi;
 
        p->stats_op = pcap_stats_dlpi;
        p->close_op = pcap_close_dlpi;
 
@@ -1477,9 +1478,3 @@ dlpi_kread(register int fd, register off_t addr,
        return (cc);
 }
 #endif
        return (cc);
 }
 #endif
-
-int
-pcap_set_datalink_platform(pcap_t *p, int dlt)
-{
-       return (0);
-}
index d346250247f65902aaf864eccaf5f3f3c18521b0..13191829b9c860fb856603bde9a9484ea9f34499 100644 (file)
@@ -30,7 +30,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * @(#) $Header: /tcpdump/master/libpcap/pcap-int.h,v 1.50 2003-07-25 04:42:03 guy Exp $ (LBL)
+ * @(#) $Header: /tcpdump/master/libpcap/pcap-int.h,v 1.51 2003-07-25 05:07:02 guy Exp $ (LBL)
  */
 
 #ifndef pcap_int_h
  */
 
 #ifndef pcap_int_h
@@ -119,6 +119,7 @@ struct pcap {
         * Methods.
         */
        int     (*setfilter_op)(pcap_t *, struct bpf_program *);
         * Methods.
         */
        int     (*setfilter_op)(pcap_t *, struct bpf_program *);
+       int     (*set_datalink_op)(pcap_t *, int);
        int     (*stats_op)(pcap_t *, struct pcap_stat *);
        void    (*close_op)(pcap_t *);
 
        int     (*stats_op)(pcap_t *, struct pcap_stat *);
        void    (*close_op)(pcap_t *);
 
index f838a92d33fd2159a2f9e2262f9f9091e3647d03..5a7321217f4f41196dfc05bd7089143604d330e2 100644 (file)
@@ -27,7 +27,7 @@
 
 #ifndef lint
 static const char rcsid[] =
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/libpcap/pcap-linux.c,v 1.93 2003-07-25 04:42:03 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/libpcap/pcap-linux.c,v 1.94 2003-07-25 05:07:02 guy Exp $ (LBL)";
 #endif
 
 /*
 #endif
 
 /*
@@ -397,6 +397,7 @@ pcap_open_live(const char *device, int snaplen, int promisc, int to_ms,
        }
 
        handle->setfilter_op = pcap_setfilter_linux;
        }
 
        handle->setfilter_op = pcap_setfilter_linux;
+       handle->set_datalink_op = NULL; /* can't change data link type */
        handle->stats_op = pcap_stats_linux;
        handle->close_op = pcap_close_linux;
 
        handle->stats_op = pcap_stats_linux;
        handle->close_op = pcap_close_linux;
 
@@ -1957,15 +1958,3 @@ reset_kernel_filter(pcap_t *handle)
                                   &dummy, sizeof(dummy));
 }
 #endif
                                   &dummy, sizeof(dummy));
 }
 #endif
-
-int
-pcap_set_datalink_platform(pcap_t *p, int dlt)
-{
-#ifdef HAVE_DAG_API
-       if (p->md.is_dag) {
-               return dag_set_datalink_platform(p, dlt);
-       }
-#endif /* HAVE_DAG_API */
-
-       return (0);
-}
index 883fc9f3c3f013a29049d01ccc4192acecd307a2..c0cd9ee91019d1179e8c1761574cb5f1b48e9a29 100644 (file)
@@ -20,7 +20,7 @@
  */
 #ifndef lint
 static const char rcsid[] =
  */
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/libpcap/pcap-nit.c,v 1.47 2003-07-25 04:42:03 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/libpcap/pcap-nit.c,v 1.48 2003-07-25 05:07:02 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -261,6 +261,7 @@ pcap_open_live(const char *device, int snaplen, int promisc, int to_ms,
        }
 
        p->setfilter_op = install_bpf_program;  /* no kernel filtering */
        }
 
        p->setfilter_op = install_bpf_program;  /* no kernel filtering */
+       p->set_datalink_op = NULL;      /* can't change data link type */
        p->stats_op = pcap_stats_nit;
        p->close_op = pcap_close_nit;
 
        p->stats_op = pcap_stats_nit;
        p->close_op = pcap_close_nit;
 
@@ -277,9 +278,3 @@ pcap_platform_finddevs(pcap_if_t **alldevsp, char *errbuf)
 {
        return (0);
 }
 {
        return (0);
 }
-
-int
-pcap_set_datalink_platform(pcap_t *p, int dlt)
-{
-       return (0);
-}
index 6f6788d96e3bf151278e4cbafd5956de10fc9ba7..013185a2c51c6b20da6c7791af2b36a1805bd177 100644 (file)
@@ -20,7 +20,7 @@
  */
 #ifndef lint
 static const char rcsid[] =
  */
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/libpcap/pcap-null.c,v 1.18 2003-07-25 04:42:03 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/libpcap/pcap-null.c,v 1.19 2003-07-25 05:07:02 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -59,9 +59,3 @@ pcap_platform_finddevs(pcap_if_t **alldevsp, char *errbuf)
 {
        return (0);
 }
 {
        return (0);
 }
-
-int
-pcap_set_datalink_platform(pcap_t *p, int dlt)
-{
-       return (0);
-}
index 9d6e26acc250027f41a47743b3b8011645753089..0a77426e9367a82b50e5cdb2dc1448c7b66f82a5 100644 (file)
--- a/pcap-pf.c
+++ b/pcap-pf.c
@@ -24,7 +24,7 @@
 
 #ifndef lint
 static const char rcsid[] =
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/libpcap/pcap-pf.c,v 1.76 2003-07-25 04:42:04 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/libpcap/pcap-pf.c,v 1.77 2003-07-25 05:07:03 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -416,6 +416,7 @@ your system may not be properly configured; see the packetfilter(4) man page\n",
        }
 
        p->setfilter_op = pcap_setfilter_pf;
        }
 
        p->setfilter_op = pcap_setfilter_pf;
+       p->set_datalink_op = NULL;      /* can't change data link type */
        p->stats_op = pcap_stats_pf;
        p->close_op = pcap_close_pf;
 
        p->stats_op = pcap_stats_pf;
        p->close_op = pcap_close_pf;
 
@@ -470,9 +471,3 @@ pcap_setfilter_pf(pcap_t *p, struct bpf_program *fp)
                fprintf(stderr, "tcpdump: Filtering in user process\n");
        return (0);
 }
                fprintf(stderr, "tcpdump: Filtering in user process\n");
        return (0);
 }
-
-int
-pcap_set_datalink_platform(pcap_t *p, int dlt)
-{
-       return (0);
-}
index c05ebbbe20d4c48d7626ce7f810d1303c49037c4..fa0dc8c88273a348b0f522d4b8304f6683326c26 100644 (file)
@@ -25,7 +25,7 @@
 
 #ifndef lint
 static const char rcsid[] =
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/libpcap/pcap-snit.c,v 1.63 2003-07-25 04:42:04 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/libpcap/pcap-snit.c,v 1.64 2003-07-25 05:07:03 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -319,6 +319,7 @@ pcap_open_live(const char *device, int snaplen, int promisc, int to_ms,
        }
 
        p->setfilter_op = install_bpf_program;  /* no kernel filtering */
        }
 
        p->setfilter_op = install_bpf_program;  /* no kernel filtering */
+       p->set_datalink_op = NULL;      /* can't change data link type */
        p->stats_op = pcap_stats_snit;
        p->close_op = pcap_close_snit;
 
        p->stats_op = pcap_stats_snit;
        p->close_op = pcap_close_snit;
 
@@ -335,9 +336,3 @@ pcap_platform_finddevs(pcap_if_t **alldevsp, char *errbuf)
 {
        return (0);
 }
 {
        return (0);
 }
-
-int
-pcap_set_datalink_platform(pcap_t *p, int dlt)
-{
-       return (0);
-}
index d2a8c4866d889dda06531083c8c670d974b78a06..f852a78201d1dca20770e2189777d3fb2a28f10e 100644 (file)
@@ -20,7 +20,7 @@
  */
 #ifndef lint
 static const char rcsid[] =
  */
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/libpcap/pcap-snoop.c,v 1.42 2003-07-25 04:42:04 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/libpcap/pcap-snoop.c,v 1.43 2003-07-25 05:07:03 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -295,6 +295,7 @@ pcap_open_live(const char *device, int snaplen, int promisc, int to_ms,
        }
 
        p->setfilter_op = install_bpf_program;  /* no kernel filtering */
        }
 
        p->setfilter_op = install_bpf_program;  /* no kernel filtering */
+       p->set_datalink_op = NULL;      /* can't change data link type */
        p->stats_op = pcap_stats_snoop;
        p->close_op = pcap_close_snoop;
 
        p->stats_op = pcap_stats_snoop;
        p->close_op = pcap_close_snoop;
 
@@ -310,9 +311,3 @@ pcap_platform_finddevs(pcap_if_t **alldevsp, char *errbuf)
 {
        return (0);
 }
 {
        return (0);
 }
-
-int
-pcap_set_datalink_platform(pcap_t *p, int dlt)
-{
-       return (0);
-}
index da20526544970ce4a45fd3f32057fa879b9cc34e..a2d29c7ae2932f10c529a3d1e4f01e2a503de760 100644 (file)
@@ -32,7 +32,7 @@
 
 #ifndef lint
 static const char rcsid[] =
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/libpcap/pcap-win32.c,v 1.11 2003-07-25 04:42:04 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/libpcap/pcap-win32.c,v 1.12 2003-07-25 05:07:03 guy Exp $ (LBL)";
 #endif
 
 #include <pcap-int.h>
 #endif
 
 #include <pcap-int.h>
@@ -257,6 +257,7 @@ pcap_open_live(const char *device, int snaplen, int promisc, int to_ms,
        PacketSetReadTimeout(p->adapter, to_ms);
 
        p->setfilter_op = pcap_setfilter_win32;
        PacketSetReadTimeout(p->adapter, to_ms);
 
        p->setfilter_op = pcap_setfilter_win32;
+       p->set_datalink_op = NULL;      /* can't change data link type */
        p->stats_op = pcap_stats_win32;
        p->close_op = pcap_close_win32;
 
        p->stats_op = pcap_stats_win32;
        p->close_op = pcap_close_win32;
 
@@ -359,9 +360,3 @@ pcap_setmintocopy(pcap_t *p, int size)
        }
        return 0;
 }
        }
        return 0;
 }
-
-int
-pcap_set_datalink_platform(pcap_t *p, int dlt)
-{
-       return (0);
-}
diff --git a/pcap.c b/pcap.c
index 51e3fe5fdf2f84ba1758939a4de880452abde520..e6fabebc06b4d4429c2c8c595e0f10053e4b9b26 100644 (file)
--- a/pcap.c
+++ b/pcap.c
@@ -33,7 +33,7 @@
 
 #ifndef lint
 static const char rcsid[] =
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/libpcap/pcap.c,v 1.59 2003-07-25 04:42:04 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/libpcap/pcap.c,v 1.60 2003-07-25 05:07:04 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -228,9 +228,10 @@ pcap_set_datalink(pcap_t *p, int dlt)
        int i;
        const char *dlt_name;
 
        int i;
        const char *dlt_name;
 
-       if (p->dlt_count == 0) {
+       if (p->dlt_count == 0 || p->set_datalink_op == NULL) {
                /*
                /*
-                * We couldn't fetch the list of DLTs, which means
+                * We couldn't fetch the list of DLTs, or we don't
+                * have a "set datalink" operation, which means
                 * this platform doesn't support changing the
                 * DLT for an interface.  Check whether the new
                 * DLT is the one this interface supports.
                 * this platform doesn't support changing the
                 * DLT for an interface.  Check whether the new
                 * DLT is the one this interface supports.
@@ -248,7 +249,7 @@ pcap_set_datalink(pcap_t *p, int dlt)
                        break;
        if (i >= p->dlt_count)
                goto unsupported;
                        break;
        if (i >= p->dlt_count)
                goto unsupported;
-       if (pcap_set_datalink_platform(p, dlt) == -1)
+       if (p->set_datalink_op(p, dlt) == -1)
                return (-1);
        p->linktype = dlt;
        return (0);
                return (-1);
        p->linktype = dlt;
        return (0);
index 53cc2157678800afc36e056e35613ef508fff8aa..51eb4cd11559ef309ebec9f3bff011b641e962bf 100644 (file)
@@ -30,7 +30,7 @@
 
 #ifndef lint
 static const char rcsid[] =
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/libpcap/savefile.c,v 1.84 2003-07-25 04:42:05 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/libpcap/savefile.c,v 1.85 2003-07-25 05:07:04 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -533,6 +533,7 @@ pcap_open_offline(const char *fname, char *errbuf)
 #endif
 
        p->setfilter_op = install_bpf_program;
 #endif
 
        p->setfilter_op = install_bpf_program;
+       p->set_datalink_op = NULL;      /* we don't support munging link-layer headers */
        p->stats_op = sf_stats;
        p->close_op = sf_close;
 
        p->stats_op = sf_stats;
        p->close_op = sf_close;