2 * Routines for the capture interface dialog
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
33 #include <epan/prefs.h>
34 #include <epan/to_str.h>
36 #include "../capture_opts.h"
37 #include "../capture_session.h"
38 #include "../capture_ifinfo.h"
39 #include "../capture.h"
40 #include "../capture-pcap-util.h"
41 #include "../capture_ui_utils.h"
42 #include "wsutil/file_util.h"
43 #include <wiretap/wtap.h>
45 #include "ui/capture_globals.h"
46 #include "ui/recent.h"
47 #include "ui/simple_dialog.h"
50 #include "ui/gtk/capture_if_details_dlg_win32.h"
51 #include "../../capture-wpcap.h"
54 #include "ui/gtk/stock_icons.h"
55 #include "ui/gtk/capture_dlg.h"
56 #include "ui/gtk/capture_if_dlg.h"
57 #include "ui/gtk/gui_utils.h"
58 #include "ui/gtk/dlg_utils.h"
59 #include "ui/gtk/main.h"
60 #include "ui/gtk/main_toolbar.h"
61 #include "ui/gtk/help_dlg.h"
62 #include "ui/gtk/keys.h"
63 #include "ui/gtk/webbrowser.h"
64 #include "ui/gtk/network_icons.h"
65 #include "ui/gtk/pipe_icon.h"
66 #include "ui/gtk/main_welcome.h"
68 #include "ui/gtk/old-gtk-compat.h"
71 #include "../../image/toolbar/capture_airpcap_16.xpm"
74 #if defined(HAVE_PCAP_REMOTE)
75 #include "ui/gtk/remote_icons.h"
78 #include "../../image/toolbar/modem_16.xpm"
80 #include "../../image/toolbar/network_virtual_16.xpm"
82 /* new buttons to be used instead of labels for 'Capture','Prepare',' */
83 /*#include "../../image/toolbar/capture_capture_16.xpm"*/
84 /*#include "../../image/toolbar/capture_prepare_16.xpm"*/
85 /*#include "../../image/toolbar/capture_details_16.xpm"*/
90 #include "airpcap_loader.h"
91 #include "airpcap_gui_utils.h"
92 #include "airpcap_dlg.h"
95 #define CAPTURE_IF_IP_ADDR_LABEL "capture_if_ip_addr_label"
96 #define CAPTURE_IF_SELECTED_IP_ADDR "capture_if_selected_ip_addr"
97 #define SOFT_LABEL_LEN 50
100 * Keep a static pointer to the current "Capture Interfaces" window, if
101 * any, so that if somebody tries to do "Capture:Start" while there's
102 * already a "Capture Interfaces" window up, we just pop up the existing
103 * one, rather than creating a new one.
105 static GtkWidget *cap_if_w;
107 static guint timer_id;
109 static GtkWidget *close_bt, *stop_bt, *capture_bt, *options_bt;
111 static GArray *if_array;
113 static if_stat_cache_t *sc;
114 static GtkWidget *cap_if_top_vb, *cap_if_sw;
117 * Timeout, in milliseconds, for reads from the stream of captured packets.
119 #define CAP_READ_TIMEOUT 250
122 /* the "runtime" data of one interface */
123 typedef struct if_dlg_data_s {
125 GtkWidget *device_lb;
130 GtkWidget *choose_bt;
132 GtkWidget *details_bt;
137 static gboolean gbl_capture_in_progress = FALSE;
145 data.device_lb = NULL;
146 data.descr_lb = NULL;
150 data.choose_bt = NULL;
152 data.details_bt = NULL;
155 g_array_append_val(if_array, data);
161 update_selected_interface(gchar *name)
167 for (i = 0; i < global_capture_opts.all_ifaces->len; i++) {
168 device = g_array_index(global_capture_opts.all_ifaces, interface_t, i);
169 data = g_array_index(if_array, if_dlg_data_t, i);
170 if (strcmp(name, device.name) == 0) {
171 gtk_toggle_button_set_active((GtkToggleButton *)data.choose_bt, device.selected);
178 store_selected(GtkWidget *choose_bt, gpointer name)
183 for (i = 0; i < global_capture_opts.all_ifaces->len; i++) {
184 device = g_array_index(global_capture_opts.all_ifaces, interface_t, i);
185 if (strcmp((char *)name, device.if_info.name) == 0) {
186 if (!device.locked) {
187 device.selected ^= 1;
188 if (device.selected) {
189 global_capture_opts.num_selected++;
191 global_capture_opts.num_selected--;
193 global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, i);
194 g_array_insert_val(global_capture_opts.all_ifaces, i, device);
195 if (gtk_widget_is_focus(choose_bt) && get_welcome_window()) {
196 change_interface_selection(device.name, device.selected);
198 if (gtk_widget_is_focus(choose_bt) && capture_dlg_window_present()) {
199 enable_selected_interface(device.name, device.selected);
201 device.locked = FALSE;
202 global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, i);
203 g_array_insert_val(global_capture_opts.all_ifaces, i, device);
209 gtk_widget_set_sensitive(capture_bt, !gbl_capture_in_progress && (global_capture_opts.num_selected > 0));
213 /* start capture button was pressed */
215 capture_do_cb(GtkWidget *capture_bt_arg _U_, gpointer if_data _U_)
220 for (ifs = 0; ifs < if_array->len; ifs++) {
221 data = g_array_index(if_array, if_dlg_data_t, ifs);
225 gtk_widget_set_sensitive(data.choose_bt, FALSE);
226 if_array = g_array_remove_index(if_array, ifs);
227 g_array_insert_val(if_array, ifs, data);
229 airpcap_if_active = get_airpcap_if_from_name(airpcap_if_list, gtk_label_get_text(GTK_LABEL(data.device_lb)));
230 airpcap_if_selected = airpcap_if_active;
234 /* XXX - remove this? */
235 if (global_capture_opts.save_file) {
236 g_free(global_capture_opts.save_file);
237 global_capture_opts.save_file = NULL;
240 if (global_capture_opts.ifaces->len > 1) {
241 global_capture_opts.use_pcapng = TRUE;
243 /* stop capturing from all interfaces, we are going to do real work now ... */
244 window_destroy(cap_if_w);
246 capture_start_cb(NULL, NULL);
250 /* prepare capture button was pressed */
252 capture_prepare_cb(GtkWidget *prepare_bt _U_, gpointer if_data _U_)
254 /* stop capturing from all interfaces, we are going to do real work now ... */
255 window_destroy(cap_if_w);
256 if (global_capture_opts.ifaces->len > 1) {
257 global_capture_opts.use_pcapng = TRUE;
259 capture_prep_cb(NULL, NULL);
264 /* capture details button was pressed */
266 capture_details_cb(GtkWidget *details_bt _U_, gpointer name)
268 capture_if_details_open(name);
272 /* update a single interface */
274 update_if(gchar *name, if_stat_cache_t *sc_p)
276 struct pcap_stat stats;
278 guint diff, ifs, data_ifs;
281 gboolean found = FALSE;
285 * Note that some versions of libpcap, on some versions of UN*X,
286 * pcap_stats() returns the number of packets since the last
289 * That's a bug, and should be fixed; "pcap_stats()" is supposed
290 * to work the same way on all platforms.
292 device.last_packets = 0;
296 for (ifs = 0, data_ifs = 0; ifs < global_capture_opts.all_ifaces->len; ifs++) {
297 device = g_array_index(global_capture_opts.all_ifaces, interface_t, ifs);
298 if (device.type != IF_PIPE) {
299 data = g_array_index(if_array, if_dlg_data_t, data_ifs++);
300 if (!device.hidden && strcmp(name, device.name) == 0) {
307 if (capture_stats(sc_p, name, &stats)) {
308 if ((int)(stats.ps_recv - device.last_packets) < 0) {
311 diff = stats.ps_recv - device.last_packets;
313 device.last_packets = stats.ps_recv;
315 str = g_strdup_printf("%u", device.last_packets);
316 gtk_label_set_text(GTK_LABEL(data.curr_lb), str);
318 str = g_strdup_printf("%u", diff);
319 gtk_label_set_text(GTK_LABEL(data.last_lb), str);
322 gtk_widget_set_sensitive(data.curr_lb, diff);
323 gtk_widget_set_sensitive(data.last_lb, diff);
325 gtk_label_set_text(GTK_LABEL(data.curr_lb), "error");
326 gtk_label_set_text(GTK_LABEL(data.last_lb), "error");
328 global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, ifs);
329 g_array_insert_val(global_capture_opts.all_ifaces, ifs, device);
330 if_array = g_array_remove_index(if_array, ifs);
331 g_array_insert_val(if_array, ifs, data);
336 /* update all interfaces */
338 update_all(gpointer data)
342 if_stat_cache_t *sc_p = (if_stat_cache_t *)data;
348 for (ifs = 0; ifs < global_capture_opts.all_ifaces->len; ifs++) {
349 device = g_array_index(global_capture_opts.all_ifaces, interface_t, ifs);
350 update_if(device.name, sc_p);
356 /* a live capture has started or stopped */
358 set_capture_if_dialog_for_capture_in_progress(gboolean capture_in_progress)
360 gbl_capture_in_progress = capture_in_progress;
362 gtk_widget_set_sensitive(stop_bt, capture_in_progress);
363 gtk_widget_set_sensitive(capture_bt, !capture_in_progress && (global_capture_opts.num_selected > 0));
367 /* a live capture is being stopped */
369 set_capture_if_dialog_for_capture_stopping(void)
372 gtk_widget_set_sensitive(stop_bt, FALSE);
377 /* the window was closed, cleanup things */
379 capture_if_destroy_cb(GtkWidget *win _U_, gpointer user_data _U_)
381 g_source_remove(timer_id);
384 capture_stat_stop(sc);
387 window_destroy(GTK_WIDGET(cap_if_w));
388 /* Note that we no longer have a "Capture Options" dialog box. */
390 cap_if_top_vb = NULL;
393 if (airpcap_if_active)
394 airpcap_set_toolbar_stop_capture(airpcap_if_active);
400 * Used to retrieve the interface icon.
402 GtkWidget * capture_get_if_icon(interface_t *device)
404 #ifdef HAVE_PCAP_REMOTE
405 if (!device->local) {
406 return pixbuf_to_widget(remote_sat_pb_data);
409 if (device->display_name && strstr(device->display_name,"Wi-Fi") != NULL) {
410 return pixbuf_to_widget(network_wireless_pb_data);
412 switch (device->type) {
414 return xpm_to_widget(modem_16_xpm);
416 return pixbuf_to_widget(network_wireless_pb_data);
419 return xpm_to_widget(capture_airpcap_16_xpm);
422 return pixbuf_to_widget(network_bluetooth_pb_data);
424 return pixbuf_to_widget(network_usb_pb_data);
426 return xpm_to_widget(network_virtual_16_xpm);
428 return pixbuf_to_widget(network_wired_pb_data);
431 return pixbuf_to_widget(pipe_pb_data);
433 printf("unknown device type\n");
435 return pixbuf_to_widget(network_wired_pb_data);
440 get_ip_addr_count(GSList *addr_list)
447 for (curr_addr = addr_list; curr_addr != NULL;
448 curr_addr = g_slist_next(curr_addr)) {
449 addr = (if_addr_t *)curr_addr->data;
450 switch (addr->ifat_type) {
458 /* In case we add non-IP addresses */
466 set_ip_addr_label(GSList *addr_list, GtkWidget *ip_lb, guint selected_ip_addr)
470 const gchar *addr_str = NULL;
472 curr_addr = g_slist_nth(addr_list, selected_ip_addr);
474 addr = (if_addr_t *)curr_addr->data;
475 switch (addr->ifat_type) {
478 addr_str = ip_to_str((guint8 *)&addr->addr.ip4_addr);
482 addr_str = ip6_to_str((struct e_in6_addr *)&addr->addr.ip6_addr);
486 /* Ignore non-IP addresses, in case we ever support them */
492 gtk_label_set_text(GTK_LABEL(ip_lb), addr_str);
494 gtk_label_set_text(GTK_LABEL(ip_lb), "none");
496 g_object_set_data(G_OBJECT(ip_lb), CAPTURE_IF_SELECTED_IP_ADDR, GINT_TO_POINTER(selected_ip_addr));
503 ip_label_enter_cb(GtkWidget *eb, GdkEventCrossing *event _U_, gpointer user_data _U_)
505 gtk_widget_set_state(eb, GTK_STATE_PRELIGHT);
512 ip_label_leave_cb(GtkWidget *eb, GdkEvent *event _U_, gpointer user_data _U_)
514 gtk_widget_set_state(eb, GTK_STATE_NORMAL);
521 ip_label_press_cb(GtkWidget *widget, GdkEvent *event _U_, gpointer data)
523 GtkWidget *ip_lb = (GtkWidget *)g_object_get_data(G_OBJECT(widget), CAPTURE_IF_IP_ADDR_LABEL);
524 GSList *addr_list = (GSList *)data;
525 GSList *curr_addr, *start_addr;
527 guint selected_ip_addr = GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(ip_lb), CAPTURE_IF_SELECTED_IP_ADDR));
529 /* Select next IP address */
530 start_addr = g_slist_nth(addr_list, selected_ip_addr);
533 if (g_slist_length(addr_list) <= selected_ip_addr) {
535 selected_ip_addr = 0;
537 curr_addr = g_slist_nth(addr_list, selected_ip_addr);
538 if (curr_addr == start_addr) {
539 /* We wrapped all the way around */
543 addr = (if_addr_t *)curr_addr->data;
544 switch (addr->ifat_type) {
551 /* In case we add non-IP addresses */
557 set_ip_addr_label(addr_list, ip_lb, selected_ip_addr);
563 capture_if_stop_cb(GtkWidget *w _U_, gpointer d _U_)
568 for (ifs = 0; ifs < if_array->len; ifs++) {
569 data = g_array_index(if_array, if_dlg_data_t, ifs);
573 gtk_widget_set_sensitive(data.choose_bt, TRUE);
574 if_array = g_array_remove_index(if_array, ifs);
575 g_array_insert_val(if_array, ifs, data);
577 capture_stop_cb(NULL, NULL);
586 if_array = g_array_new(FALSE, FALSE, sizeof(if_dlg_data_t));
588 for (i = 0; i < global_capture_opts.all_ifaces->len; i++) {
589 data.device_lb = NULL;
590 data.descr_lb = NULL;
594 data.choose_bt = NULL;
596 data.details_bt = NULL;
599 g_array_append_val(if_array, data);
604 * If this is Windows, is WinPcap loaded? If not, pop up a dialog noting
605 * that fact and return FALSE, as we can't capture traffic.
607 * Otherwise (not Windows or WinPcap loaded), are there any interfaces?
608 * If not, pop up a dialog noting that fact and return FALSE, as there
609 * are no interfaces on which to capture traffic.
611 * Otherwise, return TRUE, as we can capture.
617 /* Is WPcap loaded? */
621 detailed_err = cant_load_winpcap_err("Wireshark");
622 simple_error_message_box("%s", detailed_err);
623 g_free(detailed_err);
628 if (global_capture_opts.all_ifaces->len == 0) {
629 simple_error_message_box("There are no interfaces on which a capture can be done.");
637 capture_if_refresh_if_list(void)
639 GtkWidget *if_vb, *if_grid, *icon, *if_lb, *eb;
640 GtkRequisition requisition;
641 int row = 0, height = 0;
644 const gchar *addr_str;
648 if (!can_capture()) {
649 /* No interfaces or, on Windows, no WinPcap; we've already popped
650 up a message, so just get rid of the interface dialog. */
656 /* First, get rid of the old interface list, and stop updating
657 the statistics on it. */
658 gtk_container_remove(GTK_CONTAINER(cap_if_top_vb), cap_if_sw);
659 capture_stat_stop(sc);
660 g_source_remove(timer_id);
663 /* Now construct the new interface list, and start updating the
668 cap_if_sw = gtk_scrolled_window_new(NULL, NULL);
669 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(cap_if_sw), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
670 gtk_box_pack_start(GTK_BOX(cap_if_top_vb), cap_if_sw, TRUE, TRUE, 0);
672 if_vb = gtk_alignment_new(0.0F, 0.0F, 1.0F, 0.0F);
673 gtk_container_set_border_width(GTK_CONTAINER(if_vb), 5);
674 #if ! GTK_CHECK_VERSION(3,8,0)
675 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(cap_if_sw), if_vb);
677 gtk_container_add(GTK_CONTAINER(cap_if_sw), if_vb);
680 if_grid = ws_gtk_grid_new();
681 ws_gtk_grid_set_row_spacing(GTK_GRID(if_grid), 3);
682 ws_gtk_grid_set_column_spacing(GTK_GRID(if_grid), 3);
683 gtk_container_add(GTK_CONTAINER(if_vb), if_grid);
685 /* This is the icon column, used to display which kind of interface we have */
686 if_lb = gtk_label_new("");
687 ws_gtk_grid_attach_extended(GTK_GRID(if_grid), if_lb, 0, row, 1, 1,
688 (GtkAttachOptions)0, (GtkAttachOptions)0, 0, 0);
690 if_lb = gtk_label_new("Device");
691 ws_gtk_grid_attach_defaults(GTK_GRID(if_grid), if_lb, 1, row, 3, 1);
693 if_lb = gtk_label_new("Description");
694 ws_gtk_grid_attach_defaults(GTK_GRID(if_grid), if_lb, 4, row, 1, 1);
696 if_lb = gtk_label_new(" IP ");
697 ws_gtk_grid_attach_extended(GTK_GRID(if_grid), if_lb, 5, row, 1, 1,
698 (GtkAttachOptions)0, (GtkAttachOptions)0, 0, 0);
700 if_lb = gtk_label_new("Packets");
701 ws_gtk_grid_attach_extended(GTK_GRID(if_grid), if_lb, 6, row, 1, 1,
702 (GtkAttachOptions)0, (GtkAttachOptions)0, 0, 0);
704 if_lb = gtk_label_new(" Packets/s ");
705 ws_gtk_grid_attach_extended(GTK_GRID(if_grid), if_lb, 7, row, 1, 1,
706 (GtkAttachOptions)0, (GtkAttachOptions)0, 0, 0);
710 /* Start gathering statistics (using dumpcap) */
711 sc = capture_stat_start(&global_capture_opts);
713 /* List the interfaces */
714 for (ifs = 0; ifs < global_capture_opts.all_ifaces->len; ifs++) {
715 device = g_array_index(global_capture_opts.all_ifaces, interface_t, ifs);
716 data = g_array_index(if_array, if_dlg_data_t, ifs);
717 /* Continue if capture device is hidden */
720 if_array = g_array_remove_index(if_array, ifs);
721 g_array_insert_val(if_array, ifs, data);
724 data.choose_bt = gtk_check_button_new();
725 ws_gtk_grid_attach_extended(GTK_GRID(if_grid), data.choose_bt, 0, row, 1, 1,
726 (GtkAttachOptions)0, (GtkAttachOptions)0, 0, 0);
727 if (gbl_capture_in_progress) {
728 gtk_widget_set_sensitive(data.choose_bt, FALSE);
730 gtk_widget_set_sensitive(data.choose_bt, TRUE);
732 gtk_toggle_button_set_active((GtkToggleButton *)data.choose_bt, device.selected);
733 g_signal_connect(data.choose_bt, "toggled", G_CALLBACK(store_selected), device.name);
734 /* Kind of adaptor (icon) */
735 icon = capture_get_if_icon(&(device));
736 ws_gtk_grid_attach_extended(GTK_GRID(if_grid), icon, 1, row, 1, 1,
737 (GtkAttachOptions)0, (GtkAttachOptions)0, 0, 0);
742 * On Windows, device names are generally not meaningful - NT 5
743 * uses long blobs with GUIDs in them, for example - so instead we use
744 * the display name which should match that shown in ncpa.cpl
746 data.device_lb = gtk_label_new(device.display_name);
748 data.device_lb = gtk_label_new(device.name);
750 gtk_misc_set_alignment(GTK_MISC(data.device_lb), 0.0f, 0.5f);
751 if (strlen(gtk_label_get_text(GTK_LABEL(data.device_lb))) > SOFT_LABEL_LEN) {
752 gtk_label_set_ellipsize(GTK_LABEL(data.device_lb), PANGO_ELLIPSIZE_MIDDLE);
753 gtk_label_set_width_chars(GTK_LABEL(data.device_lb), SOFT_LABEL_LEN);
755 ws_gtk_grid_attach_defaults(GTK_GRID(if_grid), data.device_lb, 2, row, 2, 1);
758 user_descr = capture_dev_user_descr_find(device.name);
760 data.descr_lb = gtk_label_new(user_descr);
763 if (device.if_info.vendor_description)
764 data.descr_lb = gtk_label_new(device.if_info.vendor_description);
766 data.descr_lb = gtk_label_new("");
768 gtk_misc_set_alignment(GTK_MISC(data.descr_lb), 0.0f, 0.5f);
769 if (strlen(gtk_label_get_text(GTK_LABEL(data.descr_lb))) > SOFT_LABEL_LEN) {
770 gtk_label_set_ellipsize(GTK_LABEL(data.descr_lb), PANGO_ELLIPSIZE_MIDDLE);
771 gtk_label_set_width_chars(GTK_LABEL(data.descr_lb), SOFT_LABEL_LEN);
773 ws_gtk_grid_attach_defaults(GTK_GRID(if_grid), data.descr_lb, 4, row, 1, 1);
776 /* Only one IP address will be shown, start with the first */
777 data.ip_lb = gtk_label_new("");
778 addr_str = set_ip_addr_label (device.if_info.addrs, data.ip_lb, 0);
780 gtk_widget_set_sensitive(data.ip_lb, TRUE);
782 gtk_widget_set_sensitive(data.ip_lb, FALSE);
784 eb = gtk_event_box_new ();
785 gtk_container_add(GTK_CONTAINER(eb), data.ip_lb);
786 ws_gtk_grid_attach_extended(GTK_GRID(if_grid), eb, 5, row, 1, 1,
787 (GtkAttachOptions)0, (GtkAttachOptions)0, 0, 0);
788 if (get_ip_addr_count(device.if_info.addrs) > 1) {
789 /* More than one IP address, make it possible to toggle */
790 g_object_set_data(G_OBJECT(eb), CAPTURE_IF_IP_ADDR_LABEL, data.ip_lb);
791 gtk_widget_set_tooltip_text(eb, "Click to see additional IP addresses");
792 g_signal_connect(eb, "enter-notify-event", G_CALLBACK(ip_label_enter_cb), NULL);
793 g_signal_connect(eb, "leave-notify-event", G_CALLBACK(ip_label_leave_cb), NULL);
794 g_signal_connect(eb, "button-press-event", G_CALLBACK(ip_label_press_cb), device.if_info.addrs);
798 data.curr_lb = gtk_label_new("-");
799 ws_gtk_grid_attach_extended(GTK_GRID(if_grid), data.curr_lb, 6, row, 1, 1,
800 (GtkAttachOptions)0, (GtkAttachOptions)0, 0, 0);
803 data.last_lb = gtk_label_new("-");
804 ws_gtk_grid_attach_extended(GTK_GRID(if_grid), data.last_lb, 7, row, 1, 1,
805 (GtkAttachOptions)0, (GtkAttachOptions)0, 0, 0);
809 data.details_bt = gtk_button_new_from_stock(WIRESHARK_STOCK_CAPTURE_DETAILS);
810 gtk_widget_set_tooltip_text(data.details_bt, "Open the capture details dialog of this interface.");
811 ws_gtk_grid_attach_extended(GTK_GRID(if_grid), data.details_bt, 8, row, 1, 1, 0, 0, 0, 0);
812 if (capture_if_has_details(device.name)) {
813 g_signal_connect(data.details_bt, "clicked", G_CALLBACK(capture_details_cb), device.name);
815 gtk_widget_set_sensitive(data.details_bt, FALSE);
818 if_array = g_array_remove_index(if_array, ifs);
819 g_array_insert_val(if_array, ifs, data);
823 /* Add up to 20 rows of interfaces, otherwise the window may become too high */
825 gtk_widget_get_preferred_size(GTK_WIDGET(data.details_bt), &requisition, NULL);
827 gtk_widget_get_preferred_size(GTK_WIDGET(data.choose_bt), &requisition, NULL);
829 height += requisition.height;
833 gtk_widget_get_preferred_size(GTK_WIDGET(close_bt), &requisition, NULL);
834 /* height + static offset + grid spacing */
835 height += requisition.height + 40 + (row * 3);
837 gtk_window_set_default_size(GTK_WINDOW(cap_if_w), -1, height);
839 gtk_widget_show_all(cap_if_w);
841 /* update the interface list every 1000ms */
842 timer_id = g_timeout_add(1000, update_all, sc);
845 /* start getting capture stats from all interfaces */
847 capture_if_cb(GtkWidget *w _U_, gpointer d _U_)
852 GtkWidget *decryption_cb;
855 if (cap_if_w != NULL) {
856 /* There's already a "Capture Interfaces" dialog box; reactivate it. */
857 reactivate_window(cap_if_w);
861 if (!can_capture()) {
862 /* No interfaces or, on Windows, no WinPcap; just give up. */
867 /* LOAD AIRPCAP INTERFACES */
869 /* If no airpcap interface is present, gray everything */
870 if (airpcap_if_active == NULL) {
871 if (airpcap_if_list == NULL) {
872 /*No airpcap device found */
873 airpcap_enable_toolbar_widgets(wireless_tb,FALSE);
875 /* default adapter is not airpcap... or is airpcap but is not found*/
876 if (airpcap_if_active){
877 /* XXX can never happen? */
878 airpcap_set_toolbar_stop_capture(airpcap_if_active);
880 airpcap_enable_toolbar_widgets(wireless_tb,FALSE);
883 if (airpcap_if_active){
884 decryption_cb = (GtkWidget *)g_object_get_data(G_OBJECT(wireless_tb),AIRPCAP_TOOLBAR_DECRYPTION_KEY);
885 /* XXXX update_decryption_mode_list() trigers a rescan, should only be done if the mode is changed */
886 update_decryption_mode_list(decryption_cb);
887 airpcap_set_toolbar_start_capture(airpcap_if_active);
891 cap_if_w = dlg_window_new("Wireshark: Capture Interfaces"); /* transient_for top_level */
892 /* XXX: Note that on Windows the following is effectively a no-op; See dlg_window_new(). */
893 /* This means, on Windows, if the top_level Wireshark window is destroyed when */
894 /* the capture_interfaces dialog window is open, that the dumpcap process will not */
895 /* be stopped since the destroy callback for the capture_interfaces dialog window */
896 /* will not be called. */
897 /* ToDo: Fix this ! */
898 gtk_window_set_destroy_with_parent (GTK_WINDOW(cap_if_w), TRUE);
900 cap_if_top_vb = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, DLG_UNRELATED_SPACING, FALSE);
901 gtk_container_add(GTK_CONTAINER(cap_if_w), cap_if_top_vb);
902 gtk_container_set_border_width(GTK_CONTAINER(cap_if_top_vb), DLG_OUTER_MARGIN);
904 /* Button row: close, help, stop, start, and options button */
905 bbox = dlg_button_row_new(GTK_STOCK_HELP, WIRESHARK_STOCK_CAPTURE_START, WIRESHARK_STOCK_CAPTURE_OPTIONS, WIRESHARK_STOCK_CAPTURE_STOP, GTK_STOCK_CLOSE, NULL);
907 gtk_box_pack_end(GTK_BOX(cap_if_top_vb), bbox, FALSE, FALSE, 0);
908 help_bt = (GtkWidget *)g_object_get_data(G_OBJECT(bbox), GTK_STOCK_HELP);
909 g_signal_connect(help_bt, "clicked", G_CALLBACK(topic_cb), (gpointer)(HELP_CAPTURE_INTERFACES_DIALOG));
911 stop_bt = (GtkWidget *)g_object_get_data(G_OBJECT(bbox), WIRESHARK_STOCK_CAPTURE_STOP);
912 g_signal_connect(stop_bt, "clicked", G_CALLBACK(capture_if_stop_cb), NULL);
913 close_bt = (GtkWidget *)g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CLOSE);
914 window_set_cancel_button(cap_if_w, close_bt, window_cancel_button_cb);
915 gtk_widget_set_tooltip_text(close_bt, "Close this window.");
916 options_bt = (GtkWidget *)g_object_get_data(G_OBJECT(bbox), WIRESHARK_STOCK_CAPTURE_OPTIONS);
917 g_signal_connect(options_bt, "clicked", G_CALLBACK(capture_prepare_cb), NULL);
918 capture_bt = (GtkWidget *)g_object_get_data(G_OBJECT(bbox), WIRESHARK_STOCK_CAPTURE_START);
919 g_signal_connect(capture_bt, "clicked", G_CALLBACK(capture_do_cb), NULL);
921 gtk_widget_grab_default(close_bt);
923 g_signal_connect(cap_if_w, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
924 g_signal_connect(cap_if_w, "destroy", G_CALLBACK(capture_if_destroy_cb), sc);
926 capture_if_refresh_if_list();
928 window_present(cap_if_w);
930 set_capture_if_dialog_for_capture_in_progress(gbl_capture_in_progress);
933 gboolean interfaces_dialog_window_present(void)
935 return (cap_if_w?TRUE:FALSE);
938 void refresh_if_window(void)
941 capture_if_refresh_if_list();
945 void select_all_interfaces(gboolean enable _U_)
950 for (ifs = 0; ifs < global_capture_opts.all_ifaces->len; ifs++) {
951 device = g_array_index(global_capture_opts.all_ifaces, interface_t, ifs);
952 update_selected_interface(device.if_info.name);
956 void destroy_if_window(void)
959 window_destroy(cap_if_w);
962 #else /* HAVE_LIBPCAP */
965 set_capture_if_dialog_for_capture_in_progress(gboolean capture_in_progress _U_)
969 #endif /* HAVE_LIBPCAP */
977 * indent-tabs-mode: nil
980 * ex: set shiftwidth=2 tabstop=8 expandtab:
981 * :indentSize=2:tabSize=8:noTabs=true: