If opening a capture device provides a warning, show it.

We start the capture anyway, but print a warning message or pop up a
warning dialog first.
This commit is contained in:
Guy Harris 2021-06-23 01:42:14 -07:00
parent cdd6f2ec80
commit 6d9b0646d8
6 changed files with 190 additions and 129 deletions

View File

@ -33,23 +33,24 @@ extern void request_high_resolution_timestamp(pcap_t *pcap_h);
#endif
extern if_capabilities_t *get_if_capabilities_local(interface_options *interface_opts,
cap_device_open_err *err, char **err_str);
cap_device_open_status *status, char **status_str);
extern pcap_t *open_capture_device_local(capture_options *capture_opts,
interface_options *interface_opts, int timeout,
cap_device_open_err *open_err, char (*open_err_str)[PCAP_ERRBUF_SIZE]);
cap_device_open_status *open_status,
char (*open_status_str)[PCAP_ERRBUF_SIZE]);
#ifdef HAVE_PCAP_CREATE
extern if_capabilities_t *get_if_capabilities_pcap_create(interface_options *interface_opts,
cap_device_open_err *err, char **err_str);
cap_device_open_status *status, char **status_str);
extern pcap_t *open_capture_device_pcap_create(capture_options *capture_opts,
interface_options *interface_opts, int timeout,
cap_device_open_err *open_err,
char (*open_err_str)[PCAP_ERRBUF_SIZE]);
cap_device_open_status *open_status,
char (*open_status_str)[PCAP_ERRBUF_SIZE]);
#endif /* HAVE_PCAP_CREATE */
extern if_capabilities_t *get_if_capabilities_pcap_open_live(interface_options *interface_opts,
cap_device_open_err *err, char **err_str);
cap_device_open_status *status, char **status_str);
extern pcap_t *open_capture_device_pcap_open_live(interface_options *interface_opts,
int timeout, cap_device_open_err *open_err,
char (*open_err_str)[PCAP_ERRBUF_SIZE]);
int timeout, cap_device_open_status *open_status,
char (*open_status_str)[PCAP_ERRBUF_SIZE]);
/*
* Get an error message string for a CANT_GET_INTERFACE_LIST error from

View File

@ -56,12 +56,14 @@ cant_get_if_list_error_message(const char *err_str)
if_capabilities_t *
get_if_capabilities_local(interface_options *interface_opts,
cap_device_open_err *err, char **err_str)
cap_device_open_status *status, char **status_str)
{
#ifdef HAVE_PCAP_CREATE
return get_if_capabilities_pcap_create(interface_opts, err, err_str);
return get_if_capabilities_pcap_create(interface_opts, status,
status_str);
#else
return get_if_capabilities_pcap_open_live(interface_opts, err, err_str);
return get_if_capabilities_pcap_open_live(interface_opts, status,
status_str);
#endif
}
@ -72,7 +74,8 @@ open_capture_device_local(capture_options *capture_opts
#endif
,
interface_options *interface_opts, int timeout,
cap_device_open_err *open_err, char (*open_err_str)[PCAP_ERRBUF_SIZE])
cap_device_open_status *open_status,
char (*open_status_str)[PCAP_ERRBUF_SIZE])
{
/*
* We're not opening a remote device; use pcap_create() and
@ -81,10 +84,10 @@ open_capture_device_local(capture_options *capture_opts
*/
#ifdef HAVE_PCAP_CREATE
return open_capture_device_pcap_create(capture_opts,
interface_opts, timeout, open_err, open_err_str);
interface_opts, timeout, open_status, open_status_str);
#else
return open_capture_device_pcap_open_live(interface_opts, timeout,
open_err, open_err_str);
open_status, open_status_str);
#endif
}

View File

