aboutsummaryrefslogtreecommitdiffstats
path: root/caputils
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2020-07-19 11:59:34 -0700
committerAnders Broman <a.broman58@gmail.com>2020-07-21 04:33:13 +0000
commit6b4fae1a0be72c280ea570d832f7d3b930cfd718 (patch)
treeb6d37e174c2346ffeb6a61e1e93ea91bb8e942c3 /caputils
parentca3b4a79b2d4236ea4b44ec5784ca1880d720c29 (diff)
Windows: Switch from the WpdPack SDK to vcpkg's libpcap.
Switch from WinPcap's WpdPack SDK to a libpcap package built with vcpkg. We explictly load wpcap.dll on Windows, so make sure we don't link with pcap.lib. Move timestamp code from capture-pcap-util-unix.c to capture-pcap-util.c. Add timestap routines to capture-wpcap.c and make a couple of other updates. Change-Id: If0e3dbeb7378c42ed9e3f91b2f15add95d22a2bb Reviewed-on: https://code.wireshark.org/review/37905 Reviewed-by: Gerald Combs <gerald@wireshark.org> Petri-Dish: Gerald Combs <gerald@wireshark.org> Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'caputils')
-rw-r--r--caputils/capture-pcap-util-unix.c92
-rw-r--r--caputils/capture-pcap-util.c91
-rw-r--r--caputils/capture-wpcap.c123
3 files changed, 190 insertions, 116 deletions
diff --git a/caputils/capture-pcap-util-unix.c b/caputils/capture-pcap-util-unix.c
index e963f3de60..936de1ce50 100644
--- a/caputils/capture-pcap-util-unix.c
+++ b/caputils/capture-pcap-util-unix.c
@@ -18,10 +18,6 @@
#include "wspcap.h"
-#ifdef __APPLE__
-#include <dlfcn.h>
-#endif
-
#ifdef HAVE_LIBCAP
# include <sys/capability.h>
#endif
@@ -57,94 +53,6 @@ cant_get_if_list_error_message(const char *err_str)
return g_strdup_printf("Can't get list of interfaces: %s", err_str);
}
-#ifdef HAVE_PCAP_SET_TSTAMP_PRECISION
-/*
- * Request high-resolution time stamps.
- *
- * We don't check for errors - if this fails, we just live with boring old
- * microsecond-resolution time stamps. The only errors pcap_set_tstamp_precision()
- * is documenting as returning are PCAP_ERROR_TSTAMP_PRECISION_NOTSUP, which just
- * means we can't do nanosecond precision on this adapter, in which case we
- * just live with whatever resolution we get by default, and
- * PCAP_ERROR_ACTIVATED, which shouldn't happen as we shouldn't call this
- * after we've activated the pcap_t.
- */
-void
-request_high_resolution_timestamp(pcap_t *pcap_h)
-{
-#ifdef __APPLE__
- /*
- * On macOS, if you build with a newer SDK, pcap_set_tstamp_precision()
- * is available, so the code will be built with it.
- *
- * However, if you then try to run on an older release that
- * doesn't have pcap_set_tstamp_precision(), the dynamic linker
- * will fail, as it won't find pcap_set_tstamp_precision().
- *
- * libpcap doesn't use macOS "weak linking" for new routines,
- * so we can't just check whether a pointer to
- * pcap_set_tstamp_precision() is null and, if it is, not
- * call it. We have to, instead, use dlopen() to load
- * libpcap, and dlsym() to find a pointer to pcap_set_tstamp_precision(),
- * and if we find the pointer, call it.
- */
- static gboolean initialized = FALSE;
- static int (*p_pcap_set_tstamp_precision)(pcap_t *, int);
-
- if (!initialized) {
- p_pcap_set_tstamp_precision =
- (int (*)(pcap_t *, int))
- dlsym(RTLD_NEXT, "pcap_set_tstamp_precision");
- initialized = TRUE;
- }
- if (p_pcap_set_tstamp_precision != NULL)
- (*p_pcap_set_tstamp_precision)(pcap_h, PCAP_TSTAMP_PRECISION_NANO);
-#else /* __APPLE__ */
- /*
- * On other UN*Xes we require that we be run on an OS version
- * with a libpcap equal to or later than the version with which
- * we were built.
- */
- pcap_set_tstamp_precision(pcap_h, PCAP_TSTAMP_PRECISION_NANO);
-#endif /* __APPLE__ */
-}
-
-/*
- * Return TRUE if the pcap_t in question is set up for high-precision
- * time stamps, FALSE otherwise.
- */
-gboolean
-have_high_resolution_timestamp(pcap_t *pcap_h)
-{
-#ifdef __APPLE__
- /*
- * See above.
- */
- static gboolean initialized = FALSE;
- static int (*p_pcap_get_tstamp_precision)(pcap_t *);
-
- if (!initialized) {
- p_pcap_get_tstamp_precision =
- (int (*)(pcap_t *))
- dlsym(RTLD_NEXT, "pcap_get_tstamp_precision");
- initialized = TRUE;
- }
- if (p_pcap_get_tstamp_precision != NULL)
- return (*p_pcap_get_tstamp_precision)(pcap_h) == PCAP_TSTAMP_PRECISION_NANO;
- else
- return FALSE; /* Can't get implies couldn't set */
-#else /* __APPLE__ */
- /*
- * On other UN*Xes we require that we be run on an OS version
- * with a libpcap equal to or later than the version with which
- * we were built.
- */
- return pcap_get_tstamp_precision(pcap_h) == PCAP_TSTAMP_PRECISION_NANO;
-#endif /* __APPLE__ */
-}
-
-#endif /* HAVE_PCAP_SET_TSTAMP_PRECISION */
-
if_capabilities_t *
get_if_capabilities_local(interface_options *interface_opts,
cap_device_open_err *err, char **err_str)
diff --git a/caputils/capture-pcap-util.c b/caputils/capture-pcap-util.c
index 6b16ddceca..7abe416557 100644
--- a/caputils/capture-pcap-util.c
+++ b/caputils/capture-pcap-util.c
@@ -25,6 +25,10 @@
#include <sys/socket.h>
#endif
+#ifdef __APPLE__
+#include <dlfcn.h>
+#endif
+
#include "ws_attributes.h"
/*
@@ -1032,6 +1036,93 @@ get_pcap_timestamp_types(pcap_t *pch _U_, char **err_str _U_)
return list;
}
+#ifdef HAVE_PCAP_SET_TSTAMP_PRECISION
+/*
+ * Request high-resolution time stamps.
+ *
+ * We don't check for errors - if this fails, we just live with boring old
+ * microsecond-resolution time stamps. The only errors pcap_set_tstamp_precision()
+ * is documenting as returning are PCAP_ERROR_TSTAMP_PRECISION_NOTSUP, which just
+ * means we can't do nanosecond precision on this adapter, in which case we
+ * just live with whatever resolution we get by default, and
+ * PCAP_ERROR_ACTIVATED, which shouldn't happen as we shouldn't call this
+ * after we've activated the pcap_t.
+ */
+void
+request_high_resolution_timestamp(pcap_t *pcap_h)
+{
+#ifdef __APPLE__
+ /*
+ * On macOS, if you build with a newer SDK, pcap_set_tstamp_precision()
+ * is available, so the code will be built with it.
+ *
+ * However, if you then try to run on an older release that
+ * doesn't have pcap_set_tstamp_precision(), the dynamic linker
+ * will fail, as it won't find pcap_set_tstamp_precision().
+ *
+ * libpcap doesn't use macOS "weak linking" for new routines,
+ * so we can't just check whether a pointer to
+ * pcap_set_tstamp_precision() is null and, if it is, not
+ * call it. We have to, instead, use dlopen() to load
+ * libpcap, and dlsym() to find a pointer to pcap_set_tstamp_precision(),
+ * and if we find the pointer, call it.
+ */
+ static gboolean initialized = FALSE;
+ static int (*p_pcap_set_tstamp_precision)(pcap_t *, int);
+
+ if (!initialized) {
+ p_pcap_set_tstamp_precision =
+ (int (*)(pcap_t *, int))
+ dlsym(RTLD_NEXT, "pcap_set_tstamp_precision");
+ initialized = TRUE;
+ }
+ if (p_pcap_set_tstamp_precision != NULL)
+ (*p_pcap_set_tstamp_precision)(pcap_h, PCAP_TSTAMP_PRECISION_NANO);
+#else /* __APPLE__ */
+ /*
+ * On other UN*Xes we require that we be run on an OS version
+ * with a libpcap equal to or later than the version with which
+ * we were built.
+ */
+ pcap_set_tstamp_precision(pcap_h, PCAP_TSTAMP_PRECISION_NANO);
+#endif /* __APPLE__ */
+}
+
+/*
+ * Return TRUE if the pcap_t in question is set up for high-precision
+ * time stamps, FALSE otherwise.
+ */
+gboolean
+have_high_resolution_timestamp(pcap_t *pcap_h)
+{
+#ifdef __APPLE__
+ /*
+ * See above.
+ */
+ static gboolean initialized = FALSE;
+ static int (*p_pcap_get_tstamp_precision)(pcap_t *);
+
+ if (!initialized) {
+ p_pcap_get_tstamp_precision =
+ (int (*)(pcap_t *))
+ dlsym(RTLD_NEXT, "pcap_get_tstamp_precision");
+ initialized = TRUE;
+ }
+ if (p_pcap_get_tstamp_precision != NULL)
+ return (*p_pcap_get_tstamp_precision)(pcap_h) == PCAP_TSTAMP_PRECISION_NANO;
+ else
+ return FALSE; /* Can't get implies couldn't set */
+#else /* __APPLE__ */
+ /*
+ * On other UN*Xes we require that we be run on an OS version
+ * with a libpcap equal to or later than the version with which
+ * we were built.
+ */
+ return pcap_get_tstamp_precision(pcap_h) == PCAP_TSTAMP_PRECISION_NANO;
+#endif /* __APPLE__ */
+}
+
+#endif /* HAVE_PCAP_SET_TSTAMP_PRECISION */
#ifdef HAVE_PCAP_CREATE
#ifdef HAVE_BONDING
diff --git a/caputils/capture-wpcap.c b/caputils/capture-wpcap.c
index f34ea537e0..064b939ba3 100644
--- a/caputils/capture-wpcap.c
+++ b/caputils/capture-wpcap.c
@@ -46,7 +46,6 @@ gboolean has_wpcap = FALSE;
* for using Wireshark?
*/
-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, guchar *);
@@ -76,7 +75,7 @@ static int (*p_pcap_next_ex) (pcap_t *, struct pcap_pkthdr **pkt_header, con
#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 *,
+static int (*p_pcap_findalldevs_ex) (const char *, struct pcap_rmtauth *,
pcap_if_t **, char *);
static int (*p_pcap_createsrcstr) (char *, int, const char *, const char *,
const char *, char *);
@@ -106,6 +105,17 @@ static int (*p_pcap_activate)(pcap_t *);
static const char *(*p_pcap_statustostr)(int);
#endif
+#ifdef HAVE_PCAP_SET_TSTAMP_TYPE
+static int (*p_pcap_set_tstamp_type)(pcap_t *, int);
+static int (*p_pcap_set_tstamp_precision)(pcap_t *, int);
+static int (*p_pcap_get_tstamp_precision)(pcap_t *);
+static int (*p_pcap_list_tstamp_types)(pcap_t *, int **);
+static void (*p_pcap_free_tstamp_types)(int *);
+static int (*p_pcap_tstamp_type_name_to_val)(const char *);
+static const char * (*p_pcap_tstamp_type_val_to_name)(int);
+static const char * (*p_pcap_tstamp_type_val_to_description)(int);
+#endif
+
typedef struct {
const char *name;
gpointer *ptr;
@@ -120,7 +130,6 @@ load_wpcap(void)
/* 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),
@@ -169,6 +178,16 @@ load_wpcap(void)
SYM(pcap_activate, TRUE),
SYM(pcap_statustostr, TRUE),
#endif
+#ifdef HAVE_PCAP_SET_TSTAMP_TYPE
+ SYM(pcap_set_tstamp_type, TRUE),
+ SYM(pcap_set_tstamp_precision, TRUE),
+ SYM(pcap_get_tstamp_precision, TRUE),
+ SYM(pcap_list_tstamp_types, TRUE),
+ SYM(pcap_free_tstamp_types, TRUE),
+ SYM(pcap_tstamp_type_name_to_val, TRUE),
+ SYM(pcap_tstamp_type_val_to_name, TRUE),
+ SYM(pcap_tstamp_type_val_to_description, TRUE),
+#endif
{ NULL, NULL, FALSE }
};
@@ -261,19 +280,6 @@ cant_load_winpcap_err(const char *app_name)
app_name);
}
-char*
-pcap_lookupdev(char *errbuf)
-{
- char *ret;
- if (!has_wpcap) {
- return NULL;
- }
- ret = p_pcap_lookupdev(errbuf);
- if (ret == NULL)
- convert_errbuf_to_utf8(errbuf);
- return ret;
-}
-
void
pcap_close(pcap_t *a)
{
@@ -412,7 +418,7 @@ pcap_open(const char *a, int b, int c, int d, struct pcap_rmtauth *e, char *errb
}
int
-pcap_findalldevs_ex(char *a, struct pcap_rmtauth *b, pcap_if_t **c, char *errbuf)
+pcap_findalldevs_ex(const char *a, struct pcap_rmtauth *b, pcap_if_t **c, char *errbuf)
{
int ret;
g_assert(has_wpcap);
@@ -560,6 +566,81 @@ pcap_statustostr(int a)
}
#endif
+#ifdef HAVE_PCAP_SET_TSTAMP_TYPE
+int
+pcap_set_tstamp_type(pcap_t *a, int b) {
+ g_assert(has_wpcap);
+ if (p_pcap_set_tstamp_type != NULL) {
+ return p_pcap_set_tstamp_type(a, b);
+ }
+ return PCAP_ERROR_CANTSET_TSTAMP_TYPE;
+}
+
+int
+pcap_set_tstamp_precision(pcap_t *a, int b) {
+ g_assert(has_wpcap);
+ if (p_pcap_set_tstamp_precision != NULL) {
+ return p_pcap_set_tstamp_precision(a, b);
+ }
+ // No error code defined so return NOTSUP.
+ return PCAP_ERROR_TSTAMP_PRECISION_NOTSUP;
+}
+
+int
+pcap_get_tstamp_precision(pcap_t *a) {
+ g_assert(has_wpcap);
+ if (p_pcap_get_tstamp_precision != NULL) {
+ return p_pcap_get_tstamp_precision(a);
+ }
+ // No error code defined so return MICRO.
+ return PCAP_TSTAMP_PRECISION_MICRO;
+}
+
+int
+pcap_list_tstamp_types(pcap_t *a, int **b) {
+ g_assert(has_wpcap);
+ if (p_pcap_list_tstamp_types != NULL) {
+ return p_pcap_list_tstamp_types(a, b);
+ }
+ return PCAP_ERROR;
+}
+
+void
+pcap_free_tstamp_types(int *a) {
+ g_assert(has_wpcap);
+ if (p_pcap_free_tstamp_types != NULL) {
+ p_pcap_free_tstamp_types(a);
+ }
+}
+
+int
+pcap_tstamp_type_name_to_val(const char *a) {
+ g_assert(has_wpcap);
+ if (p_pcap_tstamp_type_name_to_val != NULL) {
+ return p_pcap_tstamp_type_name_to_val(a);
+ }
+ return PCAP_ERROR;
+}
+
+const char *
+pcap_tstamp_type_val_to_name(int a) {
+ g_assert(has_wpcap);
+ if (p_pcap_tstamp_type_val_to_name != NULL) {
+ return p_pcap_tstamp_type_val_to_name(a);
+ }
+ return NULL;
+}
+
+const char *
+pcap_tstamp_type_val_to_description(int a) {
+ g_assert(has_wpcap);
+ if (p_pcap_tstamp_type_val_to_description != NULL) {
+ return p_pcap_tstamp_type_val_to_description(a);
+ }
+ return NULL;
+}
+#endif
+
int
pcap_datalink_name_to_val(const char *name)
{
@@ -732,18 +813,12 @@ open_capture_device_local(capture_options *capture_opts,
}
/*
- * Neither WpdPack nor the Npcap SDK as of version 1.01 defines a version
- * string anywhere. Hard-code one for now.
- */
-#define WINPCAP_SDK_VERSION "4.1.2"
-
-/*
* Append the WinPcap or Npcap SDK version with which we were compiled to a GString.
*/
void
get_compiled_caplibs_version(GString *str)
{
- g_string_append(str, "with WinPcap SDK (WpdPack) " WINPCAP_SDK_VERSION);
+ g_string_append(str, "with libpcap");
}
/*