From 358fcedabab8517c3cc6f2f843d10f513184f41b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20T=C3=BCxen?= Date: Tue, 19 Jul 2011 12:42:18 +0000 Subject: Get the interfaces list from the Capture / Interfaces list in sync when using the capture / start menu item. Obtained from Irene Ruengeler. svn path=/trunk/; revision=38109 --- gtk/capture_dlg.c | 5 ++ gtk/capture_if_dlg.c | 161 +++++++++++++++++++-------------------------------- gtk/capture_if_dlg.h | 3 + gtk/main_welcome.c | 119 ++----------------------------------- 4 files changed, 74 insertions(+), 214 deletions(-) diff --git a/gtk/capture_dlg.c b/gtk/capture_dlg.c index 8de61b6a4c..f57bc9834b 100644 --- a/gtk/capture_dlg.c +++ b/gtk/capture_dlg.c @@ -64,6 +64,7 @@ #include "gtk/gtkglobals.h" #include "gtk/capture_globals.h" #include "gtk/cfilter_combo_utils.h" +#include "gtk/capture_if_dlg.h" #ifdef _WIN32 #include "../capture-wpcap.h" @@ -2687,6 +2688,10 @@ capture_start_cb(GtkWidget *w _U_, gpointer d _U_) } #endif + if (get_interfaces_dialog_window()) { + window_destroy(get_interfaces_dialog_window()); + } + if (cap_open_w) { /* * There's an options dialog; get the values from it and close it. diff --git a/gtk/capture_if_dlg.c b/gtk/capture_if_dlg.c index c6af773f56..68aff3513c 100644 --- a/gtk/capture_if_dlg.c +++ b/gtk/capture_if_dlg.c @@ -141,15 +141,70 @@ store_selected(GtkWidget *choose_bt _U_, gpointer if_data) { if_dlg_data_t *if_dlg_data = if_data, *temp; GList *curr; - unsigned int ifs; + unsigned int ifs, i; + gboolean found; + cap_settings_t cap_settings; + interface_options interface_opts; for (ifs = 0; ifs < g_list_length(if_data_list); ifs++) { curr = g_list_nth(if_data_list, ifs); temp = (if_dlg_data_t *)(curr->data); + found = FALSE; if (strcmp(if_dlg_data->if_info.name, temp->if_info.name) == 0) { temp->selected ^=1; if_data_list = g_list_remove(if_data_list, curr->data); if_data_list = g_list_insert(if_data_list, temp, ifs); + + for (i = 0; i < global_capture_opts.ifaces->len; i++) { + if (strcmp(g_array_index(global_capture_opts.ifaces, interface_options, i).name, temp->if_info.name) == 0) { + found = TRUE; + if (!temp->selected) { + interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, i); + global_capture_opts.ifaces = g_array_remove_index(global_capture_opts.ifaces, i); + g_free(interface_opts.name); + g_free(interface_opts.descr); + g_free(interface_opts.cfilter); +#ifdef HAVE_PCAP_REMOTE + g_free(interface_opts.remote_host); + g_free(interface_opts.remote_port); + g_free(interface_opts.auth_username); + g_free(interface_opts.auth_password); +#endif + break; + } + } + } + if (!found && temp->selected) { + interface_opts.name = g_strdup(temp->if_info.name); + interface_opts.descr = get_interface_descriptive_name(interface_opts.name); + interface_opts.linktype = capture_dev_user_linktype_find(interface_opts.name); + interface_opts.cfilter = g_strdup(global_capture_opts.default_options.cfilter); + interface_opts.has_snaplen = global_capture_opts.default_options.has_snaplen; + interface_opts.snaplen = global_capture_opts.default_options.snaplen; + cap_settings = capture_get_cap_settings (interface_opts.name);; + interface_opts.promisc_mode = global_capture_opts.default_options.promisc_mode; +#if defined(_WIN32) || defined(HAVE_PCAP_CREATE) + interface_opts.buffer_size = global_capture_opts.default_options.buffer_size; +#endif + interface_opts.monitor_mode = cap_settings.monitor_mode; +#ifdef HAVE_PCAP_REMOTE + interface_opts.src_type = global_capture_opts.default_options.src_type; + interface_opts.remote_host = g_strdup(global_capture_opts.default_options.remote_host); + interface_opts.remote_port = g_strdup(global_capture_opts.default_options.remote_port); + interface_opts.auth_type = global_capture_opts.default_options.auth_type; + interface_opts.auth_username = g_strdup(global_capture_opts.default_options.auth_username); + interface_opts.auth_password = g_strdup(global_capture_opts.default_options.auth_password); + interface_opts.datatx_udp = global_capture_opts.default_options.datatx_udp; + interface_opts.nocap_rpcap = global_capture_opts.default_options.nocap_rpcap; + interface_opts.nocap_local = global_capture_opts.default_options.nocap_local; +#endif +#ifdef HAVE_PCAP_SETSAMPLING + interface_opts.sampling_method = global_capture_opts.default_options.sampling_method; + interface_opts.sampling_param = global_capture_opts.default_options.sampling_param; +#endif + g_array_append_val(global_capture_opts.ifaces, interface_opts); + } + if (temp->selected) currently_selected += 1; else @@ -178,8 +233,6 @@ capture_do_cb(GtkWidget *capture_bt _U_, gpointer if_data _U_) if_dlg_data_t *temp; GList *curr; int ifs; - interface_options interface_opts; - cap_settings_t cap_settings; #ifdef HAVE_AIRPCAP if_dlg_data_t *if_dlg_data = if_data; @@ -187,52 +240,9 @@ capture_do_cb(GtkWidget *capture_bt _U_, gpointer if_data _U_) airpcap_if_selected = airpcap_if_active; #endif - while (global_capture_opts.ifaces->len > 0) { - interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, 0); - global_capture_opts.ifaces = g_array_remove_index(global_capture_opts.ifaces, 0); - g_free(interface_opts.name); - g_free(interface_opts.descr); - g_free(interface_opts.cfilter); -#ifdef HAVE_PCAP_REMOTE - g_free(interface_opts.remote_host); - g_free(interface_opts.remote_port); - g_free(interface_opts.auth_username); - g_free(interface_opts.auth_password); -#endif - } for (ifs = 0; (curr = g_list_nth(if_data_list, ifs)); ifs++) { temp = (if_dlg_data_t *)(curr->data); - if (temp->selected ) { - interface_opts.name = g_strdup(temp->device); - interface_opts.descr = get_interface_descriptive_name(interface_opts.name); - cap_settings = capture_get_cap_settings (interface_opts.name); - interface_opts.monitor_mode = cap_settings.monitor_mode; - interface_opts.linktype = capture_dev_user_linktype_find(interface_opts.name); - interface_opts.cfilter = g_strdup(global_capture_opts.default_options.cfilter); - interface_opts.has_snaplen = global_capture_opts.default_options.has_snaplen; - interface_opts.snaplen = global_capture_opts.default_options.snaplen; - interface_opts.promisc_mode = global_capture_opts.default_options.promisc_mode; -#if defined(_WIN32) || defined(HAVE_PCAP_CREATE) - interface_opts.buffer_size = global_capture_opts.default_options.buffer_size; -#endif -#ifdef HAVE_PCAP_REMOTE - interface_opts.src_type = global_capture_opts.default_options.src_type; - interface_opts.remote_host = g_strdup(global_capture_opts.default_options.remote_host); - interface_opts.remote_port = g_strdup(global_capture_opts.default_options.remote_port); - interface_opts.auth_type = global_capture_opts.default_options.auth_type; - interface_opts.auth_username = g_strdup(global_capture_opts.default_options.auth_username); - interface_opts.auth_password = g_strdup(global_capture_opts.default_options.auth_password); - interface_opts.datatx_udp = global_capture_opts.default_options.datatx_udp; - interface_opts.nocap_rpcap = global_capture_opts.default_options.nocap_rpcap; - interface_opts.nocap_local = global_capture_opts.default_options.nocap_local; -#endif -#ifdef HAVE_PCAP_SETSAMPLING - interface_opts.sampling_method = global_capture_opts.default_options.sampling_method; - interface_opts.sampling_param = global_capture_opts.default_options.sampling_param; -#endif - g_array_append_val(global_capture_opts.ifaces, interface_opts); - } - gtk_widget_set_sensitive(temp->choose_bt, FALSE); + gtk_widget_set_sensitive(temp->choose_bt, FALSE); } /* XXX - remove this? */ @@ -255,59 +265,6 @@ capture_do_cb(GtkWidget *capture_bt _U_, gpointer if_data _U_) static void capture_prepare_cb(GtkWidget *prepare_bt _U_, gpointer if_data _U_) { - int ifs; - if_dlg_data_t *temp; - GList *curr; - interface_options interface_opts; - cap_settings_t cap_settings; - - while (global_capture_opts.ifaces->len > 0) { - interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, 0); - global_capture_opts.ifaces = g_array_remove_index(global_capture_opts.ifaces, 0); - g_free(interface_opts.name); - g_free(interface_opts.descr); - g_free(interface_opts.cfilter); -#ifdef HAVE_PCAP_REMOTE - g_free(interface_opts.remote_host); - g_free(interface_opts.remote_port); - g_free(interface_opts.auth_username); - g_free(interface_opts.auth_password); -#endif - } - - for (ifs = 0; (curr = g_list_nth(if_data_list, ifs)); ifs++) { - temp = (if_dlg_data_t *)(curr->data); - if (temp->selected ) { - interface_opts.name = g_strdup(temp->device); - interface_opts.descr = get_interface_descriptive_name(interface_opts.name); - cap_settings = capture_get_cap_settings (interface_opts.name); - interface_opts.monitor_mode = cap_settings.monitor_mode; - interface_opts.linktype = capture_dev_user_linktype_find(interface_opts.name); - interface_opts.cfilter = g_strdup(global_capture_opts.default_options.cfilter); - interface_opts.has_snaplen = global_capture_opts.default_options.has_snaplen; - interface_opts.snaplen = global_capture_opts.default_options.snaplen; - interface_opts.promisc_mode = global_capture_opts.default_options.promisc_mode; -#if defined(_WIN32) || defined(HAVE_PCAP_CREATE) - interface_opts.buffer_size = global_capture_opts.default_options.buffer_size; -#endif -#ifdef HAVE_PCAP_REMOTE - interface_opts.src_type = global_capture_opts.default_options.src_type; - interface_opts.remote_host = g_strdup(global_capture_opts.default_options.remote_host); - interface_opts.remote_port = g_strdup(global_capture_opts.default_options.remote_port); - interface_opts.auth_type = global_capture_opts.default_options.auth_type; - interface_opts.auth_username = g_strdup(global_capture_opts.default_options.auth_username); - interface_opts.auth_password = g_strdup(global_capture_opts.default_options.auth_password); - interface_opts.datatx_udp = global_capture_opts.default_options.datatx_udp; - interface_opts.nocap_rpcap = global_capture_opts.default_options.nocap_rpcap; - interface_opts.nocap_local = global_capture_opts.default_options.nocap_local; -#endif -#ifdef HAVE_PCAP_SETSAMPLING - interface_opts.sampling_method = global_capture_opts.default_options.sampling_method; - interface_opts.sampling_param = global_capture_opts.default_options.sampling_param; -#endif - g_array_append_val(global_capture_opts.ifaces, interface_opts); - } - } /* stop capturing from all interfaces, we are going to do real work now ... */ window_destroy(cap_if_w); if (global_capture_opts.ifaces->len > 1) { @@ -1038,6 +995,10 @@ capture_if_cb(GtkWidget *w _U_, gpointer d _U_) timer_id = g_timeout_add(1000, update_all, sc); } +GtkWidget* get_interfaces_dialog_window(void) +{ + return cap_if_w; +} #else /* HAVE_LIBPCAP */ void diff --git a/gtk/capture_if_dlg.h b/gtk/capture_if_dlg.h index dcf59aee06..12f5509eef 100644 --- a/gtk/capture_if_dlg.h +++ b/gtk/capture_if_dlg.h @@ -50,6 +50,9 @@ capture_if_cb(GtkWidget *widget, gpointer data); GtkWidget * capture_get_if_icon(const if_info_t* if_info); +GtkWidget * +get_interfaces_dialog_window(void); + #endif /* HAVE_LIBPCAP */ #endif /* capture_if_dlg.h */ diff --git a/gtk/main_welcome.c b/gtk/main_welcome.c index c1d19e33d0..7b181cecaa 100644 --- a/gtk/main_welcome.c +++ b/gtk/main_welcome.c @@ -888,106 +888,24 @@ welcome_if_panel_reload(void) } #ifdef HAVE_LIBPCAP -static void make_selections_array(GtkTreeModel *model, - GtkTreePath *path _U_, - GtkTreeIter *iter, - gpointer userdata _U_) +static void capture_if_start(GtkWidget *w _U_, gpointer data _U_) { - gchar *if_name; +#ifdef HAVE_AIRPCAP interface_options interface_opts; - cap_settings_t cap_settings; - GList *if_list; - GList *curr; - int err; - if_info_t *if_info; - - gtk_tree_model_get (model, iter, IFACE_NAME, &if_name, -1); - - if_list = capture_interface_list(&err, NULL); - if_list = g_list_sort (if_list, if_list_comparator_alph); - if (g_list_length(if_list) > 0) { - for (curr = g_list_first(if_list); curr; curr = g_list_next(curr)) { - if_info = curr->data; - /* Continue if capture device is hidden */ - if (prefs_is_capture_device_hidden(if_info->name)) { - continue; - } - if (strcmp(if_info->name, if_name) == 0) { - interface_opts.name = g_strdup(if_name); - interface_opts.descr = get_interface_descriptive_name(interface_opts.name); - break; - } - } - free_interface_list(if_list); - } else { - free_interface_list(if_list); - return; - } - - interface_opts.linktype = capture_dev_user_linktype_find(interface_opts.name); - interface_opts.cfilter = g_strdup(global_capture_opts.default_options.cfilter); - interface_opts.has_snaplen = global_capture_opts.default_options.has_snaplen; - interface_opts.snaplen = global_capture_opts.default_options.snaplen; - cap_settings = capture_get_cap_settings (interface_opts.name);; - interface_opts.promisc_mode = global_capture_opts.default_options.promisc_mode; -#if defined(_WIN32) || defined(HAVE_PCAP_CREATE) - interface_opts.buffer_size = global_capture_opts.default_options.buffer_size; #endif - interface_opts.monitor_mode = cap_settings.monitor_mode; -#ifdef HAVE_PCAP_REMOTE - interface_opts.src_type = global_capture_opts.default_options.src_type; - interface_opts.remote_host = g_strdup(global_capture_opts.default_options.remote_host); - interface_opts.remote_port = g_strdup(global_capture_opts.default_options.remote_port); - interface_opts.auth_type = global_capture_opts.default_options.auth_type; - interface_opts.auth_username = g_strdup(global_capture_opts.default_options.auth_username); - interface_opts.auth_password = g_strdup(global_capture_opts.default_options.auth_password); - interface_opts.datatx_udp = global_capture_opts.default_options.datatx_udp; - interface_opts.nocap_rpcap = global_capture_opts.default_options.nocap_rpcap; - interface_opts.nocap_local = global_capture_opts.default_options.nocap_local; -#endif -#ifdef HAVE_PCAP_SETSAMPLING - interface_opts.sampling_method = global_capture_opts.default_options.sampling_method; - interface_opts.sampling_param = global_capture_opts.default_options.sampling_param; -#endif - g_array_append_val(global_capture_opts.ifaces, interface_opts); -} -static void capture_if_start(GtkWidget *w _U_, gpointer data _U_) -{ - GtkTreeSelection *entry; - GtkWidget* view; - gint len; - interface_options interface_opts; - - view = g_object_get_data(G_OBJECT(welcome_hb), TREE_VIEW_INTERFACES); - entry = gtk_tree_view_get_selection(GTK_TREE_VIEW(view)); - len = gtk_tree_selection_count_selected_rows(entry); - if (!entry || len == 0) { + if (global_capture_opts.ifaces->len == 0) { simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "You didn't specify an interface on which to capture packets."); return; } #ifndef USE_THREADS - if (len > 1) { + if (global_capture_opts.ifaces->len > 1) { simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "You specified multiple interfaces for capturing which this version of Wireshark doesn't support."); return; } #endif - while (global_capture_opts.ifaces->len > 0) { - interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, 0); - global_capture_opts.ifaces = g_array_remove_index(global_capture_opts.ifaces, 0); - g_free(interface_opts.name); - g_free(interface_opts.descr); - g_free(interface_opts.cfilter); -#ifdef HAVE_PCAP_REMOTE - g_free(interface_opts.remote_host); - g_free(interface_opts.remote_port); - g_free(interface_opts.auth_username); - g_free(interface_opts.auth_password); -#endif - } - gtk_tree_selection_selected_foreach(entry, make_selections_array, NULL); /* XXX - remove this? */ if (global_capture_opts.save_file) { @@ -1002,33 +920,6 @@ static void capture_if_start(GtkWidget *w _U_, gpointer data _U_) #endif capture_start_cb(NULL, NULL); } - -void capture_if_cb_prep(GtkWidget *w _U_, gpointer d _U_) -{ - GtkTreeSelection *entry; - GtkWidget* view; - - view = g_object_get_data(G_OBJECT(welcome_hb), TREE_VIEW_INTERFACES); - entry = gtk_tree_view_get_selection(GTK_TREE_VIEW(view)); - if (entry) { - /* global_capture_opts.number_of_ifaces = gtk_tree_selection_count_selected_rows(entry);*/ - gtk_tree_selection_selected_foreach(entry, make_selections_array, NULL); - } - capture_if_cb(NULL, NULL); -} - -void capture_opts_cb_prep(GtkWidget *w _U_, gpointer d _U_) -{ - GtkTreeSelection *entry; - GtkWidget* view; - - view = g_object_get_data(G_OBJECT(welcome_hb), TREE_VIEW_INTERFACES); - entry = gtk_tree_view_get_selection(GTK_TREE_VIEW(view)); - if (entry) { - gtk_tree_selection_selected_foreach(entry, make_selections_array, NULL); - } - capture_prep_cb(NULL, NULL); -} #endif /* create the welcome page */ @@ -1114,7 +1005,7 @@ welcome_new(void) "Interface List", "Live list of the capture interfaces\n(counts incoming packets)", "Same as Capture/Interfaces menu or toolbar item", - welcome_button_callback_helper, capture_if_cb_prep); + welcome_button_callback_helper, capture_if_cb); gtk_box_pack_start(GTK_BOX(topic_to_fill), item_hb, FALSE, FALSE, 5); swindow = gtk_scrolled_window_new (NULL, NULL); -- cgit v1.2.3