Get the version number of the libpcap/WinPcap with which we're running
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Fri, 10 Oct 2003 06:05:48 +0000 (06:05 +0000)
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Fri, 10 Oct 2003 06:05:48 +0000 (06:05 +0000)
with "pcap_lib_version()", if available.

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@8656 f5534014-38df-0310-8fa8-9805f1628bb7

acinclude.m4
capture-wpcap.c
pcap-util-unix.c
pcap-util.h
util.c

index 5456d39bfc0595b38061ff3c7ff2d6b4d99befea..395f00e7cc85a137f33565c4ee71baa6dd260171 100644 (file)
@@ -2,7 +2,7 @@ dnl Macros that test for specific features.
 dnl This file is part of the Autoconf packaging for Ethereal.
 dnl Copyright (C) 1998-2000 by Gerald Combs.
 dnl
-dnl $Id: acinclude.m4,v 1.57 2003/10/10 03:00:09 guy Exp $
+dnl $Id: acinclude.m4,v 1.58 2003/10/10 06:05:48 guy Exp $
 dnl
 dnl This program is free software; you can redistribute it and/or modify
 dnl it under the terms of the GNU General Public License as published by
@@ -352,7 +352,7 @@ and did you also install that package?]]))
        else
                AC_MSG_RESULT(no)
        fi
-       AC_CHECK_FUNCS(pcap_findalldevs)
+       AC_CHECK_FUNCS(pcap_findalldevs pcap_lib_version)
        LIBS="$ac_save_LIBS"
 ])
 
index 88f6cbfd1512e0979e1858d49dc8c6591ff43990..36f232f27709ac6e9d8729516bf195bd1ec22c00 100644 (file)
@@ -3,7 +3,7 @@
  * time, so that we only need one Ethereal binary and one Tethereal binary
  * for Windows, regardless of whether WinPcap is installed or not.
  *
- * $Id: capture-wpcap.c,v 1.4 2003/10/10 03:00:09 guy Exp $
+ * $Id: capture-wpcap.c,v 1.5 2003/10/10 06:05:48 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -59,6 +59,8 @@ static int     (*p_pcap_lookupnet) (char *, bpf_u_int32 *, bpf_u_int32 *,
                        char *);
 static pcap_t* (*p_pcap_open_live) (char *, int, int, int, char *);
 static int     (*p_pcap_loop) (pcap_t *, int, pcap_handler, guchar *);
+static int     (*p_pcap_findalldevs) (pcap_if_t **, char *);
+static const char *(*p_pcap_lib_version) (void);
 
 typedef struct {
        const char      *name;
@@ -87,6 +89,7 @@ load_wpcap(void)
                SYM(pcap_open_live, FALSE),
                SYM(pcap_loop, FALSE),
                SYM(pcap_findalldevs, TRUE),
+               SYM(pcap_lib_version, TRUE),
                { NULL, NULL, FALSE }
        };
 
@@ -372,6 +375,38 @@ get_interface_list(int *err, char *err_str)
        return il;
 }
 
+/*
+ * Append the version of WinPcap with which we were compiled to a GString.
+ */
+void
+get_compiled_pcap_version(GString *str)
+{
+       g_string_append(str, "with WinPcap (version unknown)");
+}
+
+/*
+ * Append the version of WinPcap with which we we're running to a GString.
+ */
+void
+get_runtime_pcap_version(GString *str)
+{
+       /*
+        * On Windows, we might have been compiled with WinPcap but
+        * might not have it loaded; indicate whether we have it or
+        * not and, if we have it and we have "pcap_lib_version()",
+        * what version we have.
+        */
+       if (has_wpcap) {
+               g_string_sprintfa(str, "with ");
+               if (p_pcap_lib_version != NULL)
+                       g_string_sprintfa(str, p_pcap_lib_version());
+               else
+                       g_string_append(str, "WinPcap (version unknown)");
+       } else
+               g_string_append(str, "without WinPcap");
+       g_string_append(str, " ");
+}
+
 #else /* HAVE_LIBPCAP */
 
 void
