aboutsummaryrefslogtreecommitdiffstats
path: root/caputils/capture-wpcap.c
diff options
context:
space:
mode:
Diffstat (limited to 'caputils/capture-wpcap.c')
-rw-r--r--caputils/capture-wpcap.c420
1 files changed, 17 insertions, 403 deletions
diff --git a/caputils/capture-wpcap.c b/caputils/capture-wpcap.c
index 5a81bdb5ce..461637fb2f 100644
--- a/caputils/capture-wpcap.c
+++ b/caputils/capture-wpcap.c
@@ -62,26 +62,14 @@ 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 *);
static int (*p_pcap_loop) (pcap_t *, int, pcap_handler, guchar *);
-#ifdef HAVE_PCAP_OPEN_DEAD
static pcap_t* (*p_pcap_open_dead) (int, int);
-#endif
static void (*p_pcap_freecode) (struct bpf_program *);
-#ifdef HAVE_PCAP_FINDALLDEVS
static int (*p_pcap_findalldevs) (pcap_if_t **, char *);
static void (*p_pcap_freealldevs) (pcap_if_t *);
-#endif
-#ifdef HAVE_PCAP_DATALINK_NAME_TO_VAL
static int (*p_pcap_datalink_name_to_val) (const char *);
-#endif
-#ifdef HAVE_PCAP_DATALINK_VAL_TO_NAME
static const char *(*p_pcap_datalink_val_to_name) (int);
-#endif
-#ifdef HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION
static const char *(*p_pcap_datalink_val_to_description) (int);
-#endif
-#ifdef HAVE_PCAP_BREAKLOOP
static void (*p_pcap_breakloop) (pcap_t *);
-#endif
static const char *(*p_pcap_lib_version) (void);
static int (*p_pcap_setbuff) (pcap_t *, int dim);
static int (*p_pcap_next_ex) (pcap_t *, struct pcap_pkthdr **pkt_header, const u_char **pkt_data);
@@ -97,21 +85,14 @@ static int (*p_pcap_createsrcstr) (char *, int, const char *, const char *,
static struct pcap_samp* (*p_pcap_setsampling)(pcap_t *);
#endif
-#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
#ifdef HAVE_PCAP_FREE_DATALINKS
static int (*p_pcap_free_datalinks)(int *);
#endif
-#ifdef HAVE_BPF_IMAGE
static char *(*p_bpf_image)(const struct bpf_insn *, int);
-#endif
#ifdef HAVE_PCAP_CREATE
static pcap_t *(*p_pcap_create)(const char *, char *);
@@ -156,50 +137,27 @@ load_wpcap(void)
SYM(pcap_createsrcstr, FALSE),
#endif
SYM(pcap_open_live, FALSE),
-#ifdef HAVE_PCAP_OPEN_DEAD
SYM(pcap_open_dead, FALSE),
-#endif
#ifdef HAVE_PCAP_SETSAMPLING
SYM(pcap_setsampling, TRUE),
#endif
SYM(pcap_loop, FALSE),
- SYM(pcap_freecode, TRUE),
-#ifdef HAVE_PCAP_FINDALLDEVS
- SYM(pcap_findalldevs, TRUE),
- SYM(pcap_freealldevs, TRUE),
-#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),
-#endif
-#ifdef HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION
- SYM(pcap_datalink_val_to_description, TRUE),
-#endif
-#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_freecode, FALSE),
+ SYM(pcap_findalldevs, FALSE),
+ SYM(pcap_freealldevs, FALSE),
+ SYM(pcap_datalink_name_to_val, FALSE),
+ SYM(pcap_datalink_val_to_name, FALSE),
+ SYM(pcap_datalink_val_to_description, FALSE),
SYM(pcap_breakloop, FALSE),
-#endif
- SYM(pcap_lib_version, TRUE),
+ SYM(pcap_lib_version, FALSE),
SYM(pcap_setbuff, TRUE),
SYM(pcap_next_ex, TRUE),
-#ifdef HAVE_PCAP_LIST_DATALINKS
SYM(pcap_list_datalinks, FALSE),
-#endif
-#ifdef HAVE_PCAP_SET_DATALINK
SYM(pcap_set_datalink, FALSE),
-#endif
#ifdef HAVE_PCAP_FREE_DATALINKS
SYM(pcap_free_datalinks, TRUE),
#endif
-#ifdef HAVE_BPF_IMAGE
SYM(bpf_image, FALSE),
-#endif
#ifdef HAVE_PCAP_CREATE
SYM(pcap_create, TRUE),
SYM(pcap_set_snaplen, TRUE),
@@ -351,14 +309,12 @@ pcap_datalink(pcap_t *a)
return p_pcap_datalink(a);
}
-#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
int
pcap_setfilter(pcap_t *a, struct bpf_program *b)
@@ -420,7 +376,6 @@ pcap_open_live(const char *a, int b, int c, int d, char *errbuf)
return p;
}
-#ifdef HAVE_PCAP_OPEN_DEAD
pcap_t*
pcap_open_dead(int a, int b)
{
@@ -429,9 +384,7 @@ pcap_open_dead(int a, int b)
}
return p_pcap_open_dead(a, b);
}
-#endif
-#ifdef HAVE_BPF_IMAGE
char *
bpf_image(const struct bpf_insn *a, int b)
{
@@ -440,7 +393,6 @@ bpf_image(const struct bpf_insn *a, int b)
}
return p_bpf_image(a, b);
}
-#endif
#ifdef HAVE_PCAP_REMOTE
pcap_t*
@@ -506,12 +458,9 @@ void
pcap_freecode(struct bpf_program *a)
{
g_assert(has_wpcap);
- if(p_pcap_freecode) {
- p_pcap_freecode(a);
- }
+ p_pcap_freecode(a);
}
-#ifdef HAVE_PCAP_FINDALLDEVS
int
pcap_findalldevs(pcap_if_t **a, char *errbuf)
{
@@ -529,7 +478,6 @@ pcap_freealldevs(pcap_if_t *a)
g_assert(has_wpcap && p_pcap_freealldevs != NULL);
p_pcap_freealldevs(a);
}
-#endif
#ifdef HAVE_PCAP_CREATE
pcap_t *
@@ -612,137 +560,19 @@ pcap_statustostr(int a)
}
#endif
-#if defined(HAVE_PCAP_DATALINK_NAME_TO_VAL) || defined(HAVE_PCAP_DATALINK_VAL_TO_NAME) || defined(HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION)
-/*
- * 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
-#ifdef DLT_LINUX_LAPD
- DLT_CHOICE(DLT_LINUX_LAPD, "Linux vISDN LAPD"),
-#endif
-#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"),
-#endif
-#ifdef DLT_PPI
- DLT_CHOICE(DLT_PPI, "Per-Packet Information"),
-#endif
- DLT_CHOICE_SENTINEL
-};
-#endif /* defined(HAVE_PCAP_DATALINK_NAME_TO_VAL) || defined(HAVE_PCAP_DATALINK_VAL_TO_NAME) || defined(HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION */
-
-#ifdef HAVE_PCAP_DATALINK_NAME_TO_VAL
int
pcap_datalink_name_to_val(const char *name)
{
- int i;
-
- if (has_wpcap && (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++) {
- if (g_ascii_strcasecmp(dlt_choices[i].name + sizeof("DLT_") - 1,
- name) == 0)
- return dlt_choices[i].dlt;
- }
- return -1;
- }
+ g_assert(has_wpcap);
+ return p_pcap_datalink_name_to_val(name);
}
-#endif
-#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
#ifdef HAVE_PCAP_FREE_DATALINKS
void
@@ -763,54 +593,24 @@ pcap_free_datalinks(int *ddlt)
}
#endif
-#ifdef HAVE_PCAP_DATALINK_VAL_TO_NAME
const char *
pcap_datalink_val_to_name(int dlt)
{
- int i;
-
- if (has_wpcap && (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;
- }
+ g_assert(has_wpcap);
+ return p_pcap_datalink_val_to_name(dlt);
}
-#endif
-#ifdef HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION
const char *
pcap_datalink_val_to_description(int dlt)
{
- int i;
-
- if (has_wpcap && (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;
- }
+ g_assert(has_wpcap);
+ return p_pcap_datalink_val_to_description(dlt);
}
-#endif
-#ifdef HAVE_PCAP_BREAKLOOP
void pcap_breakloop(pcap_t *a)
{
p_pcap_breakloop(a);
}
-#endif
/* setbuff is win32 specific! */
int pcap_setbuff(pcap_t *a, int b)
@@ -865,14 +665,6 @@ get_remote_interface_list(const char *hostname, const char *port,
GList *
get_interface_list(int *err, char **err_str)
{
- 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;
- char errbuf[PCAP_ERRBUF_SIZE];
-
if (!has_wpcap) {
/*
* We don't have Npcap or WinPcap, so we can't get a list of
@@ -884,146 +676,7 @@ get_interface_list(int *err, char **err_str)
return NULL;
}
-#ifdef HAVE_PCAP_FINDALLDEVS
- if (p_pcap_findalldevs != NULL)
- return get_interface_list_findalldevs(err, err_str);
-#endif
-
- /*
- * In WinPcap/Npcap, pcap_lookupdev is implemented by calling
- * PacketGetAdapterNames. According to the documentation
- * I could find:
- *
- * https://www.winpcap.org/docs/man/html/Packet32_8c.html#a43
- *
- * 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.
- */
-
- names = (wchar_t *)pcap_lookupdev(errbuf);
- 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)
- ascii_name[j++] = (char) names[i++];
- }
- ascii_name[j] = '\0';
- i++;
- il = g_list_append(il,
- if_info_new(ascii_name, ascii_desc, FALSE));
- }
- } 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, FALSE));
-
- /*
- * 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 = 0;
- if (err_str != NULL)
- *err_str = NULL;
- }
-
- return il;
+ return get_interface_list_findalldevs(err, err_str);
}
/*
@@ -1108,50 +761,11 @@ get_runtime_caplibs_version(GString *str)
/*
* On Windows, we might have been compiled with WinPcap/Npcap 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.
+ * not and, if we have it, what version we have.
*/
- GModule *handle; /* handle returned by ws_module_open */
- static gchar *packetVer;
- gchar *blankp;
-
if (has_wpcap) {
g_string_append_printf(str, "with ");
- if (p_pcap_lib_version != NULL)
- g_string_append_printf(str, p_pcap_lib_version());
- else {
- /*
- * An alternative method of obtaining the version
- * number, by using the PacketLibraryVersion
- * 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";
- handle = ws_module_open("packet.dll", 0);
- if (handle != NULL) {
- if (g_module_symbol(handle,
- "PacketLibraryVersion",
- (gpointer*)&packetVer)) {
- packetVer = g_strdup(packetVer);
- blankp = strchr(packetVer, ' ');
- if (blankp != NULL)
- *blankp = '\0';
- } else {
- packetVer = "version unknown";
- }
- g_module_close(handle);
- }
- }
- g_string_append_printf(str, "WinPcap (%s)", packetVer);
- }
+ g_string_append_printf(str, p_pcap_lib_version());
} else
g_string_append(str, "without Npcap or WinPcap");
}