Skip to content

Commit

Permalink
Configure whether we have WinPcap based on whether WINPCAP_VERSION is
Browse files Browse the repository at this point in the history
set in the config.nmake file.

Configure whether we have pcap_findalldevs() based on whether
WINPCAP_VERSION is 2.3 (if so, we don't) or 3.0 or 3.1 (if so, we do).

WinPcap 3.0 has the new libpcap declarations of "pcap_lookupnet()" and
"pcap_open_live()" in which the first argument is a "const char *"
rather than a "char *"; declare the functions and pointers to them
appropriately based on the version of WinPcap.

If we don't have pcap_findalldevs(), don't declare a pointer to it, as
we don't have a declaration of pcap_if_t.

We also need to refer to "pcap_freealldevs()", so make a pointer for it.

"symbols[]" is a const array; make the pointer to elements in it a const
pointer.

Fix some typoes.

svn path=/trunk/; revision=8660
  • Loading branch information
guyharris committed Oct 10, 2003
1 parent e75b86f commit bd2ea47
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 9 deletions.
9 changes: 7 additions & 2 deletions Makefile.nmake
Original file line number Diff line number Diff line change
@@ -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.344 2003/10/06 19:25:20 guy Exp $
# $Id: Makefile.nmake,v 1.345 2003/10/10 09:48:54 guy Exp $

include config.nmake
include <win32.mak>
Expand Down Expand Up @@ -566,7 +566,12 @@ randpkt.exe : $(randpkt_OBJECTS) $(EXTRA_OBJECTS)
<<

config.h : config.h.win32 config.nmake
sed -e s/@VERSION@/$(VERSION)/ -e "s/@HAVE_GNU_ADNS@/$(ADNS_CONFIG)/" < config.h.win32 > $@
sed -e s/@VERSION@/$(VERSION)/ \
-e "s/@HAVE_GNU_ADNS@/$(ADNS_CONFIG)/" \
-e "s/@HAVE_LIBPCAP@/$(WINPCAP_CONFIG)/" \
-e "s/@HAVE_PCAP_FINDALLDEVS@/$(PCAP_FINDALLDEVS_CONFIG)/" \
-e "s/@WPCAP_CONSTIFIED@/$(WPCAP_CONSTIFIED_CONFIG)/" \
< config.h.win32 > $@

ps.c : rdps.exe print.ps
rdps print.ps ps.c
Expand Down
35 changes: 31 additions & 4 deletions capture-wpcap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.5 2003/10/10 06:05:48 guy Exp $
* $Id: capture-wpcap.c,v 1.6 2003/10/10 09:48:54 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
Expand Down Expand Up @@ -55,11 +55,20 @@ 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);
#ifdef WPCAP_CONSTIFIED
static int (*p_pcap_lookupnet) (const char *, bpf_u_int32 *, bpf_u_int32 *,
char *);
static pcap_t* (*p_pcap_open_live) (const char *, int, int, int, char *);
#else
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 *);
#endif
static int (*p_pcap_loop) (pcap_t *, int, pcap_handler, guchar *);
#ifdef HAVE_PCAP_FINDALLDEVS
static int (*p_pcap_findalldevs) (pcap_if_t **, char *);
static void (*p_pcap_freealldevs) (pcap_if_t *);
#endif
static const char *(*p_pcap_lib_version) (void);

typedef struct {
Expand Down Expand Up @@ -88,13 +97,16 @@ load_wpcap(void)
SYM(pcap_lookupnet, FALSE),
SYM(pcap_open_live, FALSE),
SYM(pcap_loop, FALSE),
#ifdef HAVE_PCAP_FINDALLDEVS
SYM(pcap_findalldevs, TRUE),
SYM(pcap_freealldevs, TRUE),
#endif
SYM(pcap_lib_version, TRUE),
{ NULL, NULL, FALSE }
};

GModule *wh; /* wpcap handle */
symbol_table_t *sym;
const symbol_table_t *sym;

wh = g_module_open("wpcap", 0);

Expand Down Expand Up @@ -192,14 +204,22 @@ pcap_compile(pcap_t *a, struct bpf_program *b, char *c, int d,
}