@@ -380,4 +415,22 @@ load_wpcap(void)
        return;
 }
 
+/*
+ * Append an indication that we were not compiled with WinPcap
+ * to a GString.
+ */
+void
+get_compiled_pcap_version(GString *str)
+{
+       g_string_append(str, "without WinPcap");
+}
+
+/*
+ * Don't append anything, as we weren't even compiled to use WinPcap.
+ */
+void
+get_runtime_pcap_version(GString *str _U_)
+{
+}
+
 #endif /* HAVE_LIBPCAP */
index 6e3e8676a9d18562dbd8c22cdf0c052ce58a9f84..29015769b68cfa5be05df1568c932855ee8257f3 100644 (file)
@@ -1,7 +1,7 @@
 /* pcap-util-unix.c
  * UN*X-specific utility routines for packet capture
  *
- * $Id: pcap-util-unix.c,v 1.1 2003/10/10 03:00:10 guy Exp $
+ * $Id: pcap-util-unix.c,v 1.2 2003/10/10 06:05:48 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
 # include "config.h"
 #endif
 
-#ifdef HAVE_LIBPCAP
-
 #include <glib.h>
 
+#ifdef HAVE_LIBPCAP
+
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
@@ -270,4 +270,54 @@ search_for_if_cb(gpointer data, gpointer user_data)
 }
 #endif /* HAVE_PCAP_FINDALLDEVS */
 
+/*
+ * Append the version of libpcap with which we were compiled to a GString.
+ */
+void
+get_compiled_pcap_version(GString *str)
+{
+#ifdef HAVE_PCAP_VERSION
+       extern char pcap_version[];
+
+       g_string_sprintfa(str, "with libpcap %s", pcap_version);
+#else
+       g_string_append(str, "with libpcap (version unknown)");
+#endif
+}
+
+/*
+ * Append the version of libpcap with which we we're running to a GString.
+ */
+void
+get_runtime_pcap_version(GString *str)
+{
+       g_string_sprintfa(str, "with ");
+#ifdef HAVE_PCAP_LIB_VERSION
+       g_string_sprintfa(str, pcap_lib_version());
+#else
+       g_string_append(str, "libpcap (version unknown)");
+#endif
+       g_string_append(str, " ");
+}
+
+#else /* HAVE_LIBPCAP */
+
+/*
+ * Append an indication that we were not compiled with libpcap
+ * to a GString.
+ */
+void
+get_compiled_pcap_version(GString *str)
+{
+       g_string_append(str, "without libpcap");
+}
+
+/*
+ * Don't append anything, as we weren't even compiled to use WinPcap.
+ */
+void
+get_runtime_pcap_version(GString *str _U_)
+{
+}
+
 #endif /* HAVE_LIBPCAP */
index fe9c71bbd3c00b172b649c38fc513497b60ae3ec..d110f3c0fcb788dcf3d6a31a5dfc69b025bae0cb 100644 (file)
@@ -1,7 +1,7 @@
 /* pcap-util.h
  * Utility definitions for packet capture
  *
- * $Id: pcap-util.h,v 1.4 2003/09/10 05:35:24 guy Exp $
+ * $Id: pcap-util.h,v 1.5 2003/10/10 06:05:48 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -58,4 +58,19 @@ void free_interface_list(GList *if_list);
 
 #endif /* HAVE_LIBPCAP */
 
+/*
+ * Append to a GString an indication of the version of libpcap/WinPcap
+ * with which we were compiled, if we were, or an indication that we
+ * weren't compiled with libpcap/WinPcap, if we weren't.
+ */
+extern void get_compiled_pcap_version(GString *str);
+
+/*
+ * Append to a GString an indication of the version of libpcap/WinPcap
+ * with which we're running, or an indication that we're not running
+ * with libpcap/WinPcap, if we were compiled with libpcap/WinPcap,
+ * or nothing, if we weren't compiled with libpcap/WinPcap.
+ */
+extern void get_runtime_pcap_version(GString *str);
+
 #endif /* __PCAP_UTIL_H__ */
