Now that WinPcap is a DLL, I can load it at run-time rather than load-time.

That means that I no longer need to distribute capture and non-capture
versions of Ethereal for Win32; one version (compiled with WinPcap headers)
can run on systems with or without WinPcap.

For systems that don't have WinPcap, instead of disabling the Capture
menu, Capture|Start brings up a dialogue informing the user that wpcap.dll
was not loadable, and gives a URL to the WinPcap home page.

svn path=/trunk/; revision=3249
This commit is contained in:
Gilbert Ramirez 2001-04-03 05:26:27 +00:00
parent e453b3e5de
commit a817e97015
7 changed files with 294 additions and 15 deletions

View File

@ -1,7 +1,7 @@
# Makefile.am
# Automake file for Ethereal
#
# $Id: Makefile.am,v 1.299 2001/04/01 06:11:24 hagbard Exp $
# $Id: Makefile.am,v 1.300 2001/04/03 05:26:25 gram Exp $
#
# Ethereal - Network traffic analyzer
# By Gerald Combs <gerald@zing.org>
@ -585,6 +585,8 @@ DISTCLEANFILES = \
EXTRA_DIST = \
aclocal-flags \
capture-wpcap.c \
capture-wpcap.h \
config.h.win32 \
config.nmake \
debian/README.debian \

View File

@ -1,7 +1,7 @@
## Makefile for building ethereal.exe with Microsoft C and nmake
## Use: $(MAKE) /$(MAKEFLAGS) -f makefile.nmake
#
# $Id: Makefile.nmake,v 1.91 2001/03/31 10:13:10 guy Exp $
# $Id: Makefile.nmake,v 1.92 2001/04/03 05:26:25 gram Exp $
include config.nmake
include <win32.mak>
@ -196,6 +196,7 @@ DISSECTOR_OBJECTS = $(DISSECTOR_SOURCES:.c=.obj)
ETHEREAL_COMMON_OBJECTS = \
asn1.obj \
capture-wpcap.obj \
column.obj \
follow.obj \
getopt.obj \
@ -212,11 +213,11 @@ ETHEREAL_COMMON_OBJECTS = \
ethereal_OBJECTS = \
$(DISSECTOR_OBJECTS) \
$(ETHEREAL_COMMON_OBJECTS) \
capture.obj \
file.obj \
filters.obj \
capture.obj \
file.obj \
filters.obj \
proto_hier_stats.obj \
summary.obj \
summary.obj
tethereal_OBJECTS = \
$(DISSECTOR_OBJECTS) \
@ -240,16 +241,15 @@ ethereal_LIBS= wiretap\wiretap-$(WTAP_VERSION).lib \
$(GTK_DIR)\gtk\gtk-$(GTK_VERSION).lib \
$(GTK_DIR)\gdk\gdk-$(GTK_VERSION).lib \
$(GLIB_DIR)\glib-$(GLIB_VERSION).lib \
$(GLIB_DIR)\gmodule\gmodule-$(GLIB_VERSION).lib \
$(PCAP_DIR)\lib\wpcap.lib
$(GLIB_DIR)\gmodule\gmodule-$(GLIB_VERSION).lib
# $(PCAP_DIR)\lib\wpcap.lib
tethereal_LIBS= wiretap\wiretap-$(WTAP_VERSION).lib \
epan\ethereal.lib \
epan\dfilter\dfilter.lib epan\ftypes\ftypes.lib \
wsock32.lib user32.lib \
$(GLIB_DIR)\glib-$(GLIB_VERSION).lib \
$(GLIB_DIR)\gmodule\gmodule-$(GLIB_VERSION).lib \
$(PCAP_DIR)\lib\wpcap.lib
$(GLIB_DIR)\gmodule\gmodule-$(GLIB_VERSION).lib
editcap_LIBS= wiretap\wiretap-$(WTAP_VERSION).lib \
wsock32.lib user32.lib \
@ -260,8 +260,7 @@ dftest_LIBS= epan\ethereal.lib \
epan\dfilter\dfilter.lib epan\ftypes\ftypes.lib \
wsock32.lib user32.lib \
$(GLIB_DIR)\glib-$(GLIB_VERSION).lib \
$(GLIB_DIR)\gmodule\gmodule-$(GLIB_VERSION).lib \
$(PCAP_DIR)\lib\wpcap.lib
$(GLIB_DIR)\gmodule\gmodule-$(GLIB_VERSION).lib
EXECUTABLES=ethereal.exe tethereal.exe editcap.exe

