diff options
-rw-r--r-- | acinclude.m4 | 4 | ||||
-rw-r--r-- | capture-wpcap.c | 55 | ||||
-rw-r--r-- | pcap-util-unix.c | 56 | ||||
-rw-r--r-- | pcap-util.h | 17 | ||||
-rw-r--r-- | util.c | 51 |
5 files changed, 130 insertions, 53 deletions
diff --git a/acinclude.m4 b/acinclude.m4 index 5456d39bfc..395f00e7cc 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -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" ]) diff --git a/capture-wpcap.c b/capture-wpcap.c index 88f6cbfd15..36f232f277 100644 --- a/capture-wpcap.c +++ b/capture-wpcap.c @@ -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 */ diff --git a/pcap-util-unix.c b/pcap-util-unix.c index 6e3e8676a9..29015769b6 100644 --- a/pcap-util-unix.c +++ b/pcap-util-unix.c @@ -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> @@ -26,10 +26,10 @@ # 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 */ diff --git a/pcap-util.h b/pcap-util.h index fe9c71bbd3..d110f3c0fc 100644 --- a/pcap-util.h +++ b/pcap-util.h @@ -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__ */ @@ -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) |