@ -923,7 +923,7 @@ create_data_link_info(int dlt)
static GList *
get_data_link_types(pcap_t *pch, interface_options *interface_opts,
cap_device_open_err *err, char **err_str)
cap_device_open_status *status, char **status_str)
{
GList *data_link_types;
int deflt;
@ -946,19 +946,19 @@ get_data_link_types(pcap_t *pch, interface_options *interface_opts,
* them properly.
*/
if (nlt == PCAP_ERROR) {
*err = CAP_DEVICE_OPEN_ERR_GENERIC;
*err_str = g_strdup_printf("pcap_list_datalinks() failed: %s",
*status = CAP_DEVICE_OPEN_ERR_GENERIC;
*status_str = g_strdup_printf("pcap_list_datalinks() failed: %s",
pcap_geterr(pch));
} else {
if (nlt == PCAP_ERROR_PERM_DENIED)
*err = CAP_DEVICE_OPEN_ERR_PERMISSIONS;
*status = CAP_DEVICE_OPEN_ERR_PERMISSIONS;
else
*err = CAP_DEVICE_OPEN_ERR_NOT_PERMISSIONS;
*err_str = g_strdup(pcap_statustostr(nlt));
*status = CAP_DEVICE_OPEN_ERR_NOT_PERMISSIONS;
*status_str = g_strdup(pcap_statustostr(nlt));
}
#else /* HAVE_PCAP_CREATE */
*err = CAP_DEVICE_OPEN_ERR_GENERIC;
*err_str = g_strdup_printf("pcap_list_datalinks() failed: %s",
*status = CAP_DEVICE_OPEN_ERR_GENERIC;
*status_str = g_strdup_printf("pcap_list_datalinks() failed: %s",
pcap_geterr(pch));
#endif /* HAVE_PCAP_CREATE */
return NULL;
@ -1005,7 +1005,7 @@ get_data_link_types(pcap_t *pch, interface_options *interface_opts,
#endif /* _WIN32 */
#endif /* HAVE_PCAP_FREE_DATALINKS */
*err_str = NULL;
*status_str = NULL;
return data_link_types;
}
@ -1166,7 +1166,7 @@ is_linux_bonding_device(const char *ifname _U_)
if_capabilities_t *
get_if_capabilities_pcap_create(interface_options *interface_opts,
cap_device_open_err *err, char **err_str)
cap_device_open_status *open_status, char **open_status_str)
{
if_capabilities_t *caps;
char errbuf[PCAP_ERRBUF_SIZE];
@ -1175,8 +1175,8 @@ get_if_capabilities_pcap_create(interface_options *interface_opts,
pch = pcap_create(interface_opts->name, errbuf);
if (pch == NULL) {
*err = CAP_DEVICE_OPEN_ERR_NOT_PERMISSIONS;
*err_str = g_strdup(errbuf);
*open_status = CAP_DEVICE_OPEN_ERR_NOT_PERMISSIONS;
*open_status_str = g_strdup(errbuf);
return NULL;
}
@ -1196,15 +1196,15 @@ get_if_capabilities_pcap_create(interface_options *interface_opts,
if (status < 0) {
/* Error. */
if (status == PCAP_ERROR) {
*err = CAP_DEVICE_OPEN_ERR_GENERIC;
*err_str = g_strdup_printf("pcap_can_set_rfmon() failed: %s",
*open_status = CAP_DEVICE_OPEN_ERR_GENERIC;
*open_status_str = g_strdup_printf("pcap_can_set_rfmon() failed: %s",
pcap_geterr(pch));
} else {
if (status == PCAP_ERROR_PERM_DENIED)
*err = CAP_DEVICE_OPEN_ERR_PERMISSIONS;
*open_status = CAP_DEVICE_OPEN_ERR_PERMISSIONS;
else
*err = CAP_DEVICE_OPEN_ERR_NOT_PERMISSIONS;
*err_str = g_strdup(pcap_statustostr(status));
*open_status = CAP_DEVICE_OPEN_ERR_NOT_PERMISSIONS;
*open_status_str = g_strdup(pcap_statustostr(status));
}
pcap_close(pch);
return NULL;
@ -1217,8 +1217,8 @@ get_if_capabilities_pcap_create(interface_options *interface_opts,
if (interface_opts->monitor_mode)
pcap_set_rfmon(pch, 1);
} else {
*err = CAP_DEVICE_OPEN_ERR_NOT_PERMISSIONS;
*err_str = g_strdup_printf("pcap_can_set_rfmon() returned %d",
*open_status = CAP_DEVICE_OPEN_ERR_NOT_PERMISSIONS;
*open_status_str = g_strdup_printf("pcap_can_set_rfmon() returned %d",
status);
pcap_close(pch);
g_free(caps);
@ -1227,17 +1227,17 @@ get_if_capabilities_pcap_create(interface_options *interface_opts,
status = pcap_activate(pch);
if (status < 0) {
/* Error. We ignore warnings (status > 0). */
/* Error. */
if (status == PCAP_ERROR) {
*err = CAP_DEVICE_OPEN_ERR_GENERIC;
*err_str = g_strdup_printf("pcap_activate() failed: %s",
*open_status = CAP_DEVICE_OPEN_ERR_GENERIC;
*open_status_str = g_strdup_printf("pcap_activate() failed: %s",
pcap_geterr(pch));
} else {
if (status == PCAP_ERROR_PERM_DENIED)
*err = CAP_DEVICE_OPEN_ERR_PERMISSIONS;
*open_status = CAP_DEVICE_OPEN_ERR_PERMISSIONS;
else
*err = CAP_DEVICE_OPEN_ERR_NOT_PERMISSIONS;
*err_str = g_strdup(pcap_statustostr(status));
*open_status = CAP_DEVICE_OPEN_ERR_NOT_PERMISSIONS;
*open_status_str = g_strdup(pcap_statustostr(status));
}
pcap_close(pch);
g_free(caps);
@ -1245,7 +1245,7 @@ get_if_capabilities_pcap_create(interface_options *interface_opts,
}
caps->data_link_types = get_data_link_types(pch, interface_opts,
err, err_str);
open_status, open_status_str);
if (caps->data_link_types == NULL) {
pcap_close(pch);
g_free(caps);
@ -1256,8 +1256,8 @@ get_if_capabilities_pcap_create(interface_options *interface_opts,
pcap_close(pch);
if (err_str != NULL)
*err_str = NULL;
if (open_status_str != NULL)
*open_status_str = NULL;
return caps;
}
@ -1269,17 +1269,17 @@ open_capture_device_pcap_create(
capture_options* capture_opts _U_,
#endif
interface_options *interface_opts, int timeout,
cap_device_open_err *open_err,
char (*open_err_str)[PCAP_ERRBUF_SIZE])
cap_device_open_status *open_status,
char (*open_status_str)[PCAP_ERRBUF_SIZE])
{
pcap_t *pcap_h;
int status;
ws_debug("Calling pcap_create() using %s.", interface_opts->name);
pcap_h = pcap_create(interface_opts->name, *open_err_str);
pcap_h = pcap_create(interface_opts->name, *open_status_str);
ws_debug("pcap_create() returned %p.", (void *)pcap_h);
if (pcap_h == NULL) {
*open_err = CAP_DEVICE_OPEN_ERR_NOT_PERMISSIONS;
*open_status = CAP_DEVICE_OPEN_ERR_NOT_PERMISSIONS;
return NULL;
}
if (interface_opts->has_snaplen) {
@ -1324,9 +1324,9 @@ open_capture_device_pcap_create(
* isn't supported?
*/
if (status == PCAP_ERROR) {
*open_err = CAP_DEVICE_OPEN_ERR_NOT_PERMISSIONS;
(void) g_strlcpy(*open_err_str, pcap_geterr(pcap_h),
sizeof *open_err_str);
*open_status = CAP_DEVICE_OPEN_ERR_NOT_PERMISSIONS;
(void) g_strlcpy(*open_status_str, pcap_geterr(pcap_h),
sizeof *open_status_str);
pcap_close(pcap_h);
return NULL;
}
@ -1345,27 +1345,46 @@ open_capture_device_pcap_create(
if (status < 0) {
/* Failed to activate, set to NULL */
if (status == PCAP_ERROR) {
*open_err = CAP_DEVICE_OPEN_ERR_GENERIC;
(void) g_strlcpy(*open_err_str, pcap_geterr(pcap_h),
sizeof *open_err_str);
*open_status = CAP_DEVICE_OPEN_ERR_GENERIC;
(void) g_strlcpy(*open_status_str, pcap_geterr(pcap_h),
sizeof *open_status_str);
} else {
if (status == PCAP_ERROR_PERM_DENIED)
*open_err = CAP_DEVICE_OPEN_ERR_PERMISSIONS;
*open_status = CAP_DEVICE_OPEN_ERR_PERMISSIONS;
else
*open_err = CAP_DEVICE_OPEN_ERR_NOT_PERMISSIONS;
(void) g_strlcpy(*open_err_str, pcap_statustostr(status),
sizeof *open_err_str);
*open_status = CAP_DEVICE_OPEN_ERR_NOT_PERMISSIONS;
(void) g_strlcpy(*open_status_str, pcap_statustostr(status),
sizeof *open_status_str);
}
pcap_close(pcap_h);
return NULL;
}
if (status > 0) {
/*
* Warning. The call succeeded, but something happened
* that the user might want to know.
*/
*open_status = CAP_DEVICE_OPEN_WARNING_GENERIC;
if (status == PCAP_WARNING) {
g_snprintf(*open_status_str, sizeof *open_status_str,
"Warning: %s", pcap_geterr(pcap_h));
} else {
g_snprintf(*open_status_str, sizeof *open_status_str,
"Warning: %s", pcap_statustostr(status));
}
} else {
/*
* No warning issued.
*/
*open_status = CAP_DEVICE_OPEN_NO_ERR;
}
return pcap_h;
}
#endif /* HAVE_PCAP_CREATE */
if_capabilities_t *
get_if_capabilities_pcap_open_live(interface_options *interface_opts,
cap_device_open_err *err, char **err_str)
cap_device_open_status *open_status, char **open_status_str)
{
if_capabilities_t *caps;
char errbuf[PCAP_ERRBUF_SIZE];
@ -1374,15 +1393,15 @@ get_if_capabilities_pcap_open_live(interface_options *interface_opts,
pch = pcap_open_live(interface_opts->name, MIN_PACKET_SIZE, 0, 0,
errbuf);
if (pch == NULL) {
*err = CAP_DEVICE_OPEN_ERR_GENERIC;
*err_str = g_strdup(errbuf[0] == '\0' ? "Unknown error (pcap bug; actual error cause not reported)" : errbuf);
*open_status = CAP_DEVICE_OPEN_ERR_GENERIC;
*open_status_str = g_strdup(errbuf[0] == '\0' ? "Unknown error (pcap bug; actual error cause not reported)" : errbuf);
return NULL;
}
caps = (if_capabilities_t *)g_malloc(sizeof *caps);
caps->can_set_rfmon = FALSE;
caps->data_link_types = get_data_link_types(pch, interface_opts,
err, err_str);
open_status, open_status_str);
if (caps->data_link_types == NULL) {
pcap_close(pch);
g_free(caps);
@ -1393,14 +1412,15 @@ get_if_capabilities_pcap_open_live(interface_options *interface_opts,
pcap_close(pch);
*err_str = NULL;
*open_status = CAP_DEVICE_OPEN_NO_ERR;
*open_status_str = NULL;
return caps;
}
pcap_t *
open_capture_device_pcap_open_live(interface_options *interface_opts,
int timeout, cap_device_open_err *open_err,
char (*open_err_str)[PCAP_ERRBUF_SIZE])
int timeout, cap_device_open_status *open_status,
char (*open_status_str)[PCAP_ERRBUF_SIZE])
{
pcap_t *pcap_h;
int snaplen;
@ -1419,13 +1439,33 @@ open_capture_device_pcap_open_live(interface_options *interface_opts,
}
ws_debug("pcap_open_live() calling using name %s, snaplen %d, promisc_mode %d.",
interface_opts->name, snaplen, interface_opts->promisc_mode);
/*
* This might succeed but put a messsage in *open_status_str;
* that means that a warning was issued.
*
* Clear the error message buffer, so that if it's not an empty
* string after the call, we know a warning was issued.
*/
(*open_status_str)[0] = '\0';
pcap_h = pcap_open_live(interface_opts->name, snaplen,
interface_opts->promisc_mode, timeout, *open_err_str);
interface_opts->promisc_mode, timeout, *open_status_str);
ws_debug("pcap_open_live() returned %p.", (void *)pcap_h);
if (pcap_h == NULL) {
*open_err = CAP_DEVICE_OPEN_ERR_GENERIC;
*open_status = CAP_DEVICE_OPEN_ERR_GENERIC;
return NULL;
}
if ((*open_status_str)[0] != '\0') {
/*
* Warning. The call succeeded, but something happened
* that the user might want to know.
*/
*open_status = CAP_DEVICE_OPEN_WARNING_GENERIC;
} else {
/*
* No warning issued.
*/
*open_status = CAP_DEVICE_OPEN_NO_ERR;
}
#ifdef _WIN32
/* Try to set the capture buffer size. */
@ -1449,7 +1489,7 @@ open_capture_device_pcap_open_live(interface_options *interface_opts,
*/
if_capabilities_t *
get_if_capabilities(interface_options *interface_opts,
cap_device_open_err *err, char **err_str)
cap_device_open_status *status, char **status_str)
{
#if defined(HAVE_PCAP_OPEN) && defined(HAVE_PCAP_REMOTE)
if_capabilities_t *caps;
@ -1486,11 +1526,12 @@ get_if_capabilities(interface_options *interface_opts,
if (pch == NULL) {
/*
* We don't know whether it's a permission error or not.
* (If it is, maybe we can give ourselves permission or
* maybe we just have to ask politely for permission.)
* And, if it is, the user will either have to ask for
* permission for their own remote account or will have
* to use an account that *does* have permissions.
*/
*err = CAP_DEVICE_OPEN_ERR_GENERIC;
*err_str = g_strdup(errbuf[0] == '\0' ? "Unknown error (pcap bug; actual error cause not reported)" : errbuf);
*status = CAP_DEVICE_OPEN_ERR_GENERIC;
*status_str = g_strdup(errbuf[0] == '\0' ? "Unknown error (pcap bug; actual error cause not reported)" : errbuf);
return NULL;
}
@ -1503,7 +1544,12 @@ get_if_capabilities(interface_options *interface_opts,
caps->timestamp_types = get_pcap_timestamp_types(pch, NULL);
pcap_close(pch);
*err_str = NULL;
/*
* This doesn't return warnings for remote devices, and
* we don't use it for local devices.
*/
*status = CAP_DEVICE_OPEN_NO_ERR;
*status_str = NULL;
return caps;
}
#endif /* defined(HAVE_PCAP_OPEN) && defined(HAVE_PCAP_REMOTE) */
@ -1511,14 +1557,14 @@ get_if_capabilities(interface_options *interface_opts,
/*
* Local interface.
*/
return get_if_capabilities_local(interface_opts, err, err_str);
return get_if_capabilities_local(interface_opts, status, status_str);
}
pcap_t *
open_capture_device(capture_options *capture_opts,
interface_options *interface_opts, int timeout,
cap_device_open_err *open_err,
char (*open_err_str)[PCAP_ERRBUF_SIZE])
cap_device_open_status *open_status,
char (*open_status_str)[PCAP_ERRBUF_SIZE])
{
pcap_t *pcap_h;
#if defined(HAVE_PCAP_OPEN) && defined(HAVE_PCAP_REMOTE)
@ -1530,8 +1576,8 @@ open_capture_device(capture_options *capture_opts,
if they succeed; to tell if that's happened, we have to clear
the error buffer, and check if it's still a null string. */
ws_debug("Entering open_capture_device().");
*open_err = CAP_DEVICE_OPEN_NO_ERR;
(*open_err_str)[0] = '\0';
*open_status = CAP_DEVICE_OPEN_NO_ERR;
(*open_status_str)[0] = '\0';
#if defined(HAVE_PCAP_OPEN) && defined(HAVE_PCAP_REMOTE)
/*
* If we're opening a remote device, use pcap_open(); that's currently
@ -1563,7 +1609,7 @@ open_capture_device(capture_options *capture_opts,
(interface_opts->promisc_mode ? PCAP_OPENFLAG_PROMISCUOUS : 0) |
(interface_opts->datatx_udp ? PCAP_OPENFLAG_DATATX_UDP : 0) |
(interface_opts->nocap_rpcap ? PCAP_OPENFLAG_NOCAPTURE_RPCAP : 0),
timeout, &auth, *open_err_str);
timeout, &auth, *open_status_str);
if (pcap_h == NULL) {
/*
* Error.
@ -1574,27 +1620,32 @@ open_capture_device(capture_options *capture_opts,
* or maybe we just have to ask politely for
* permission.)
*/
*open_err = CAP_DEVICE_OPEN_ERR_GENERIC;
*open_status = CAP_DEVICE_OPEN_ERR_GENERIC;
/* Did pcap actually supply an error message? */
if ((*open_err_str)[0] == '\0') {
if ((*open_status_str)[0] == '\0') {
/*
* Work around known WinPcap bug wherein
* no error message is filled in on a
* failure to open an rpcap: URL.
*/
(void) g_strlcpy(*open_err_str,
(void) g_strlcpy(*open_status_str,
"Unknown error (pcap bug; actual error cause not reported)",
sizeof *open_err_str);
sizeof *open_status_str);
}
}
ws_debug("pcap_open() returned %p.", (void *)pcap_h);
ws_debug("open_capture_device %s : %s", pcap_h ? "SUCCESS" : "FAILURE", interface_opts->name);
/*
* This doesn't return warnings for remote devices, and
* we don't use it for local devices.
*/
*open_status = CAP_DEVICE_OPEN_NO_ERR;
return pcap_h;
}
#endif
pcap_h = open_capture_device_local(capture_opts, interface_opts,
timeout, open_err, open_err_str);
timeout, open_status, open_status_str);
ws_debug("open_capture_device %s : %s", pcap_h ? "SUCCESS" : "FAILURE", interface_opts->name);
return pcap_h;
}

View File

@ -58,20 +58,21 @@ gboolean have_high_resolution_timestamp(pcap_t *pcap_h);
#endif /* HAVE_PCAP_SET_TSTAMP_PRECISION */
/*
* Error values.
* Capture device open status values.
*/
typedef enum {
CAP_DEVICE_OPEN_NO_ERR, /* No error */
CAP_DEVICE_OPEN_NO_ERR, /* No error and no warning */
CAP_DEVICE_OPEN_ERR_PERMISSIONS, /* Error is known to be a permissions error */
CAP_DEVICE_OPEN_ERR_NOT_PERMISSIONS, /* Error is known not to be a permissions error */
CAP_DEVICE_OPEN_ERR_GENERIC /* Error is not known to be one or the other */
} cap_device_open_err;
CAP_DEVICE_OPEN_ERR_GENERIC, /* Error is not known to be one or the other */
CAP_DEVICE_OPEN_WARNING_GENERIC /* No error, but a warning */
} cap_device_open_status;
extern if_capabilities_t *get_if_capabilities(interface_options *interface_opts,
cap_device_open_err *err, char **err_str);
cap_device_open_status *status, char **status_str);
extern pcap_t *open_capture_device(capture_options *capture_opts,
interface_options *interface_opts,
int timeout, cap_device_open_err *open_err,
char (*open_err_str)[PCAP_ERRBUF_SIZE]);
int timeout, cap_device_open_status *open_status,
char (*open_status_str)[PCAP_ERRBUF_SIZE]);
#endif /* HAVE_LIBPCAP */

View File

@ -779,7 +779,7 @@ cant_get_if_list_error_message(const char *err_str)
if_capabilities_t *
get_if_capabilities_local(interface_options *interface_opts,
cap_device_open_err *err, char **err_str)
cap_device_open_status *status, char **status_str)
{
/*
* We're not getting capaibilities for a remote device; use
@ -788,16 +788,18 @@ get_if_capabilities_local(interface_options *interface_opts,
*/
#ifdef HAVE_PCAP_CREATE
if (p_pcap_create != NULL)
return get_if_capabilities_pcap_create(interface_opts, err, err_str);
return get_if_capabilities_pcap_create(interface_opts, status,
status_str);
#endif
return get_if_capabilities_pcap_open_live(interface_opts, err, err_str);
return get_if_capabilities_pcap_open_live(interface_opts, status,
status_str);
}
pcap_t *
open_capture_device_local(capture_options *capture_opts,
interface_options *interface_opts, int timeout,
cap_device_open_err *open_err,
char (*open_err_str)[PCAP_ERRBUF_SIZE])
cap_device_open_status *open_status,
char (*open_status_str)[PCAP_ERRBUF_SIZE])
{
/*
* We're not opening a remote device; use pcap_create() and
@ -807,10 +809,10 @@ open_capture_device_local(capture_options *capture_opts,
#ifdef HAVE_PCAP_CREATE
if (p_pcap_create != NULL)
return open_capture_device_pcap_create(capture_opts,
interface_opts, timeout, open_err, open_err_str);
interface_opts, timeout, open_status, open_status_str);
#endif
return open_capture_device_pcap_open_live(interface_opts, timeout,
open_err, open_err_str);
open_status, open_status_str);
}
/*

View File

@ -573,8 +573,8 @@ relinquish_all_capabilities(void)
#endif
static const char *
get_pcap_failure_secondary_error_message(cap_device_open_err open_err,
const char *open_err_str)
get_pcap_failure_secondary_error_message(cap_device_open_status open_status,
const char *open_status_str)
{
#ifdef _WIN32
/*
@ -596,7 +596,7 @@ get_pcap_failure_secondary_error_message(cap_device_open_err open_err,
* have platform-specific suggestions at the end (for example, suggestions
* for how to get permission to capture).
*/
if (open_err == CAP_DEVICE_OPEN_ERR_GENERIC) {
if (open_status == CAP_DEVICE_OPEN_ERR_GENERIC) {
/*
* We don't know what kind of error it is. See if there's a hint
* in the error string; if not, throw all generic suggestions at
@ -612,7 +612,7 @@ get_pcap_failure_secondary_error_message(cap_device_open_err open_err,
* from an NDIS error after the initial part, so we do a prefix
* check rather than an exact match check.)
*/
if (strncmp(open_err_str, promisc_failed, sizeof promisc_failed - 1) == 0) {
if (strncmp(open_status_str, promisc_failed, sizeof promisc_failed - 1) == 0) {
/*
* Yes. Suggest that the user turn off promiscuous mode on that
* device.
@ -625,7 +625,7 @@ get_pcap_failure_secondary_error_message(cap_device_open_err open_err,
"the proper interface or pipe specified."
PLATFORM_PERMISSIONS_SUGGESTION;
}
} else if (open_err == CAP_DEVICE_OPEN_ERR_PERMISSIONS) {
} else if (open_status == CAP_DEVICE_OPEN_ERR_PERMISSIONS) {
/*
* This is a permissions error, so no need to specify any other
* warnings.
@ -644,8 +644,8 @@ get_pcap_failure_secondary_error_message(cap_device_open_err open_err,
}
static void
get_capture_device_open_failure_messages(cap_device_open_err open_err,
const char *open_err_str,
get_capture_device_open_failure_messages(cap_device_open_status open_status,
const char *open_status_str,
const char *iface,
char *errmsg, size_t errmsg_len,
char *secondary_errmsg,
@ -653,9 +653,9 @@ get_capture_device_open_failure_messages(cap_device_open_err open_err,
{
g_snprintf(errmsg, (gulong) errmsg_len,
"The capture session could not be initiated on interface '%s' (%s).",
iface, open_err_str);
iface, open_status_str);
g_snprintf(secondary_errmsg, (gulong) secondary_errmsg_len, "%s",
get_pcap_failure_secondary_error_message(open_err, open_err_str));
get_pcap_failure_secondary_error_message(open_status, open_status_str));
}
static gboolean
@ -697,8 +697,8 @@ show_filter_code(capture_options *capture_opts)
{
interface_options *interface_opts;
pcap_t *pcap_h;
cap_device_open_err open_err;
gchar open_err_str[PCAP_ERRBUF_SIZE];
cap_device_open_status open_status;
gchar open_status_str[PCAP_ERRBUF_SIZE];
char errmsg[MSG_MAX_LENGTH+1];
char secondary_errmsg[MSG_MAX_LENGTH+1];
struct bpf_program fcode;
@ -709,10 +709,10 @@ show_filter_code(capture_options *capture_opts)
for (j = 0; j < capture_opts->ifaces->len; j++) {
interface_opts = &g_array_index(capture_opts->ifaces, interface_options, j);
pcap_h = open_capture_device(capture_opts, interface_opts,
CAP_READ_TIMEOUT, &open_err, &open_err_str);
CAP_READ_TIMEOUT, &open_status, &open_status_str);
if (pcap_h == NULL) {
/* Open failed; get messages */
get_capture_device_open_failure_messages(open_err, open_err_str,
get_capture_device_open_failure_messages(open_status, open_status_str,
interface_opts->name,
errmsg, sizeof errmsg,
secondary_errmsg,
@ -2773,8 +2773,8 @@ capture_loop_open_input(capture_options *capture_opts, loop_data *ld,
char *errmsg, size_t errmsg_len,
char *secondary_errmsg, size_t secondary_errmsg_len)
{
cap_device_open_err open_err;
gchar open_err_str[PCAP_ERRBUF_SIZE];
cap_device_open_status open_status;
gchar open_status_str[PCAP_ERRBUF_SIZE];
gchar *sync_msg_str;
interface_options *interface_opts;
capture_src *pcap_src;
@ -2831,7 +2831,7 @@ capture_loop_open_input(capture_options *capture_opts, loop_data *ld,
ws_debug("capture_loop_open_input : %s", interface_opts->name);
pcap_src->pcap_h = open_capture_device(capture_opts, interface_opts,
CAP_READ_TIMEOUT, &open_err, &open_err_str);
CAP_READ_TIMEOUT, &open_status, &open_status_str);
if (pcap_src->pcap_h != NULL) {
/* we've opened "iface" as a network device */
@ -2911,8 +2911,8 @@ capture_loop_open_input(capture_options *capture_opts, loop_data *ld,
* doesn't exist. Report the error message for
* the interface.
*/
get_capture_device_open_failure_messages(open_err,
open_err_str,
get_capture_device_open_failure_messages(open_status,
open_status_str,
interface_opts->name,
errmsg,
errmsg_len,
@ -2925,9 +2925,11 @@ capture_loop_open_input(capture_options *capture_opts, loop_data *ld,
*/
return FALSE;
} else {
/* cap_pipe_open_live() succeeded; don't want
error message from pcap_open_live() */
open_err_str[0] = '\0';
/*
* We tried opening as an interface, and that failed,
* so we tried to open it as a pipe, and that succeeded.
*/
open_status = CAP_DEVICE_OPEN_NO_ERR;
}
}
@ -2938,10 +2940,11 @@ capture_loop_open_input(capture_options *capture_opts, loop_data *ld,
}
#endif
/* Does "open_err_str" contain a non-empty string? If so, "pcap_open_live()"
returned a warning; print it, but keep capturing. */
if (open_err_str[0] != '\0') {
sync_msg_str = g_strdup_printf("%s.", open_err_str);
/* Is "open_status" something other than CAP_DEVICE_OPEN_NO_ERR?
If so, "open_capture_device()" returned a warning; print it,
but keep capturing. */
if (open_status != CAP_DEVICE_OPEN_NO_ERR) {
sync_msg_str = g_strdup_printf("%s.", open_status_str);
report_capture_error(sync_msg_str, "");
g_free(sync_msg_str);
}
@ -5424,8 +5427,8 @@ main(int argc, char *argv[])
if (caps_queries) {
/* Get the list of link-layer and/or timestamp types for the capture device. */
if_capabilities_t *caps;
cap_device_open_err err;
gchar *err_str;
cap_device_open_status open_status;
gchar *open_status_str;
guint ii;
for (ii = 0; ii < global_capture_opts.ifaces->len; ii++) {
@ -5433,23 +5436,23 @@ main(int argc, char *argv[])
interface_opts = &g_array_index(global_capture_opts.ifaces, interface_options, ii);
caps = get_if_capabilities(interface_opts, &err, &err_str);
caps = get_if_capabilities(interface_opts, &open_status, &open_status_str);
if (caps == NULL) {
if (capture_child) {
char *error_msg = g_strdup_printf("The capabilities of the capture device"
" \"%s\" could not be obtained (%s)",
interface_opts->name, err_str);
interface_opts->name, open_status_str);
sync_pipe_errmsg_to_parent(2, error_msg,
get_pcap_failure_secondary_error_message(err, err_str));
get_pcap_failure_secondary_error_message(open_status, open_status_str));
g_free(error_msg);
}
else {
cmdarg_err("The capabilities of the capture device"
"\"%s\" could not be obtained (%s).\n%s",
interface_opts->name, err_str,
get_pcap_failure_secondary_error_message(err, err_str));
interface_opts->name, open_status_str,
get_pcap_failure_secondary_error_message(open_status, open_status_str));
}
g_free(err_str);
g_free(open_status_str);
exit_main(2);
}