205
capture-wpcap.c Normal file
View File

@ -0,0 +1,205 @@
/* capture-wpcap.c
* Try to load WinPcap DLL at run-time.
*
* $Id: capture-wpcap.c,v 1.1 2001/04/03 05:26:26 gram Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
* Copyright 2001 Gerald Combs
*
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <glib.h>
#include <gmodule.h>
#ifdef HAVE_LIBPCAP
#include <pcap.h>
#endif
/* XXX - yes, I know, I should move cppmagic.h to a generic location. */
#include "tools/lemon/cppmagic.h"
gboolean has_wpcap = FALSE;
#ifdef HAVE_LIBPCAP
static char* (*p_pcap_lookupdev) (char *);
static void (*p_pcap_close) (pcap_t *);
static int (*p_pcap_stats) (pcap_t *, struct pcap_stat *);
static int (*p_pcap_dispatch) (pcap_t *, int, pcap_handler, u_char *);
static int (*p_pcap_snapshot) (pcap_t *);
static int (*p_pcap_datalink) (pcap_t *);
static int (*p_pcap_setfilter) (pcap_t *, struct bpf_program *);
static char* (*p_pcap_geterr) (pcap_t *);
static int (*p_pcap_compile) (pcap_t *, struct bpf_program *, char *, int,
bpf_u_int32);
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, u_char *);
typedef struct {
const char *name;
gpointer *ptr;
} symbol_table_t;
#define SYM(x) STRINGIFY(x) , (gpointer) &CONCAT(p_,x)
void
load_wpcap(void)
{
/* These are the symbols I need from Wpcap */
symbol_table_t symbols[] = {
SYM(pcap_lookupdev),
SYM(pcap_close),
SYM(pcap_stats),
SYM(pcap_dispatch),
SYM(pcap_snapshot),
SYM(pcap_datalink),
SYM(pcap_setfilter),
SYM(pcap_geterr),
SYM(pcap_compile),
SYM(pcap_lookupnet),
SYM(pcap_open_live),
SYM(pcap_loop),
NULL, NULL
};
GModule *wh; /* wpcap handle */
symbol_table_t *sym;
wh = g_module_open("wpcap", 0);
if (!wh) {
return;
}
sym = symbols;
while (sym && sym->name) {
if (!g_module_symbol(wh, sym->name, sym->ptr)) {
return;
}
sym++;
}
has_wpcap = TRUE;
}
char*
pcap_lookupdev (char *a)
{
g_assert(has_wpcap);
return p_pcap_lookupdev(a);
}
void
pcap_close(pcap_t *a)
{
g_assert(has_wpcap);
p_pcap_close(a);
}
int
pcap_stats(pcap_t *a, struct pcap_stat *b)
{
g_assert(has_wpcap);
return p_pcap_stats(a, b);
}
int
pcap_dispatch(pcap_t *a, int b, pcap_handler c, u_char *d)
{
g_assert(has_wpcap);
return p_pcap_dispatch(a, b, c, d);
}
int
pcap_snapshot(pcap_t *a)
{
g_assert(has_wpcap);
return p_pcap_snapshot(a);
}
int
pcap_datalink(pcap_t *a)
{
g_assert(has_wpcap);
return p_pcap_datalink(a);
}
int
pcap_setfilter(pcap_t *a, struct bpf_program *b)
{
g_assert(has_wpcap);
return p_pcap_setfilter(a, b);
}
char*
pcap_geterr(pcap_t *a)
{
g_assert(has_wpcap);
return p_pcap_geterr(a);
}
int
pcap_compile(pcap_t *a, struct bpf_program *b, char *c, int d,
bpf_u_int32 e)
{
g_assert(has_wpcap);
return p_pcap_compile(a, b, c, d, e);
}
int
pcap_lookupnet(char *a, bpf_u_int32 *b, bpf_u_int32 *c, char *d)
{
g_assert(has_wpcap);
return p_pcap_lookupnet(a, b, c, d);
}
pcap_t*
pcap_open_live(char *a, int b, int c, int d, char *e)
{
g_assert(has_wpcap);
return p_pcap_open_live(a, b, c, d, e);
}
int
pcap_loop(pcap_t *a, int b, pcap_handler c, u_char *d)
{
g_assert(has_wpcap);
return p_pcap_loop(a, b, c, d);
}
#else /* HAVE_LIBPCAP */
void
load_wpcap(void)
{
return;
}
#endif /* HAVE_LIBPCAP */