diff --git a/util.c b/util.c
index b5789fe07a4a4f042349403df5c784bcfe644c74..fa731361b099f431944b8f2afa34aa46ce9b5415 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1,7 +1,7 @@
 /* util.c
  * Utility routines
  *
- * $Id: util.c,v 1.68 2003/08/18 18:41:24 guy Exp $
+ * $Id: util.c,v 1.69 2003/10/10 06:05:48 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -62,9 +62,6 @@ typedef int mode_t;   /* for win32 */
 
 #ifdef HAVE_LIBPCAP
 #include <pcap.h>
-#ifdef WIN32
-#include "capture-wpcap.h"
-#endif /* WIN32 */
 #endif /* HAVE_LIBPCAP */
 
 #ifdef HAVE_SOME_SNMP
@@ -84,6 +81,7 @@ typedef int mode_t;   /* for win32 */
 #endif
 
 #include "util.h"
+#include "pcap-util.h"
 
 /*
  * See whether the last line in the string goes past column 80; if so,
@@ -112,11 +110,6 @@ do_word_wrap(GString *str, gint point)
 void
 get_compiled_version_info(GString *str)
 {
-#ifdef HAVE_LIBPCAP
-#ifdef HAVE_PCAP_VERSION
-       extern char pcap_version[];
-#endif /* HAVE_PCAP_VERSION */
-#endif /* HAVE_LIBPCAP */
        gint break_point;
 
        g_string_append(str, "with ");
@@ -128,29 +121,11 @@ get_compiled_version_info(GString *str)
            "GLib (version unknown),");
 #endif
 
-#ifdef HAVE_LIBPCAP
        g_string_append(str, " ");
        break_point = str->len - 1;
-#ifdef WIN32
-       g_string_append(str, "with WinPcap (version unknown)");
-#else /* WIN32 */
-#ifdef HAVE_PCAP_VERSION
-       g_string_sprintfa(str, "with libpcap %s,", pcap_version);
-#else /* HAVE_PCAP_VERSION */
-       g_string_append(str, "with libpcap (version unknown)");
-#endif /* HAVE_PCAP_VERSION */
-       do_word_wrap(str, break_point);
-#endif /* WIN32 */
-#else /* HAVE_LIBPCAP */
-       g_string_append(str, " ");
-       break_point = str->len - 1;
-#ifdef WIN32
-       g_string_append(str, "without WinPcap,");
-#else /* WIN32 */
-       g_string_append(str, "without libpcap,");
-#endif /* WIN32 */
+       get_compiled_pcap_version(str);
+       g_string_append(str, ",");
        do_word_wrap(str, break_point);
-#endif /* HAVE_LIBPCAP */
 
        g_string_append(str, " ");
        break_point = str->len - 1;
@@ -212,23 +187,7 @@ get_runtime_version_info(GString *str)
        struct utsname name;
 #endif
 
-#ifdef HAVE_LIBPCAP
-#ifdef WIN32
-       /*
-        * On Windows, we might have been compiled with WinPcap but
-        * might not have it loaded; indicate whether we have it or
-        * not.
-        *
-        * XXX - when versions of libcap and WinPcap with
-        * "pcap_lib_version()" are released, we should use it
-        * here if available.
-        */
-       if (has_wpcap)
-               g_string_sprintfa(str, "with WinPcap ");
-       else
-               g_string_append(str, "without WinPcap ");
-#endif /* WIN32 */
-#endif /* HAVE_LIBPCAP */
+       get_runtime_pcap_version(str);
 
        g_string_append(str, "on ");
 #if defined(WIN32)