diff options
author | João Valverde <joao.valverde@tecnico.ulisboa.pt> | 2021-03-05 04:09:47 +0000 |
---|---|---|
committer | Wireshark GitLab Utility <gerald+gitlab-utility@wireshark.org> | 2021-03-06 12:56:11 +0000 |
commit | 41a172cc953382e4c830481dea14d895c622754e (patch) | |
tree | c5356ca4a2d622f621aefd5124e9ad3bd4cd6871 /capchild | |
parent | b5530e7021fa68c1d8e7e454b758cfea64acd6ba (diff) |
if_capabilities: Use a structured error msg from dumpcap
Have dumpcap in child mode return an error message with a primary and
secondary string, instead of using stderr. When writing to the console
log we ignore the second message to prevent flooding the log with
tutorial-like info on permissions.
Diffstat (limited to 'capchild')
-rw-r--r-- | capchild/capture_ifinfo.c | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/capchild/capture_ifinfo.c b/capchild/capture_ifinfo.c index e8f049818a..a7dc7b7649 100644 --- a/capchild/capture_ifinfo.c +++ b/capchild/capture_ifinfo.c @@ -196,7 +196,8 @@ capture_interface_list(int *err, char **err_str, void (*update_cb)(void)) if_capabilities_t * capture_get_if_capabilities(const gchar *ifname, gboolean monitor_mode, const gchar *auth_string, - char **err_str, void (*update_cb)(void)) + char **err_primary_msg, char **err_secondary_msg, + void (*update_cb)(void)) { if_capabilities_t *caps; GList *linktype_list = NULL, *timestamp_list = NULL; @@ -207,27 +208,28 @@ capture_get_if_capabilities(const gchar *ifname, gboolean monitor_mode, g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture Interface Capabilities ..."); /* see if the interface is from extcap */ - caps = extcap_get_if_dlts(ifname, err_str); + caps = extcap_get_if_dlts(ifname, err_primary_msg); if (caps != NULL) return caps; /* return if the extcap interface generated an error */ - if (err_str != NULL && *err_str != NULL) + if (err_primary_msg != NULL && *err_primary_msg != NULL) return NULL; /* Try to get our interface list */ err = sync_if_capabilities_open(ifname, monitor_mode, auth_string, &data, &primary_msg, &secondary_msg, update_cb); if (err != 0) { - g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture Interface Capabilities failed. Error %d, %s (%s)", - err, primary_msg ? primary_msg : "no message", - secondary_msg ? secondary_msg : "no secondary message"); - if (err_str) { - *err_str = primary_msg; - } else { + g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture Interface Capabilities failed. Error %d, %s", + err, primary_msg ? primary_msg : "no message"); + if (err_primary_msg) + *err_primary_msg = primary_msg; + else g_free(primary_msg); - } - g_free(secondary_msg); + if (err_secondary_msg) + *err_secondary_msg = secondary_msg; + else + g_free(secondary_msg); return NULL; } @@ -244,8 +246,8 @@ capture_get_if_capabilities(const gchar *ifname, gboolean monitor_mode, */ if (raw_list[0] == NULL || *raw_list[0] == '\0') { g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture Interface Capabilities returned no information."); - if (err_str) { - *err_str = g_strdup("Dumpcap returned no interface capability information"); + if (err_primary_msg) { + *err_primary_msg = g_strdup("Dumpcap returned no interface capability information"); } g_strfreev(raw_list); return NULL; @@ -267,8 +269,8 @@ capture_get_if_capabilities(const gchar *ifname, gboolean monitor_mode, default: g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture Interface Capabilities returned bad information."); - if (err_str) { - *err_str = g_strdup_printf("Dumpcap returned \"%s\" for monitor-mode capability", + if (err_primary_msg) { + *err_primary_msg = g_strdup_printf("Dumpcap returned \"%s\" for monitor-mode capability", raw_list[0]); } g_free(caps); @@ -323,8 +325,8 @@ capture_get_if_capabilities(const gchar *ifname, gboolean monitor_mode, /* Check to see if we built a list */ if (linktype_list == NULL) { /* No. */ - if (err_str) - *err_str = g_strdup("Dumpcap returned no link-layer types"); + if (err_primary_msg) + *err_primary_msg = g_strdup("Dumpcap returned no link-layer types"); g_free(caps); return NULL; } |