2001-04-03 05:26:27 +00:00
|
|
|
/* capture-wpcap.c
|
2003-10-10 03:04:38 +00:00
|
|
|
* WinPcap-specific interfaces for capturing. We load WinPcap at run
|
2006-05-31 17:38:42 +00:00
|
|
|
* time, so that we only need one Wireshark binary and one TShark binary
|
2003-10-10 03:04:38 +00:00
|
|
|
* for Windows, regardless of whether WinPcap is installed or not.
|
2001-04-03 05:26:27 +00:00
|
|
|
*
|
2004-07-18 00:24:25 +00:00
|
|
|
* $Id$
|
2001-04-03 05:26:27 +00:00
|
|
|
*
|
2006-05-21 05:12:17 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
2001-04-03 05:26:27 +00:00
|
|
|
* 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.
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
2001-04-03 05:26:27 +00:00
|
|
|
* 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.
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
2001-04-03 05:26:27 +00:00
|
|
|
* 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
|
|
|
|
|
2007-11-30 22:01:05 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <glib.h>
|
|
|
|
#include <gmodule.h>
|
|
|
|
|
2010-03-04 01:33:56 +00:00
|
|
|
#include "capture_ifinfo.h"
|
2005-12-06 00:07:13 +00:00
|
|
|
#include "capture-pcap-util.h"
|
|
|
|
#include "capture-pcap-util-int.h"
|
2003-10-10 03:04:38 +00:00
|
|
|
|
2010-08-25 20:30:59 +00:00
|
|
|
#include <wsutil/file_util.h>
|
|
|
|
|
2009-08-29 07:53:48 +00:00
|
|
|
/* XXX - yes, I know, I should move cppmagic.h to a generic location. */
|
|
|
|
#include "tools/lemon/cppmagic.h"
|
|
|
|
|
2006-02-17 02:18:48 +00:00
|
|
|
#define MAX_WIN_IF_NAME_LEN 511
|
|
|
|
|
|
|
|
|
2001-04-03 05:26:27 +00:00
|
|
|
gboolean has_wpcap = FALSE;
|
|
|
|
|
|
|
|
#ifdef HAVE_LIBPCAP
|
|
|
|
|
2006-05-21 21:32:04 +00:00
|
|
|
/*
|
|
|
|
* XXX - should we require at least WinPcap 3.1 both for building an
|
|
|
|
* for using Wireshark?
|
|
|
|
*/
|
|
|
|
|
2001-04-03 05:26:27 +00:00
|
|
|
static char* (*p_pcap_lookupdev) (char *);
|
|
|
|
static void (*p_pcap_close) (pcap_t *);
|
|
|
|
static int (*p_pcap_stats) (pcap_t *, struct pcap_stat *);
|
2002-08-02 23:36:07 +00:00
|
|
|
static int (*p_pcap_dispatch) (pcap_t *, int, pcap_handler, guchar *);
|
2001-04-03 05:26:27 +00:00
|
|
|
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 *);
|
2009-04-16 04:05:39 +00:00
|
|
|
static int (*p_pcap_compile) (pcap_t *, struct bpf_program *, const char *, int,
|
2001-04-03 05:26:27 +00:00
|
|
|
bpf_u_int32);
|
2003-10-10 09:48:54 +00:00
|
|
|
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 *);
|
2002-08-02 23:36:07 +00:00
|
|
|
static int (*p_pcap_loop) (pcap_t *, int, pcap_handler, guchar *);
|
2005-03-23 01:25:01 +00:00
|
|
|
static void (*p_pcap_freecode) (struct bpf_program *);
|
2003-10-10 09:48:54 +00:00
|
|
|
#ifdef HAVE_PCAP_FINDALLDEVS
|
2003-10-10 06:05:48 +00:00
|
|
|
static int (*p_pcap_findalldevs) (pcap_if_t **, char *);
|
2003-10-10 09:48:54 +00:00
|
|
|
static void (*p_pcap_freealldevs) (pcap_if_t *);
|
|
|
|
#endif
|
2004-09-23 17:54:49 +00:00
|
|
|
#ifdef HAVE_PCAP_DATALINK_NAME_TO_VAL
|
2004-09-24 02:09:40 +00:00
|
|
|
static int (*p_pcap_datalink_name_to_val) (const char *);
|
2004-09-23 17:54:49 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_PCAP_DATALINK_VAL_TO_NAME
|
|
|
|
static const char *(*p_pcap_datalink_val_to_name) (int);
|
|
|
|
#endif
|
2009-12-18 20:36:36 +00:00
|
|
|
#ifdef HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION
|
|
|
|
static const char *(*p_pcap_datalink_val_to_description) (int);
|
|
|
|
#endif
|
2006-05-21 21:32:04 +00:00
|
|
|
#ifdef HAVE_PCAP_BREAKLOOP
|
|
|
|
static void (*p_pcap_breakloop) (pcap_t *);
|
|
|
|
#endif
|
2003-10-10 06:05:48 +00:00
|
|
|
static const char *(*p_pcap_lib_version) (void);
|
2004-03-13 22:49:30 +00:00
|
|
|
static int (*p_pcap_setbuff) (pcap_t *, int dim);
|
2005-05-25 21:37:46 +00:00
|
|
|
static int (*p_pcap_next_ex) (pcap_t *, struct pcap_pkthdr **pkt_header, const u_char **pkt_data);
|
2007-12-04 11:19:29 +00:00
|
|
|
#ifdef HAVE_PCAP_REMOTE
|
|
|
|
static pcap_t* (*p_pcap_open) (const char *, int, int, int,
|
|
|
|
struct pcap_rmtauth *, char *);
|
|
|
|
static int (*p_pcap_findalldevs_ex) (char *, struct pcap_rmtauth *,
|
|
|
|
pcap_if_t **, char *);
|
|
|
|
static int (*p_pcap_createsrcstr) (char *, int, const char *, const char *,
|
|
|
|
const char *, char *);
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_PCAP_SETSAMPLING
|
|
|
|
static struct pcap_samp* (*p_pcap_setsampling)(pcap_t *);
|
|
|
|
#endif
|
2001-04-03 05:26:27 +00:00
|
|
|
|
2008-06-24 21:16:22 +00:00
|
|
|
#ifdef HAVE_PCAP_LIST_DATALINKS
|
|
|
|
static int (*p_pcap_list_datalinks)(pcap_t *, int **);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_PCAP_SET_DATALINK
|
|
|
|
static int (*p_pcap_set_datalink)(pcap_t *, int);
|
|
|
|
#endif
|
|
|
|
|
2010-03-17 18:04:21 +00:00
|
|
|
#ifdef HAVE_PCAP_FREE_DATALINKS
|
2008-07-04 03:33:00 +00:00
|
|
|
static int (*p_pcap_free_datalinks)(int *);
|
|
|
|
#endif
|
|
|
|
|
2001-04-03 05:26:27 +00:00
|
|
|
typedef struct {
|
|
|
|
const char *name;
|
|
|
|
gpointer *ptr;
|
2003-10-10 03:04:38 +00:00
|
|
|
gboolean optional;
|
2001-04-03 05:26:27 +00:00
|
|
|
} symbol_table_t;
|
|
|
|
|
2009-08-29 07:53:48 +00:00
|
|
|
#define SYM(x, y) { STRINGIFY(x) , (gpointer) &CONCAT(p_,x), y }
|
2001-04-03 05:26:27 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
load_wpcap(void)
|
|
|
|
{
|
|
|
|
|
2003-10-10 03:04:38 +00:00
|
|
|
/* These are the symbols I need or want from Wpcap */
|
|
|
|
static const symbol_table_t symbols[] = {
|
|
|
|
SYM(pcap_lookupdev, FALSE),
|
|
|
|
SYM(pcap_close, FALSE),
|
|
|
|
SYM(pcap_stats, FALSE),
|
|
|
|
SYM(pcap_dispatch, FALSE),
|
|
|
|
SYM(pcap_snapshot, FALSE),
|
|
|
|
SYM(pcap_datalink, FALSE),
|
|
|
|
SYM(pcap_setfilter, FALSE),
|
|
|
|
SYM(pcap_geterr, FALSE),
|
|
|
|
SYM(pcap_compile, FALSE),
|
|
|
|
SYM(pcap_lookupnet, FALSE),
|
2007-12-04 11:19:29 +00:00
|
|
|
#ifdef HAVE_PCAP_REMOTE
|
|
|
|
SYM(pcap_open, FALSE),
|
|
|
|
SYM(pcap_findalldevs_ex, FALSE),
|
|
|
|
SYM(pcap_createsrcstr, FALSE),
|
|
|
|
#endif
|
2010-05-11 21:09:21 +00:00
|
|
|
SYM(pcap_open_live, FALSE),
|
2007-12-04 11:19:29 +00:00
|
|
|
#ifdef HAVE_PCAP_SETSAMPLING
|
|
|
|
SYM(pcap_setsampling, TRUE),
|
|
|
|
#endif
|
2003-10-10 03:04:38 +00:00
|
|
|
SYM(pcap_loop, FALSE),
|
2005-05-21 09:59:49 +00:00
|
|
|
SYM(pcap_freecode, TRUE),
|
2003-10-10 09:48:54 +00:00
|
|
|
#ifdef HAVE_PCAP_FINDALLDEVS
|
2003-10-10 03:04:38 +00:00
|
|
|
SYM(pcap_findalldevs, TRUE),
|
2003-10-10 09:48:54 +00:00
|
|
|
SYM(pcap_freealldevs, TRUE),
|
2004-09-23 17:54:49 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_PCAP_DATALINK_NAME_TO_VAL
|
|
|
|
SYM(pcap_datalink_name_to_val, TRUE),
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_PCAP_DATALINK_VAL_TO_NAME
|
|
|
|
SYM(pcap_datalink_val_to_name, TRUE),
|
2006-05-21 21:32:04 +00:00
|
|
|
#endif
|
2009-12-18 20:36:36 +00:00
|
|
|
#ifdef HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION
|
|
|
|
SYM(pcap_datalink_val_to_description, TRUE),
|
|
|
|
#endif
|
2006-05-21 21:32:04 +00:00
|
|
|
#ifdef HAVE_PCAP_BREAKLOOP
|
|
|
|
/*
|
|
|
|
* We don't try to work around the lack of this at
|
|
|
|
* run time; it's present in WinPcap 3.1, which is
|
|
|
|
* the version we build with and ship with.
|
|
|
|
*/
|
|
|
|
SYM(pcap_breakloop, FALSE),
|
2003-10-10 09:48:54 +00:00
|
|
|
#endif
|
2003-10-10 06:05:48 +00:00
|
|
|
SYM(pcap_lib_version, TRUE),
|
2004-03-13 22:49:30 +00:00
|
|
|
SYM(pcap_setbuff, TRUE),
|
2005-05-21 09:59:49 +00:00
|
|
|
SYM(pcap_next_ex, TRUE),
|
2008-06-24 21:16:22 +00:00
|
|
|
#ifdef HAVE_PCAP_LIST_DATALINKS
|
|
|
|
SYM(pcap_list_datalinks, FALSE),
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_PCAP_SET_DATALINK
|
|
|
|
SYM(pcap_set_datalink, FALSE),
|
2008-07-04 03:33:00 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_PCAP_FREE_DATALINKS
|
|
|
|
SYM(pcap_free_datalinks, TRUE),
|
2008-06-24 21:16:22 +00:00
|
|
|
#endif
|
2003-10-10 03:04:38 +00:00
|
|
|
{ NULL, NULL, FALSE }
|
2001-04-03 05:26:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
GModule *wh; /* wpcap handle */
|
2003-10-10 09:48:54 +00:00
|
|
|
const symbol_table_t *sym;
|
2001-04-03 05:26:27 +00:00
|
|
|
|
2010-08-25 20:30:59 +00:00
|
|
|
wh = ws_module_open("wpcap.dll", 0);
|
2001-04-03 05:26:27 +00:00
|
|
|
|
|
|
|
if (!wh) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sym = symbols;
|
2003-10-10 03:04:38 +00:00
|
|
|
while (sym->name) {
|
2001-04-03 05:26:27 +00:00
|
|
|
if (!g_module_symbol(wh, sym->name, sym->ptr)) {
|
2003-10-10 03:04:38 +00:00
|
|
|
if (sym->optional) {
|
|
|
|
/*
|
|
|
|
* We don't care if it's missing; we just
|
|
|
|
* don't use it.
|
|
|
|
*/
|
|
|
|
*sym->ptr = NULL;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* We require this symbol.
|
|
|
|
*/
|
|
|
|
return;
|
|
|
|
}
|
2001-04-03 05:26:27 +00:00
|
|
|
}
|
|
|
|
sym++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
has_wpcap = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
char*
|
|
|
|
pcap_lookupdev (char *a)
|
|
|
|
{
|
2009-12-07 18:21:58 +00:00
|
|
|
if (!has_wpcap) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-04-03 05:26:27 +00:00
|
|
|
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
|
2002-08-02 23:36:07 +00:00
|
|
|
pcap_dispatch(pcap_t *a, int b, pcap_handler c, guchar *d)
|
2001-04-03 05:26:27 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2008-06-24 21:16:22 +00:00
|
|
|
#ifdef HAVE_PCAP_SET_DATALINK
|
|
|
|
int
|
|
|
|
pcap_set_datalink(pcap_t *p, int dlt)
|
|
|
|
{
|
|
|
|
g_assert(has_wpcap);
|
|
|
|
return p_pcap_set_datalink(p, dlt);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-04-03 05:26:27 +00:00
|
|
|
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
|
2009-04-16 04:05:39 +00:00
|
|
|
pcap_compile(pcap_t *a, struct bpf_program *b, const char *c, int d,
|
2001-04-03 05:26:27 +00:00
|
|
|
bpf_u_int32 e)
|
|
|
|
{
|
|
|
|
g_assert(has_wpcap);
|
|
|
|
return p_pcap_compile(a, b, c, d, e);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-10-10 09:48:54 +00:00
|
|
|
pcap_lookupnet(const char *a, bpf_u_int32 *b, bpf_u_int32 *c, char *d)
|
2001-04-03 05:26:27 +00:00
|
|
|
{
|
|
|
|
g_assert(has_wpcap);
|
|
|
|
return p_pcap_lookupnet(a, b, c, d);
|
|
|
|
}
|
|
|
|
|
|
|
|
pcap_t*
|
2003-10-10 09:48:54 +00:00
|
|
|
pcap_open_live(const char *a, int b, int c, int d, char *e)
|
2001-04-03 05:26:27 +00:00
|
|
|
{
|
2009-12-15 19:29:21 +00:00
|
|
|
if (!has_wpcap) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return p_pcap_open_live(a, b, c, d, e);
|
2001-04-03 05:26:27 +00:00
|
|
|
}
|
|
|
|
|
2007-12-04 11:19:29 +00:00
|
|
|
#ifdef HAVE_PCAP_REMOTE
|
|
|
|
pcap_t*
|
|
|
|
pcap_open(const char *a, int b, int c, int d, struct pcap_rmtauth *e, char *f)
|
|
|
|
{
|
2009-12-15 19:29:21 +00:00
|
|
|
if (!has_wpcap) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2007-12-04 11:19:29 +00:00
|
|
|
return p_pcap_open(a, b, c, d, e, f);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
pcap_findalldevs_ex(char *a, struct pcap_rmtauth *b, pcap_if_t **c, char *d)
|
|
|
|
{
|
|
|
|
g_assert(has_wpcap);
|
|
|
|
return p_pcap_findalldevs_ex(a, b, c, d);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
pcap_createsrcstr(char *a, int b, const char *c, const char *d, const char *e,
|
|
|
|
char *f)
|
|
|
|
{
|
|
|
|
g_assert(has_wpcap);
|
|
|
|
return p_pcap_createsrcstr(a, b, c, d, e, f);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_PCAP_SETSAMPLING
|
|
|
|
struct pcap_samp *
|
|
|
|
pcap_setsampling(pcap_t *a)
|
|
|
|
{
|
|
|
|
g_assert(has_wpcap);
|
|
|
|
if (p_pcap_setsampling != NULL) {
|
|
|
|
return p_pcap_setsampling(a);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-04-03 05:26:27 +00:00
|
|
|
int
|
2002-08-02 23:36:07 +00:00
|
|
|
pcap_loop(pcap_t *a, int b, pcap_handler c, guchar *d)
|
2001-04-03 05:26:27 +00:00
|
|
|
{
|
|
|
|
g_assert(has_wpcap);
|
|
|
|
return p_pcap_loop(a, b, c, d);
|
|
|
|
}
|
|
|
|
|
2005-03-23 01:25:01 +00:00
|
|
|
void
|
|
|
|
pcap_freecode(struct bpf_program *a)
|
|
|
|
{
|
|
|
|
g_assert(has_wpcap);
|
2005-05-21 09:59:49 +00:00
|
|
|
if(p_pcap_freecode) {
|
|
|
|
p_pcap_freecode(a);
|
|
|
|
}
|
2005-03-23 01:25:01 +00:00
|
|
|
}
|
|
|
|
|
2003-10-10 03:04:38 +00:00
|
|
|
#ifdef HAVE_PCAP_FINDALLDEVS
|
|
|
|
int
|
|
|
|
pcap_findalldevs(pcap_if_t **a, char *b)
|
|
|
|
{
|
2003-10-10 09:48:54 +00:00
|
|
|
g_assert(has_wpcap && p_pcap_findalldevs != NULL);
|
2003-10-10 03:04:38 +00:00
|
|
|
return p_pcap_findalldevs(a, b);
|
|
|
|
}
|
2003-10-10 09:48:54 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
pcap_freealldevs(pcap_if_t *a)
|
|
|
|
{
|
|
|
|
g_assert(has_wpcap && p_pcap_freealldevs != NULL);
|
|
|
|
p_pcap_freealldevs(a);
|
|
|
|
}
|
2003-10-10 03:04:38 +00:00
|
|
|
#endif
|
|
|
|
|
2009-12-18 20:36:36 +00:00
|
|
|
#if defined(HAVE_PCAP_DATALINK_NAME_TO_VAL) || defined(HAVE_PCAP_DATALINK_VAL_TO_NAME) || defined(HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION)
|
2004-09-27 01:11:23 +00:00
|
|
|
/*
|
|
|
|
* Table of DLT_ types, names, and descriptions, for use if the version
|
|
|
|
* of WinPcap we have installed lacks "pcap_datalink_name_to_val()"
|
|
|
|
* or "pcap_datalink_val_to_name()".
|
|
|
|
*/
|
|
|
|
struct dlt_choice {
|
|
|
|
const char *name;
|
|
|
|
const char *description;
|
|
|
|
int dlt;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define DLT_CHOICE(code, description) { #code, description, code }
|
|
|
|
#define DLT_CHOICE_SENTINEL { NULL, NULL, 0 }
|
|
|
|
|
|
|
|
static struct dlt_choice dlt_choices[] = {
|
|
|
|
DLT_CHOICE(DLT_NULL, "BSD loopback"),
|
|
|
|
DLT_CHOICE(DLT_EN10MB, "Ethernet"),
|
|
|
|
DLT_CHOICE(DLT_IEEE802, "Token ring"),
|
|
|
|
DLT_CHOICE(DLT_ARCNET, "ARCNET"),
|
|
|
|
DLT_CHOICE(DLT_SLIP, "SLIP"),
|
|
|
|
DLT_CHOICE(DLT_PPP, "PPP"),
|
|
|
|
DLT_CHOICE(DLT_FDDI, "FDDI"),
|
|
|
|
DLT_CHOICE(DLT_ATM_RFC1483, "RFC 1483 IP-over-ATM"),
|
|
|
|
DLT_CHOICE(DLT_RAW, "Raw IP"),
|
|
|
|
#ifdef DLT_SLIP_BSDOS
|
|
|
|
DLT_CHOICE(DLT_SLIP_BSDOS, "BSD/OS SLIP"),
|
|
|
|
#endif
|
|
|
|
#ifdef DLT_PPP_BSDOS
|
|
|
|
DLT_CHOICE(DLT_PPP_BSDOS, "BSD/OS PPP"),
|
|
|
|
#endif
|
|
|
|
#ifdef DLT_ATM_CLIP
|
|
|
|
DLT_CHOICE(DLT_ATM_CLIP, "Linux Classical IP-over-ATM"),
|
|
|
|
#endif
|
|
|
|
#ifdef DLT_PPP_SERIAL
|
|
|
|
DLT_CHOICE(DLT_PPP_SERIAL, "PPP over serial"),
|
|
|
|
#endif
|
|
|
|
#ifdef DLT_PPP_ETHER
|
|
|
|
DLT_CHOICE(DLT_PPP_ETHER, "PPPoE"),
|
|
|
|
#endif
|
|
|
|
#ifdef DLT_C_HDLC
|
|
|
|
DLT_CHOICE(DLT_C_HDLC, "Cisco HDLC"),
|
|
|
|
#endif
|
|
|
|
#ifdef DLT_IEEE802_11
|
|
|
|
DLT_CHOICE(DLT_IEEE802_11, "802.11"),
|
|
|
|
#endif
|
|
|
|
#ifdef DLT_FRELAY
|
|
|
|
DLT_CHOICE(DLT_FRELAY, "Frame Relay"),
|
|
|
|
#endif
|
|
|
|
#ifdef DLT_LOOP
|
|
|
|
DLT_CHOICE(DLT_LOOP, "OpenBSD loopback"),
|
|
|
|
#endif
|
|
|
|
#ifdef DLT_ENC
|
|
|
|
DLT_CHOICE(DLT_ENC, "OpenBSD encapsulated IP"),
|
|
|
|
#endif
|
|
|
|
#ifdef DLT_LINUX_SLL
|
|
|
|
DLT_CHOICE(DLT_LINUX_SLL, "Linux cooked"),
|
|
|
|
#endif
|
|
|
|
#ifdef DLT_LTALK
|
|
|
|
DLT_CHOICE(DLT_LTALK, "Localtalk"),
|
|
|
|
#endif
|
|
|
|
#ifdef DLT_PFLOG
|
|
|
|
DLT_CHOICE(DLT_PFLOG, "OpenBSD pflog file"),
|
|
|
|
#endif
|
|
|
|
#ifdef DLT_PRISM_HEADER
|
|
|
|
DLT_CHOICE(DLT_PRISM_HEADER, "802.11 plus Prism header"),
|
|
|
|
#endif
|
|
|
|
#ifdef DLT_IP_OVER_FC
|
|
|
|
DLT_CHOICE(DLT_IP_OVER_FC, "RFC 2625 IP-over-Fibre Channel"),
|
|
|
|
#endif
|
|
|
|
#ifdef DLT_SUNATM
|
|
|
|
DLT_CHOICE(DLT_SUNATM, "Sun raw ATM"),
|
|
|
|
#endif
|
|
|
|
#ifdef DLT_IEEE802_11_RADIO
|
|
|
|
DLT_CHOICE(DLT_IEEE802_11_RADIO, "802.11 plus radio information header"),
|
|
|
|
#endif
|
|
|
|
#ifdef DLT_ARCNET_LINUX
|
|
|
|
DLT_CHOICE(DLT_ARCNET_LINUX, "Linux ARCNET"),
|
|
|
|
#endif
|
|
|
|
#ifdef DLT_LINUX_IRDA
|
|
|
|
DLT_CHOICE(DLT_LINUX_IRDA, "Linux IrDA"),
|
|
|
|
#endif
|
2006-03-02 21:29:15 +00:00
|
|
|
#ifdef DLT_LINUX_LAPD
|
|
|
|
DLT_CHOICE(DLT_LINUX_LAPD, "Linux vISDN LAPD"),
|
|
|
|
#endif
|
2004-09-27 01:11:23 +00:00
|
|
|
#ifdef DLT_LANE8023
|
|
|
|
DLT_CHOICE(DLT_LANE8023, "Linux 802.3 LANE"),
|
|
|
|
#endif
|
|
|
|
#ifdef DLT_CIP
|
|
|
|
DLT_CHOICE(DLT_CIP, "Linux Classical IP-over-ATM"),
|
|
|
|
#endif
|
|
|
|
#ifdef DLT_HDLC
|
|
|
|
DLT_CHOICE(DLT_HDLC, "Cisco HDLC"),
|
2009-12-18 20:36:36 +00:00
|
|
|
#endif
|
|
|
|
#ifdef DLT_PPI
|
|
|
|
DLT_CHOICE(DLT_PPI, "Per-Packet Information"),
|
2004-09-27 01:11:23 +00:00
|
|
|
#endif
|
|
|
|
DLT_CHOICE_SENTINEL
|
|
|
|
};
|
2009-12-18 20:36:36 +00:00
|
|
|
#endif /* defined(HAVE_PCAP_DATALINK_NAME_TO_VAL) || defined(HAVE_PCAP_DATALINK_VAL_TO_NAME) || defined(HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION */
|
2004-09-27 01:11:23 +00:00
|
|
|
|
2004-09-23 17:54:49 +00:00
|
|
|
#ifdef HAVE_PCAP_DATALINK_NAME_TO_VAL
|
|
|
|
int
|
|
|
|
pcap_datalink_name_to_val(const char *name)
|
|
|
|
{
|
2004-09-27 01:11:23 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
g_assert(has_wpcap);
|
|
|
|
|
|
|
|
if (p_pcap_datalink_name_to_val != NULL)
|
|
|
|
return p_pcap_datalink_name_to_val(name);
|
|
|
|
else {
|
|
|
|
/*
|
|
|
|
* We don't have it in WinPcap; do it ourselves.
|
|
|
|
*/
|
|
|
|
for (i = 0; dlt_choices[i].name != NULL; i++) {
|
strcasecmp(), strncasecmp(), g_strcasecmp(), and g_strncasecmp() delenda
est. Use g_ascii_strcasecmp() and g_ascii_strncasecmp(), and supply our
own versions if they're missing from GLib (as is the case with GLib
1.x).
In the code to build the list of named fields for Diameter, don't use
g_strdown(); do our own g_ascii_-style upper-case to lower-case mapping
in the hash function and use g_ascii_strcasecmp() in the compare
function.
We do this because there is no guarantee that toupper(), tolower(), and
functions that use them will, for example, map between "I" and "i" in
all locales; in Turkish locales, for example, there are, in both
upper case and lower case, versions of "i" with and without a dot, and
the upper-case version of "i" is "I"-with-a-dot and the lower-case
version of "I" is "i"-without-a-dot. This causes strings that should
match not to match.
This finishes fixing bug 2010 - an earlier checkin prevented the crash
(as there are other ways to produce the same crash, e.g. a bogus
dictionary.xml file), but didn't fix the case-insensitive string matching.
svn path=/trunk/; revision=23623
2007-11-27 18:52:51 +00:00
|
|
|
if (g_ascii_strcasecmp(dlt_choices[i].name + sizeof("DLT_") - 1,
|
2004-09-27 01:11:23 +00:00
|
|
|
name) == 0)
|
|
|
|
return dlt_choices[i].dlt;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
2004-09-23 17:54:49 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-06-24 21:16:22 +00:00
|
|
|
#ifdef HAVE_PCAP_LIST_DATALINKS
|
|
|
|
int
|
|
|
|
pcap_list_datalinks(pcap_t *p, int **ddlt)
|
|
|
|
{
|
|
|
|
g_assert(has_wpcap);
|
|
|
|
return p_pcap_list_datalinks(p, ddlt);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-07-04 03:33:00 +00:00
|
|
|
#ifdef HAVE_PCAP_FREE_DATALINKS
|
|
|
|
void
|
|
|
|
pcap_free_datalinks(int *ddlt)
|
|
|
|
{
|
|
|
|
g_assert(has_wpcap);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we don't have pcap_free_datalinks() in WinPcap,
|
|
|
|
* we don't free the memory - we can't use free(), as
|
|
|
|
* we might not have been built with the same version
|
|
|
|
* of the C runtime library as WinPcap was, and, if we're
|
|
|
|
* not, free() isn't guaranteed to work on something
|
|
|
|
* allocated by WinPcap.
|
|
|
|
*/
|
|
|
|
if (p_pcap_free_datalinks != NULL)
|
|
|
|
p_pcap_free_datalinks(ddlt);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-09-23 17:54:49 +00:00
|
|
|
#ifdef HAVE_PCAP_DATALINK_VAL_TO_NAME
|
|
|
|
const char *
|
|
|
|
pcap_datalink_val_to_name(int dlt)
|
|
|
|
{
|
2004-09-27 01:11:23 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
g_assert(has_wpcap);
|
|
|
|
|
|
|
|
if (p_pcap_datalink_val_to_name != NULL)
|
|
|
|
return p_pcap_datalink_val_to_name(dlt);
|
|
|
|
else {
|
|
|
|
/*
|
|
|
|
* We don't have it in WinPcap; do it ourselves.
|
|
|
|
*/
|
|
|
|
for (i = 0; dlt_choices[i].name != NULL; i++) {
|
|
|
|
if (dlt_choices[i].dlt == dlt)
|
|
|
|
return dlt_choices[i].name + sizeof("DLT_") - 1;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2004-09-23 17:54:49 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-12-18 20:36:36 +00:00
|
|
|
#ifdef HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION
|
|
|
|
const char *
|
|
|
|
pcap_datalink_val_to_description(int dlt)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
g_assert(has_wpcap);
|
|
|
|
|
|
|
|
if (p_pcap_datalink_val_to_description != NULL)
|
|
|
|
return p_pcap_datalink_val_to_description(dlt);
|
|
|
|
else {
|
|
|
|
/*
|
|
|
|
* We don't have it in WinPcap; do it ourselves.
|
|
|
|
*/
|
|
|
|
for (i = 0; dlt_choices[i].name != NULL; i++) {
|
|
|
|
if (dlt_choices[i].dlt == dlt)
|
|
|
|
return (dlt_choices[i].description);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-05-21 21:32:04 +00:00
|
|
|
#ifdef HAVE_PCAP_BREAKLOOP
|
|
|
|
void pcap_breakloop(pcap_t *a)
|
|
|
|
{
|
|
|
|
p_pcap_breakloop(a);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-03-13 22:49:30 +00:00
|
|
|
/* setbuff is win32 specific! */
|
|
|
|
int pcap_setbuff(pcap_t *a, int b)
|
|
|
|
{
|
|
|
|
g_assert(has_wpcap);
|
|
|
|
return p_pcap_setbuff(a, b);
|
|
|
|
}
|
|
|
|
|
2005-05-25 21:37:46 +00:00
|
|
|
/* pcap_next_ex is available since libpcap 0.8 / WinPcap 3.0! */
|
|
|
|
/* (if you get a declaration warning here, try to update to at least WinPcap 3.1b4 develpack) */
|
|
|
|
int pcap_next_ex (pcap_t *a, struct pcap_pkthdr **b, const u_char **c)
|
2005-05-21 09:59:49 +00:00
|
|
|
{
|
|
|
|
g_assert(has_wpcap);
|
|
|
|
return p_pcap_next_ex(a, b, c);
|
|
|
|
}
|
|
|
|
|
2007-12-04 11:19:29 +00:00
|
|
|
#ifdef HAVE_PCAP_REMOTE
|
|
|
|
GList *
|
|
|
|
get_remote_interface_list(const char *hostname, const char *port,
|
|
|
|
int auth_type, const char *username,
|
|
|
|
const char *passwd, int *err, char **err_str)
|
|
|
|
{
|
|
|
|
struct pcap_rmtauth auth;
|
|
|
|
char source[PCAP_BUF_SIZE];
|
|
|
|
char errbuf[PCAP_ERRBUF_SIZE];
|
|
|
|
GList *result;
|
|
|
|
|
|
|
|
if (pcap_createsrcstr(source, PCAP_SRC_IFREMOTE, hostname, port,
|
|
|
|
NULL, errbuf) == -1) {
|
|
|
|
*err = CANT_GET_INTERFACE_LIST;
|
|
|
|
if (err_str != NULL)
|
|
|
|
*err_str = cant_get_if_list_error_message(errbuf);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
auth.type = auth_type;
|
|
|
|
auth.username = g_strdup(username);
|
|
|
|
auth.password = g_strdup(passwd);
|
|
|
|
|
|
|
|
result = get_interface_list_findalldevs_ex(source, &auth, err, err_str);
|
|
|
|
g_free(auth.username);
|
|
|
|
g_free(auth.password);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2003-10-10 03:04:38 +00:00
|
|
|
/*
|
|
|
|
* This will use "pcap_findalldevs()" if we have it, otherwise it'll
|
|
|
|
* fall back on "pcap_lookupdev()".
|
|
|
|
*/
|
|
|
|
GList *
|
2007-01-21 23:45:36 +00:00
|
|
|
get_interface_list(int *err, char **err_str)
|
2003-10-10 03:04:38 +00:00
|
|
|
{
|
|
|
|
GList *il = NULL;
|
|
|
|
wchar_t *names;
|
|
|
|
char *win95names;
|
|
|
|
char ascii_name[MAX_WIN_IF_NAME_LEN + 1];
|
|
|
|
char ascii_desc[MAX_WIN_IF_NAME_LEN + 1];
|
|
|
|
int i, j;
|
2007-01-21 23:45:36 +00:00
|
|
|
char errbuf[PCAP_ERRBUF_SIZE];
|
2003-10-10 03:04:38 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_PCAP_FINDALLDEVS
|
|
|
|
if (p_pcap_findalldevs != NULL)
|
2003-10-10 09:48:54 +00:00
|
|
|
return get_interface_list_findalldevs(err, err_str);
|
2003-10-10 03:04:38 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* In WinPcap, pcap_lookupdev is implemented by calling
|
|
|
|
* PacketGetAdapterNames. According to the documentation
|
|
|
|
* I could find:
|
|
|
|
*
|
2005-06-03 09:55:28 +00:00
|
|
|
* http://www.winpcap.org/docs/man/html/Packet32_8c.html#a43
|
2003-10-10 03:04:38 +00:00
|
|
|
*
|
|
|
|
* this means that:
|
|
|
|
*
|
|
|
|
* On Windows OT (95, 98, Me), pcap_lookupdev returns a sequence
|
|
|
|
* of bytes consisting of:
|
|
|
|
*
|
|
|
|
* a sequence of null-terminated ASCII strings (i.e., each
|
|
|
|
* one is terminated by a single 0 byte), giving the names
|
|
|
|
* of the interfaces;
|
|
|
|
*
|
|
|
|
* an empty ASCII string (i.e., a single 0 byte);
|
|
|
|
*
|
|
|
|
* a sequence of null-terminated ASCII strings, giving the
|
|
|
|
* descriptions of the interfaces;
|
|
|
|
*
|
|
|
|
* an empty ASCII string.
|
|
|
|
*
|
|
|
|
* On Windows NT (NT 4.0, W2K, WXP, W2K3, etc.), pcap_lookupdev
|
|
|
|
* returns a sequence of bytes consisting of:
|
|
|
|
*
|
|
|
|
* a sequence of null-terminated double-byte Unicode strings
|
|
|
|
* (i.e., each one consits of a sequence of double-byte
|
|
|
|
* characters, terminated by a double-byte 0), giving the
|
|
|
|
* names of the interfaces;
|
|
|
|
*
|
|
|
|
* an empty Unicode string (i.e., a double 0 byte);
|
|
|
|
*
|
|
|
|
* a sequence of null-terminated ASCII strings, giving the
|
|
|
|
* descriptions of the interfaces;
|
|
|
|
*
|
|
|
|
* an empty ASCII string.
|
|
|
|
*
|
|
|
|
* The Nth string in the first sequence is the name of the Nth
|
|
|
|
* adapter; the Nth string in the second sequence is the
|
|
|
|
* description of the Nth adapter.
|
|
|
|
*/
|
|
|
|
|
2007-01-21 23:45:36 +00:00
|
|
|
names = (wchar_t *)pcap_lookupdev(errbuf);
|
2003-10-10 03:04:38 +00:00
|
|
|
i = 0;
|
|
|
|
|
|
|
|
if (names) {
|
|
|
|
char* desc = 0;
|
|
|
|
int desc_pos = 0;
|
|
|
|
|
|
|
|
if (names[0]<256) {
|
|
|
|
/*
|
|
|
|
* If names[0] is less than 256 it means the first
|
|
|
|
* byte is 0. This implies that we are using Unicode
|
|
|
|
* characters.
|
|
|
|
*/
|
|
|
|
while (*(names+desc_pos) || *(names+desc_pos-1))
|
|
|
|
desc_pos++;
|
|
|
|
desc_pos++; /* Step over the extra '\0' */
|
|
|
|
desc = (char*)(names + desc_pos); /* cast *after* addition */
|
|
|
|
|
|
|
|
while (names[i] != 0) {
|
|
|
|
/*
|
|
|
|
* Copy the Unicode description to an ASCII
|
|
|
|
* string.
|
|
|
|
*/
|
|
|
|
j = 0;
|
|
|
|
while (*desc != 0) {
|
|
|
|
if (j < MAX_WIN_IF_NAME_LEN)
|
|
|
|
ascii_desc[j++] = *desc;
|
|
|
|
desc++;
|
|
|
|
}
|
|
|
|
ascii_desc[j] = '\0';
|
|
|
|
desc++;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy the Unicode name to an ASCII string.
|
|
|
|
*/
|
|
|
|
j = 0;
|
|
|
|
while (names[i] != 0) {
|
|
|
|
if (j < MAX_WIN_IF_NAME_LEN)
|
2004-01-05 19:31:44 +00:00
|
|
|
ascii_name[j++] = (char) names[i++];
|
2003-10-10 03:04:38 +00:00
|
|
|
}
|
|
|
|
ascii_name[j] = '\0';
|
|
|
|
i++;
|
|
|
|
il = g_list_append(il,
|
|
|
|
if_info_new(ascii_name, ascii_desc));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Otherwise we are in Windows 95/98 and using ASCII
|
|
|
|
* (8-bit) characters.
|
|
|
|
*/
|
|
|
|
win95names=(char *)names;
|
|
|
|
while (*(win95names+desc_pos) || *(win95names+desc_pos-1))
|
|
|
|
desc_pos++;
|
|
|
|
desc_pos++; /* Step over the extra '\0' */
|
|
|
|
desc = win95names + desc_pos;
|
|
|
|
|
|
|
|
while (win95names[i] != '\0') {
|
|
|
|
/*
|
|
|
|
* "&win95names[i]" points to the current
|
|
|
|
* interface name, and "desc" points to
|
|
|
|
* that interface's description.
|
|
|
|
*/
|
|
|
|
il = g_list_append(il,
|
|
|
|
if_info_new(&win95names[i], desc));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Skip to the next description.
|
|
|
|
*/
|
|
|
|
while (*desc != 0)
|
|
|
|
desc++;
|
|
|
|
desc++;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Skip to the next name.
|
|
|
|
*/
|
|
|
|
while (win95names[i] != 0)
|
|
|
|
i++;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (il == NULL) {
|
|
|
|
/*
|
|
|
|
* No interfaces found.
|
|
|
|
*/
|
|
|
|
*err = NO_INTERFACES_FOUND;
|
2007-01-21 23:45:36 +00:00
|
|
|
if (err_str != NULL)
|
|
|
|
*err_str = NULL;
|
2003-10-10 03:04:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return il;
|
|
|
|
}
|
|
|
|
|
2004-06-12 07:47:14 +00:00
|
|
|
/*
|
|
|
|
* Get an error message string for a CANT_GET_INTERFACE_LIST error from
|
|
|
|
* "get_interface_list()".
|
|
|
|
*/
|
|
|
|
gchar *
|
|
|
|
cant_get_if_list_error_message(const char *err_str)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* If the error message includes "Not enough storage is available
|
|
|
|
* to process this command" or "The operation completed successfully",
|
|
|
|
* suggest that they install a WinPcap version later than 3.0.
|
|
|
|
*/
|
|
|
|
if (strstr(err_str, "Not enough storage is available to process this command") != NULL ||
|
|
|
|
strstr(err_str, "The operation completed successfully") != NULL) {
|
|
|
|
return g_strdup_printf("Can't get list of interfaces: %s\n"
|
|
|
|
"This might be a problem with WinPcap 3.0; you should try updating to\n"
|
2005-06-03 09:55:28 +00:00
|
|
|
"a later version of WinPcap - see the WinPcap site at www.winpcap.org",
|
2004-06-12 07:47:14 +00:00
|
|
|
err_str);
|
|
|
|
}
|
|
|
|
return g_strdup_printf("Can't get list of interfaces: %s", err_str);
|
|
|
|
}
|
|
|
|
|
2003-10-10 06:05:48 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2004-08-10 05:27:50 +00:00
|
|
|
GModule *handle; /* handle returned by dlopen */
|
2005-04-14 20:37:13 +00:00
|
|
|
static gchar *packetVer;
|
|
|
|
gchar *blankp;
|
2004-08-10 05:27:50 +00:00
|
|
|
|
2003-10-10 06:05:48 +00:00
|
|
|
if (has_wpcap) {
|
2008-05-07 05:26:40 +00:00
|
|
|
g_string_append_printf(str, "with ");
|
2003-10-10 06:05:48 +00:00
|
|
|
if (p_pcap_lib_version != NULL)
|
2008-05-07 05:26:40 +00:00
|
|
|
g_string_append_printf(str, p_pcap_lib_version());
|
2005-04-14 20:37:13 +00:00
|
|
|
else {
|
|
|
|
/*
|
|
|
|
* An alternative method of obtaining the version
|
2005-10-04 03:58:40 +00:00
|
|
|
* number, by using the PacketLibraryVersion
|
2005-04-14 20:37:13 +00:00
|
|
|
* string from packet.dll.
|
|
|
|
*
|
|
|
|
* Unfortunately, in WinPcap 3.0, it returns
|
|
|
|
* "3.0 alpha3", even in the final version of
|
|
|
|
* WinPcap 3.0, so if there's a blank in the
|
|
|
|
* string, we strip it and everything after
|
|
|
|
* it from the string, so we don't misleadingly
|
|
|
|
* report that 3.0 alpha3 is being used when
|
|
|
|
* the final version is being used.
|
|
|
|
*/
|
|
|
|
if (packetVer == NULL) {
|
|
|
|
packetVer = "version unknown";
|
2010-08-25 20:30:59 +00:00
|
|
|
handle = ws_module_open("packet.dll", 0);
|
2005-04-14 20:37:13 +00:00
|
|
|
if (handle != NULL) {
|
|
|
|
if (g_module_symbol(handle,
|
|
|
|
"PacketLibraryVersion",
|
|
|
|
(gpointer*)&packetVer)) {
|
|
|
|
packetVer = g_strdup(packetVer);
|
|
|
|
blankp = strchr(packetVer, ' ');
|
|
|
|
if (blankp != NULL)
|
|
|
|
*blankp = '\0';
|
2005-10-04 03:58:40 +00:00
|
|
|
} else {
|
|
|
|
packetVer = "version unknown";
|
|
|
|
}
|
2005-04-14 20:37:13 +00:00
|
|
|
g_module_close(handle);
|
|
|
|
}
|
|
|
|
}
|
2008-05-07 05:26:40 +00:00
|
|
|
g_string_append_printf(str, "WinPcap (%s)", packetVer);
|
2005-04-14 20:37:13 +00:00
|
|
|
}
|
2003-10-10 06:05:48 +00:00
|
|
|
} else
|
|
|
|
g_string_append(str, "without WinPcap");
|
|
|
|
}
|
|
|
|
|
2001-04-03 05:26:27 +00:00
|
|
|
#else /* HAVE_LIBPCAP */
|
|
|
|
|
|
|
|
void
|
|
|
|
load_wpcap(void)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-10-10 06:05:48 +00:00
|
|
|
/*
|
|
|
|
* 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_)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-04-03 05:26:27 +00:00
|
|
|
#endif /* HAVE_LIBPCAP */
|