int
#ifdef WPCAP_CONSTIFIED
pcap_lookupnet(const char *a, bpf_u_int32 *b, bpf_u_int32 *c, char *d)
#else
pcap_lookupnet(char *a, bpf_u_int32 *b, bpf_u_int32 *c, char *d)
#endif
{
g_assert(has_wpcap);
return p_pcap_lookupnet(a, b, c, d);
}

pcap_t*
#ifdef WPCAP_CONSTIFIED
pcap_open_live(const char *a, int b, int c, int d, char *e)
#else
pcap_open_live(char *a, int b, int c, int d, char *e)
#endif
{
g_assert(has_wpcap);
return p_pcap_open_live(a, b, c, d, e);
Expand All @@ -216,9 +236,16 @@ pcap_loop(pcap_t *a, int b, pcap_handler c, guchar *d)
int
pcap_findalldevs(pcap_if_t **a, char *b)
{
g_assert(has_wpcap && p_pcap_findalldevs != NULL)
g_assert(has_wpcap && p_pcap_findalldevs != NULL);
return p_pcap_findalldevs(a, b);
}

void
pcap_freealldevs(pcap_if_t *a)
{
g_assert(has_wpcap && p_pcap_freealldevs != NULL);
p_pcap_freealldevs(a);
}
#endif

/*
Expand All @@ -237,7 +264,7 @@ get_interface_list(int *err, char *err_str)

#ifdef HAVE_PCAP_FINDALLDEVS
if (p_pcap_findalldevs != NULL)
return get_interface_list_findalldevs(err, errstr);
return get_interface_list_findalldevs(err, err_str);
#endif

/*
Expand Down
6 changes: 4 additions & 2 deletions config.h.win32
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $Id: config.h.win32,v 1.40 2003/06/12 09:45:42 guy Exp $ */
/* $Id: config.h.win32,v 1.41 2003/10/10 09:48:54 guy Exp $ */
/* config.h.win32 Generated manually. :-) */
/* config.h. Generated automatically by configure. */
/* config.h.in. Generated automatically from configure.in by autoheader. */
Expand Down Expand Up @@ -41,7 +41,9 @@

#define NEED_MKSTEMP 1

#define HAVE_LIBPCAP 1
@HAVE_LIBPCAP@
@HAVE_PCAP_FINDALLDEVS@
@WPCAP_CONSTIFIED@

#define HAVE_NET_SNMP 1
#define HAVE_SOME_SNMP 1
Expand Down
20 changes: 19 additions & 1 deletion config.nmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# $Id: config.nmake,v 1.59 2003/09/08 03:13:14 gerald Exp $
# $Id: config.nmake,v 1.60 2003/10/10 09:48:54 guy Exp $

VERSION=0.9.15
#
Expand All @@ -15,6 +15,8 @@ VERSION=0.9.15
RC_VERSION=0,9,15
WTAP_VERSION=0.0

WINPCAP_VERSION=2.3

GTK_VERSION=1.3
GLIB_VERSION=2.0

Expand Down Expand Up @@ -123,6 +125,22 @@ GTK_LIBS=$(GTK_DIR)\lib\gtk-win32-$(GTK_VERSION).lib \
$(GLIB_LIBS)
!ENDIF

!IFDEF WINPCAP_VERSION
# Nmake uses carets to escape special characters
WINPCAP_CONFIG=^#define HAVE_LIBPCAP 1
!IF "$(WINPCAP_VERSION)" == "3.0" || "$(WINPCAP_VERSION)" == "3.1"
PCAP_FINDALLDEVS_CONFIG=^#define HAVE_PCAP_FINDALLDEVS 1
WPCAP_CONSTIFIED_CONFIG=^#define WPCAP_CONSTIFIED 1
!ELSE
PCAP_FINDALLDEVS_CONFIG=
WPCAP_CONSTIFIED=
!ENDIF
!ELSE
WINPCAP_CONFIG=
PCAP_FINDALLDEVS_CONFIG=
WPCAP_CONSTIFIED=
!ENDIF

!IFDEF ADNS_DIR
ADNS_CFLAGS=/I$(ADNS_DIR)\src /I$(ADNS_DIR)\adns_win32
ADNS_LIBS=$(ADNS_DIR)\adns_win32\lib\adns_dll.lib
Expand Down

0 comments on commit bd2ea47

Please sign in to comment.