From 92a2661d949b1fed78affd87c6e80b537ce49dfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stig=20Bj=C3=B8rlykke?= Date: Wed, 2 Dec 2015 09:13:40 +0100 Subject: [PATCH] ui: Update interfaces when when changing profile. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The interfaces preferences are different for each profile so ensure we update the interface settings when changing profile. This bug was introduced in version 1.8.0. Change-Id: Icf22670875e01bab6204c300ddc7fb8aeb3dcecf Reviewed-on: https://code.wireshark.org/review/12363 Petri-Dish: Stig Bjørlykke Tested-by: Petri Dish Buildbot Reviewed-by: Stig Bjørlykke --- ui/gtk/main.c | 1 + ui/iface_lists.c | 71 +++++++++++++++++++++++---------- ui/iface_lists.h | 9 +++++ ui/qt/wireshark_application.cpp | 2 + 4 files changed, 62 insertions(+), 21 deletions(-) diff --git a/ui/gtk/main.c b/ui/gtk/main.c index 08e308e204..69d9d9a81a 100644 --- a/ui/gtk/main.c +++ b/ui/gtk/main.c @@ -3936,6 +3936,7 @@ void change_configuration_profile (const gchar *profile_name) prefs_to_capture_opts(); prefs_apply_all(); + update_local_interfaces(); macros_post_update(); /* Update window view and redraw the toolbar */ diff --git a/ui/iface_lists.c b/ui/iface_lists.c index bd8dd4a905..be9c8bfaf1 100644 --- a/ui/iface_lists.c +++ b/ui/iface_lists.c @@ -54,6 +54,33 @@ if_list_comparator_alph(const void *first_arg, const void *second_arg) } } +static void +fill_from_ifaces (interface_t *device) +{ + interface_options interface_opts; + guint i; + + for (i = 0; i < global_capture_opts.ifaces->len; i++) { + interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, i); + if (strcmp(interface_opts.name, device->name) != 0) { + continue; + } + +#if defined(HAVE_PCAP_CREATE) + device->buffer = interface_opts.buffer_size; + device->monitor_mode_enabled = interface_opts.monitor_mode; +#endif + device->pmode = interface_opts.promisc_mode; + device->has_snaplen = interface_opts.has_snaplen; + device->snaplen = interface_opts.snaplen; + device->cfilter = g_strdup(interface_opts.cfilter); + if (interface_opts.linktype != -1) { + device->active_dlt = interface_opts.linktype; + } + return; + } +} + /* * Fetch the list of local interfaces with capture_interface_list() * and set the list of "all interfaces" in *capture_opts to include @@ -257,27 +284,7 @@ scan_local_interfaces(void (*update_cb)(void)) } #endif - if (global_capture_opts.ifaces->len > 0) { - for (j = 0; j < global_capture_opts.ifaces->len; j++) { - interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, j); - if (strcmp(interface_opts.name, device.name) == 0) { -#if defined(HAVE_PCAP_CREATE) - device.buffer = interface_opts.buffer_size; - device.monitor_mode_enabled = interface_opts.monitor_mode; -#endif - device.pmode = interface_opts.promisc_mode; - device.has_snaplen = interface_opts.has_snaplen; - device.snaplen = interface_opts.snaplen; - device.cfilter = g_strdup(interface_opts.cfilter); - if (interface_opts.linktype != -1) { - device.active_dlt = interface_opts.linktype; - } - device.selected = TRUE; - global_capture_opts.num_selected++; - break; - } - } - } + fill_from_ifaces(&device); #ifdef HAVE_EXTCAP /* Extcap devices start with no cached args */ @@ -415,6 +422,28 @@ hide_interface(gchar* new_hide) g_list_free(hidden_devices); g_free(new_hide); } + +void +update_local_interfaces(void) +{ + interface_t device; + gchar *descr; + guint i; + + for (i = 0; i < global_capture_opts.all_ifaces->len; i++) { + device = g_array_index(global_capture_opts.all_ifaces, interface_t, i); + device.type = capture_dev_user_linktype_find(device.name); + g_free (device.display_name); + descr = capture_dev_user_descr_find(device.name); + device.display_name = get_iface_display_name(descr, &device.if_info); + g_free (descr); + device.hidden = prefs_is_capture_device_hidden(device.name); + fill_from_ifaces(&device); + + global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, i); + g_array_insert_val(global_capture_opts.all_ifaces, i, device); + } +} #endif /* HAVE_LIBPCAP */ /* diff --git a/ui/iface_lists.h b/ui/iface_lists.h index 125be9981b..0c40f02f17 100644 --- a/ui/iface_lists.h +++ b/ui/iface_lists.h @@ -46,7 +46,16 @@ extern void fill_in_local_interfaces(void(*update_cb)(void)); */ extern void scan_local_interfaces(void (*update_cb)(void)); +/* + * Hide the interfaces + */ extern void hide_interface(gchar* new_hide); + +/* + * Update the global interface list from preferences. + */ +extern void update_local_interfaces(void); + #endif /* HAVE_LIBPCAP */ #ifdef __cplusplus diff --git a/ui/qt/wireshark_application.cpp b/ui/qt/wireshark_application.cpp index 25f10fca14..a2b985506d 100644 --- a/ui/qt/wireshark_application.cpp +++ b/ui/qt/wireshark_application.cpp @@ -372,6 +372,7 @@ void WiresharkApplication::setConfigurationProfile(const gchar *profile_name) prefs_to_capture_opts(); prefs_apply_all(); + update_local_interfaces(); emit columnsChanged(); emit preferencesChanged(); @@ -389,6 +390,7 @@ void WiresharkApplication::setConfigurationProfile(const gchar *profile_name) /* Reload color filters */ color_filters_reload(); + emit localInterfaceListChanged(); emit packetDissectionChanged(); // user_font_apply();