diff --git a/ui/capture_ui_utils.c b/ui/capture_ui_utils.c index 589512cbd4..1d60aed891 100644 --- a/ui/capture_ui_utils.c +++ b/ui/capture_ui_utils.c @@ -237,9 +237,17 @@ capture_dev_user_snaplen_find(const gchar *if_name, gboolean *hassnap, int *snap } gboolean -capture_dev_user_pmode_find(const gchar *if_name) +capture_dev_user_pmode_find(const gchar *if_name, gboolean *pmode) { - return (capture_dev_get_if_int_property(prefs.capture_devices_pmode, if_name) != 0); + int value; + + value = capture_dev_get_if_int_property(prefs.capture_devices_pmode, if_name); + if (value == -1) { + /* Not found or bad. */ + return FALSE; + } + *pmode = (value != 0); + return TRUE; } gchar* diff --git a/ui/capture_ui_utils.h b/ui/capture_ui_utils.h index 6146e96f43..50fb13073a 100644 --- a/ui/capture_ui_utils.h +++ b/ui/capture_ui_utils.h @@ -85,8 +85,14 @@ gboolean capture_dev_user_snaplen_find(const gchar *if_name, gboolean *hassnap, /** * Find user-specified promiscuous mode that matches interface * name, if any. + * + * @param if_name The name of the interface. + * @param pmode Pointer to a variable to be set to TRUE if promiscuous + * mode should be used and FALSE if it shouldn't be used. + * + * @return TRUE if found or FALSE if not found. */ -gboolean capture_dev_user_pmode_find(const gchar *if_name); +gboolean capture_dev_user_pmode_find(const gchar *if_name, gboolean *pmode); /** * Find user-specified capture filter that matches interface diff --git a/ui/gtk/capture_dlg.c b/ui/gtk/capture_dlg.c index f8e2601aaf..1f3469c163 100644 --- a/ui/gtk/capture_dlg.c +++ b/ui/gtk/capture_dlg.c @@ -1272,7 +1272,7 @@ insert_new_rows(GList *list) device.buffer = global_capture_opts.default_options.buffer_size; } #endif - if ((device.pmode = capture_dev_user_pmode_find(if_string)) == -1) { + if (!capture_dev_user_pmode_find(if_string, &device.pmode)) { device.pmode = global_capture_opts.default_options.promisc_mode; } if (!capture_dev_user_snaplen_find(if_string, &device.has_snaplen, @@ -5688,8 +5688,7 @@ create_and_fill_model(GtkTreeView *view) } if (!linkname) linkname = g_strdup("unknown"); - pmode = capture_dev_user_pmode_find(device.name); - if (pmode != -1) { + if (capture_dev_user_pmode_find(device.name, &pmode)) { device.pmode = pmode; } if (capture_dev_user_snaplen_find(device.name, &hassnap, &snaplen)) { diff --git a/ui/gtk/prefs_capture.c b/ui/gtk/prefs_capture.c index 738f1fa874..be9654ecb2 100644 --- a/ui/gtk/prefs_capture.c +++ b/ui/gtk/prefs_capture.c @@ -1121,6 +1121,7 @@ ifopts_edit_ifsel_cb(GtkTreeSelection *selection _U_, #endif gint snaplen; gboolean hide, hide_enabled = TRUE, hassnap = FALSE, pmode; + gboolean pmode_pref; if_capabilities_t *caps; gint selected = 0; @@ -1163,8 +1164,8 @@ ifopts_edit_ifsel_cb(GtkTreeSelection *selection _U_, if (prefs.capture_prom_mode) { gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(if_pmode_cb), TRUE); - } else if (capture_dev_user_pmode_find(if_name) != -1) { - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(if_pmode_cb), capture_dev_user_pmode_find(if_name)); + } else if (capture_dev_user_pmode_find(if_name, &pmode_pref)) { + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(if_pmode_cb), pmode_pref); } else { gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(if_pmode_cb), FALSE); } @@ -1662,9 +1663,7 @@ ifopts_options_add(GtkListStore *list_store, if_info_t *if_info) if (prefs.capture_prom_mode) { pmode = TRUE; } else { - if ((pmode = capture_dev_user_pmode_find(if_info->name)) != -1) { - pmode = capture_dev_user_pmode_find(if_info->name); - } else { + if (!capture_dev_user_pmode_find(if_info->name, &pmode)) { pmode = FALSE; } } diff --git a/ui/iface_lists.c b/ui/iface_lists.c index a78eb4c186..2756805a93 100644 --- a/ui/iface_lists.c +++ b/ui/iface_lists.c @@ -276,7 +276,7 @@ scan_local_interfaces(void (*update_cb)(void)) device.local = TRUE; device.if_info = *temp; device.last_packets = 0; - if ((device.pmode = capture_dev_user_pmode_find(if_info->name)) == -1) { + if (!capture_dev_user_pmode_find(if_info->name, &device.pmode)) { device.pmode = global_capture_opts.default_options.promisc_mode; } if (!capture_dev_user_snaplen_find(if_info->name, &device.has_snaplen, diff --git a/ui/qt/capture_interfaces_dialog.cpp b/ui/qt/capture_interfaces_dialog.cpp index 80a807458b..a51f7c5357 100644 --- a/ui/qt/capture_interfaces_dialog.cpp +++ b/ui/qt/capture_interfaces_dialog.cpp @@ -498,8 +498,7 @@ void CaptureInterfacesDialog::updateInterfaces() } } - pmode = capture_dev_user_pmode_find(device->name); - if (pmode != -1) { + if (capture_dev_user_pmode_find(device->name, &pmode)) { device->pmode = pmode; } if (capture_dev_user_snaplen_find(device->name, &hassnap, &snaplen)) {