34
capture-wpcap.h Normal file
View File

@ -0,0 +1,34 @@
/* capture-wpcap.h
*
* $Id: capture-wpcap.h,v 1.1 2001/04/03 05:26:26 gram Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
* Copyright 2001 Gerald Combs
*
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef CAPTURE_WPCAP_H
#define CAPTURE_WPCAP_H
extern gboolean has_wpcap;
void
load_wpcap(void);
#endif

View File

@ -1,7 +1,7 @@
/* capture_dlg.c
* Routines for packet capture windows
*
* $Id: capture_dlg.c,v 1.37 2001/01/28 23:56:29 guy Exp $
* $Id: capture_dlg.c,v 1.38 2001/04/03 05:26:27 gram Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -58,6 +58,10 @@
#include "dlg_utils.h"
#include "util.h"
#ifdef _WIN32
#include "capture-wpcap.h"
#endif
/* Capture callback data keys */
#define E_CAP_IFACE_KEY "cap_iface"
#define E_CAP_FILT_KEY "cap_filter_te"
@ -130,6 +134,18 @@ capture_prep_cb(GtkWidget *w, gpointer d)
return;
}
#ifdef _WIN32
/* Is WPcap loaded? */
if (!has_wpcap) {
simple_dialog(ESD_TYPE_CRIT, NULL,
"Unable to load wpcap.dll: capturing not enabled.\n"
"See http://netgroup-serv.polito.it/winpcap/ for\n"
"more details.");
return;
}
#endif
if_list = get_interface_list(&err, err_str);
if (if_list == NULL && err == CANT_GET_INTERFACE_LIST) {
simple_dialog(ESD_TYPE_WARN, NULL, "Can't get list of interfaces: %s",

View File

@ -1,6 +1,6 @@
/* main.c
*
* $Id: main.c,v 1.187 2001/04/02 09:53:46 guy Exp $
* $Id: main.c,v 1.188 2001/04/03 05:26:27 gram Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -137,6 +137,11 @@
#include "strutil.h"
#include "register.h"
#ifdef WIN32
#include "capture-wpcap.h"
#endif
packet_info pi;
capture_file cfile;
GtkWidget *top_level, *packet_list, *tree_view, *byte_nb_ptr,
@ -1113,6 +1118,9 @@ main(int argc, char *argv[])
}
#ifdef WIN32
/* Load wpcap if possible */
load_wpcap();
/* Start windows sockets */
WSAStartup( MAKEWORD( 1, 1 ), &wsaData );
#endif

View File

@ -1,6 +1,6 @@
/* tethereal.c
*
* $Id: tethereal.c,v 1.73 2001/04/02 00:38:33 hagbard Exp $
* $Id: tethereal.c,v 1.74 2001/04/03 05:26:26 gram Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -95,6 +95,10 @@
#include "plugins.h"
#include "register.h"
#ifdef WIN32
#include "capture-wpcap.h"
#endif
static guint32 firstsec, firstusec;
static guint32 prevsec, prevusec;
static GString *comp_info_str;
@ -230,6 +234,9 @@ main(int argc, char *argv[])
fprintf(stderr, "Can't open your preferences file \"%s\": %s.\n", pf_path,
strerror(pf_open_errno));
}
/* Load Wpcap, if possible */
load_wpcap();
/* Initialize the capture file struct */
cfile.plist = NULL;
@ -540,6 +547,14 @@ main(int argc, char *argv[])
/* No capture file specified, so we're supposed to do a live capture;
do we have support for live captures? */
#ifdef HAVE_LIBPCAP
#ifdef _WIN32
if (!has_wpcap) {
fprintf(stderr, "tethereal: Could not load wpcap.dll.\n");
exit(2);
}
#endif
/* Yes; did the user specify an interface to use? */
if (cfile.iface == NULL) {
/* No - pick the first one from the list of interfaces. */