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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
36 #include <sys/types.h>
40 #include <epan/prefs.h>
42 #include "../capture_ifinfo.h"
43 #include "../simple_dialog.h"
44 #include "../capture.h"
45 #include "../capture-pcap-util.h"
46 #include "../capture_ui_utils.h"
47 #include "wsutil/file_util.h"
48 #include <wiretap/wtap.h>
51 #include "ui/gtk/capture_if_details_dlg_win32.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/recent.h"
58 #include "ui/gtk/gui_utils.h"
59 #include "ui/gtk/dlg_utils.h"
60 #include "ui/gtk/main.h"
61 #include "ui/gtk/main_toolbar.h"
62 #include "ui/gtk/help_dlg.h"
63 #include "ui/gtk/keys.h"
64 #include "ui/gtk/webbrowser.h"
65 #include "ui/gtk/capture_globals.h"
66 #include "ui/gtk/network_icons.h"
67 #include "ui/gtk/main_welcome.h"
68 #include "ui/gtk/menus.h"
70 #include "ui/gtk/old-gtk-compat.h"
73 #include "../image/toolbar/capture_airpcap_16.xpm"
76 #if defined(HAVE_PCAP_REMOTE)
77 #include "ui/gtk/remote_icons.h"
81 #include "../image/toolbar/capture_ethernet_16.xpm"
82 #include "../image/toolbar/modem_16.xpm"
85 #include "../image/toolbar/network_virtual_16.xpm"
87 /* new buttons to be used instead of labels for 'Capture','Prepare',' */
88 /*#include "../image/toolbar/capture_capture_16.xpm"*/
89 /*#include "../image/toolbar/capture_prepare_16.xpm"*/
90 /*#include "../image/toolbar/capture_details_16.xpm"*/
95 #include "airpcap_loader.h"
96 #include "airpcap_gui_utils.h"
97 #include "airpcap_dlg.h"
100 #define CAPTURE_IF_IP_ADDR_LABEL "capture_if_ip_addr_label"
101 #define CAPTURE_IF_SELECTED_IP_ADDR "capture_if_selected_ip_addr"
104 * Keep a static pointer to the current "Capture Interfaces" window, if
105 * any, so that if somebody tries to do "Capture:Start" while there's
106 * already a "Capture Interfaces" window up, we just pop up the existing
107 * one, rather than creating a new one.
109 static GtkWidget *cap_if_w;
111 static GList *if_data_list = NULL;
113 static guint timer_id;
115 static GtkWidget *stop_bt, *capture_bt, *options_bt;
117 static GList *if_list;
119 static guint currently_selected = 0;
121 static if_stat_cache_t *sc;
124 * Timeout, in milliseconds, for reads from the stream of captured packets.
126 #define CAP_READ_TIMEOUT 250
129 /* the "runtime" data of one interface */
130 typedef struct if_dlg_data_s {
131 GtkWidget *device_lb;
136 GtkWidget *choose_bt;
138 GtkWidget *details_bt;
140 guint32 last_packets;
146 static gboolean gbl_capture_in_progress = FALSE;
149 update_selected_interface(gchar *name, gboolean activate)
155 for (ifs = 0; ifs < g_list_length(if_data_list); ifs++) {
156 curr = g_list_nth(if_data_list, ifs);
157 temp = (if_dlg_data_t *)(curr->data);
158 if (strcmp(name, temp->if_info.name) == 0) {
160 gtk_toggle_button_set_active((GtkToggleButton *)temp->choose_bt, TRUE);
162 gtk_toggle_button_set_active((GtkToggleButton *)temp->choose_bt, FALSE);
170 store_selected(GtkWidget *choose_bt, gpointer if_data)
172 if_dlg_data_t *if_dlg_data = (if_dlg_data_t *)if_data, *temp;
176 cap_settings_t cap_settings;
177 interface_options interface_opts;
179 for (ifs = 0; ifs < g_list_length(if_data_list); ifs++) {
180 curr = g_list_nth(if_data_list, ifs);
181 temp = (if_dlg_data_t *)(curr->data);
183 if (strcmp(if_dlg_data->if_info.name, temp->if_info.name) == 0) {
185 if_data_list = g_list_remove(if_data_list, curr->data);
186 if_data_list = g_list_insert(if_data_list, temp, ifs);
188 for (i = 0; i < global_capture_opts.ifaces->len; i++) {
189 if (strcmp(g_array_index(global_capture_opts.ifaces, interface_options, i).name, temp->if_info.name) == 0) {
191 if (!temp->selected) {
192 interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, i);
193 global_capture_opts.ifaces = g_array_remove_index(global_capture_opts.ifaces, i);
194 if (gtk_widget_is_focus(choose_bt) && get_welcome_window()) {
195 change_interface_selection(interface_opts.name, FALSE);
197 if (gtk_widget_is_focus(choose_bt) && dlg_window_present()) {
198 enable_selected_interface(interface_opts.name, FALSE);
200 g_free(interface_opts.name);
201 g_free(interface_opts.descr);
202 g_free(interface_opts.cfilter);
203 #ifdef HAVE_PCAP_REMOTE
204 g_free(interface_opts.remote_host);
205 g_free(interface_opts.remote_port);
206 g_free(interface_opts.auth_username);
207 g_free(interface_opts.auth_password);
213 if (!found && temp->selected) {
214 interface_opts.name = g_strdup(temp->if_info.name);
215 interface_opts.descr = get_interface_descriptive_name(interface_opts.name);
216 interface_opts.linktype = capture_dev_user_linktype_find(interface_opts.name);
217 interface_opts.cfilter = g_strdup(global_capture_opts.default_options.cfilter);
218 interface_opts.has_snaplen = global_capture_opts.default_options.has_snaplen;
219 interface_opts.snaplen = global_capture_opts.default_options.snaplen;
220 cap_settings = capture_get_cap_settings (interface_opts.name);;
221 interface_opts.promisc_mode = global_capture_opts.default_options.promisc_mode;
222 #if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
223 interface_opts.buffer_size = global_capture_opts.default_options.buffer_size;
225 interface_opts.monitor_mode = cap_settings.monitor_mode;
226 #ifdef HAVE_PCAP_REMOTE
227 interface_opts.src_type = global_capture_opts.default_options.src_type;
228 interface_opts.remote_host = g_strdup(global_capture_opts.default_options.remote_host);
229 interface_opts.remote_port = g_strdup(global_capture_opts.default_options.remote_port);
230 interface_opts.auth_type = global_capture_opts.default_options.auth_type;
231 interface_opts.auth_username = g_strdup(global_capture_opts.default_options.auth_username);
232 interface_opts.auth_password = g_strdup(global_capture_opts.default_options.auth_password);
233 interface_opts.datatx_udp = global_capture_opts.default_options.datatx_udp;
234 interface_opts.nocap_rpcap = global_capture_opts.default_options.nocap_rpcap;
235 interface_opts.nocap_local = global_capture_opts.default_options.nocap_local;
237 #ifdef HAVE_PCAP_SETSAMPLING
238 interface_opts.sampling_method = global_capture_opts.default_options.sampling_method;
239 interface_opts.sampling_param = global_capture_opts.default_options.sampling_param;
241 g_array_append_val(global_capture_opts.ifaces, interface_opts);
242 if (gtk_widget_is_focus(choose_bt) && get_welcome_window() != NULL) {
243 change_interface_selection(g_strdup(temp->if_info.name), TRUE);
245 if (gtk_widget_is_focus(choose_bt) && dlg_window_present()) {
246 enable_selected_interface(interface_opts.name, TRUE);
251 currently_selected += 1;
253 currently_selected -= 1;
258 gtk_widget_set_sensitive(capture_bt, !gbl_capture_in_progress && (currently_selected > 0));
262 /* start capture button was pressed */
265 capture_do_cb(GtkWidget *capture_bt _U_, gpointer if_data)
267 capture_do_cb(GtkWidget *capture_bt _U_, gpointer if_data _U_)
274 if_dlg_data_t *if_dlg_data = if_data;
276 airpcap_if_active = get_airpcap_if_from_name(airpcap_if_list, if_dlg_data->if_info.name);
277 airpcap_if_selected = airpcap_if_active;
280 for (ifs = 0; (curr = g_list_nth(if_data_list, ifs)); ifs++) {
281 temp = (if_dlg_data_t *)(curr->data);
282 gtk_widget_set_sensitive(temp->choose_bt, FALSE);
285 /* XXX - remove this? */
286 if (global_capture_opts.save_file) {
287 g_free(global_capture_opts.save_file);
288 global_capture_opts.save_file = NULL;
291 if (global_capture_opts.ifaces->len > 1) {
292 global_capture_opts.use_pcapng = TRUE;
294 /* stop capturing from all interfaces, we are going to do real work now ... */
295 window_destroy(cap_if_w);
297 capture_start_cb(NULL, NULL);
301 /* prepare capture button was pressed */
303 capture_prepare_cb(GtkWidget *prepare_bt _U_, gpointer if_data _U_)
305 /* stop capturing from all interfaces, we are going to do real work now ... */
306 window_destroy(cap_if_w);
307 if (global_capture_opts.ifaces->len > 1) {
308 global_capture_opts.use_pcapng = TRUE;
310 capture_prep_cb(NULL, NULL);
315 /* capture details button was pressed */
317 capture_details_cb(GtkWidget *details_bt _U_, gpointer if_data)
319 if_dlg_data_t *if_dlg_data = if_data;
322 capture_if_details_open(if_dlg_data->device);
326 /* update a single interface */
328 update_if(if_dlg_data_t *if_dlg_data, if_stat_cache_t *sc)
330 struct pcap_stat stats;
336 * Note that some versions of libpcap, on some versions of UN*X,
337 * pcap_stats() returns the number of packets since the last
340 * That's a bug, and should be fixed; "pcap_stats()" is supposed
341 * to work the same way on all platforms.
344 if (capture_stats(sc, if_dlg_data->device, &stats)) {
345 diff = stats.ps_recv - if_dlg_data->last_packets;
346 if_dlg_data->last_packets = stats.ps_recv;
348 str = g_strdup_printf("%u", if_dlg_data->last_packets);
349 gtk_label_set_text(GTK_LABEL(if_dlg_data->curr_lb), str);
351 str = g_strdup_printf("%u", diff);
352 gtk_label_set_text(GTK_LABEL(if_dlg_data->last_lb), str);
355 gtk_widget_set_sensitive(if_dlg_data->curr_lb, diff);
356 gtk_widget_set_sensitive(if_dlg_data->last_lb, diff);
358 gtk_label_set_text(GTK_LABEL(if_dlg_data->curr_lb), "error");
359 gtk_label_set_text(GTK_LABEL(if_dlg_data->last_lb), "error");
364 /* update all interfaces */
366 update_all(gpointer data)
370 if_stat_cache_t *sc = (if_stat_cache_t *)data;
376 for (ifs = 0; (curr = g_list_nth(if_data_list, ifs)); ifs++) {
377 update_if((if_dlg_data_t *)curr->data, sc);
383 /* a live capture has started or stopped */
385 set_capture_if_dialog_for_capture_in_progress(gboolean capture_in_progress)
387 gbl_capture_in_progress = capture_in_progress;
389 gtk_widget_set_sensitive(stop_bt, capture_in_progress);
390 gtk_widget_set_sensitive(capture_bt, !capture_in_progress && (currently_selected > 0));
395 /* the window was closed, cleanup things */
397 capture_if_destroy_cb(GtkWidget *win _U_, gpointer user_data _U_)
402 g_source_remove(timer_id);
404 for (ifs = 0; (curr = g_list_nth(if_data_list, ifs)); ifs++) {
410 free_interface_list(if_list);
412 /* Note that we no longer have a "Capture Options" dialog box. */
415 capture_stat_stop(sc);
418 airpcap_set_toolbar_stop_capture(airpcap_if_active);
424 * Sorts the Interface List in alphabetical order
426 gint if_list_comparator_alph (const void *first_arg, const void *second_arg){
427 const if_info_t *first = first_arg, *second = second_arg;
429 if (first != NULL && first->description != NULL &&
430 second != NULL && second->description != NULL) {
431 return g_ascii_strcasecmp(first->description, second->description);
439 * Used to retrieve the interface icon.
440 * This is hideously platform-dependent.
442 GtkWidget * capture_get_if_icon(const if_info_t* if_info)
444 #if defined(__linux__)
449 #ifdef HAVE_PCAP_REMOTE
450 if (if_info->description && strstr(if_info->description, "on remote node") != NULL ) {
451 return pixbuf_to_widget(remote_sat_pb_data);
456 * Much digging failed to reveal any obvious way to get something such
457 * as the SNMP MIB-II ifType value for an interface:
459 * http://www.iana.org/assignments/ianaiftype-mib
461 * by making some NDIS request.
463 if ( if_info->description && ( strstr(if_info->description,"generic dialup") != NULL ||
464 strstr(if_info->description,"PPP/SLIP") != NULL ) ) {
465 return xpm_to_widget(modem_16_xpm);
468 if ( if_info->description && ( strstr(if_info->description,"Wireless") != NULL ||
469 strstr(if_info->description,"802.11") != NULL || strstr(if_info->description,"AirPcap") != NULL ) ) {
470 return pixbuf_to_widget(network_wireless_pb_data);
473 if ( strstr(if_info->name,"airpcap") != NULL ) {
474 return pixbuf_to_widget(network_wireless_pb_data);
477 if ( if_info->description && strstr(if_info->description, "Bluetooth") != NULL ) {
478 return pixbuf_to_widget(network_bluetooth_pb_data);
480 #elif defined(__APPLE__)
482 * XXX - yes, fetching all the network addresses for an interface
483 * gets you an AF_LINK address, of type "struct sockaddr_dl", and,
484 * yes, that includes an SNMP MIB-II ifType value.
486 * However, it's IFT_ETHER, i.e. Ethernet, for AirPort interfaces,
487 * not IFT_IEEE80211 (which isn't defined in OS X in any case).
489 * Perhaps some other BSD-flavored OSes won't make this mistake;
490 * however, FreeBSD 7.0 and OpenBSD 4.2, at least, appear to have
491 * made the same mistake, at least for my Belkin ZyDAS stick.
493 * On Mac OS X, one might be able to get the information one wants from
496 if ( strcmp(if_info->name, "en1") == 0) {
497 return pixbuf_to_widget(network_wireless_pb_data);
501 * XXX - PPP devices have names beginning with "ppp" and an IFT_ of
502 * IFT_PPP, but they could be dial-up, or PPPoE, or mobile phone modem,
503 * or VPN, or... devices. One might have to dive into the bowels of
508 * XXX - there's currently no support for raw Bluetooth capture,
509 * and IP-over-Bluetooth devices just look like fake Ethernet
510 * devices. There's also Bluetooth modem support, but that'll
511 * probably just give you a device that looks like a PPP device.
513 #elif defined(__linux__)
515 * Look for /sys/class/net/{device}/wireless.
517 wireless_path = g_strdup_printf("/sys/class/net/%s/wireless", if_info->name);
518 if (wireless_path != NULL) {
519 if (ws_stat64(wireless_path, &statb) == 0) {
520 g_free(wireless_path);
521 return pixbuf_to_widget(network_wireless_pb_data);
523 g_free(wireless_path);
529 * XXX - this is for raw Bluetooth capture; what about IP-over-Bluetooth
532 if ( strstr(if_info->name,"bluetooth") != NULL) {
533 return pixbuf_to_widget(network_bluetooth_pb_data);
539 if ( strstr(if_info->name,"usbmon") != NULL ) {
540 return pixbuf_to_widget(network_usb_pb_data);
545 * TODO: find a better icon!
546 * Bridge, NAT, or host-only interfaces on VMWare hosts have the name
547 * vmnet[0-9]+ or VMnet[0-9+ on Windows. Guests might use a native
548 * (LANCE or E1000) driver or the vmxnet driver. These devices have an
549 * IFT_ of IFT_ETHER, so we have to check the name.
551 if ( g_ascii_strncasecmp(if_info->name, "vmnet", 5) == 0) {
552 return xpm_to_widget(network_virtual_16_xpm);
555 if ( g_ascii_strncasecmp(if_info->name, "vmxnet", 6) == 0) {
556 return xpm_to_widget(network_virtual_16_xpm);
559 if ( if_info->description && strstr(if_info->description, "VMware") != NULL ) {
560 return xpm_to_widget(network_virtual_16_xpm);
563 return pixbuf_to_widget(network_wired_pb_data);
568 get_ip_addr_count(GSList *addr_list)
575 for (curr_addr = addr_list; curr_addr != NULL;
576 curr_addr = g_slist_next(curr_addr)) {
577 addr = (if_addr_t *)curr_addr->data;
578 switch (addr->ifat_type) {
586 /* In case we add non-IP addresses */
594 set_ip_addr_label(GSList *addr_list, GtkWidget *ip_lb, guint selected_ip_addr)
598 const gchar *addr_str = NULL;
600 curr_addr = g_slist_nth(addr_list, selected_ip_addr);
602 addr = (if_addr_t *)curr_addr->data;
603 switch (addr->ifat_type) {
606 addr_str = ip_to_str((guint8 *)&addr->addr.ip4_addr);
610 addr_str = ip6_to_str((struct e_in6_addr *)&addr->addr.ip6_addr);
614 /* Ignore non-IP addresses, in case we ever support them */
620 gtk_label_set_text(GTK_LABEL(ip_lb), addr_str);
622 gtk_label_set_text(GTK_LABEL(ip_lb), "none");
624 g_object_set_data(G_OBJECT(ip_lb), CAPTURE_IF_SELECTED_IP_ADDR, GINT_TO_POINTER(selected_ip_addr));
631 ip_label_enter_cb(GtkWidget *eb, GdkEventCrossing *event _U_, gpointer user_data _U_)
633 gtk_widget_set_state(eb, GTK_STATE_PRELIGHT);
640 ip_label_leave_cb(GtkWidget *eb, GdkEvent *event _U_, gpointer user_data _U_)
642 gtk_widget_set_state(eb, GTK_STATE_NORMAL);
649 ip_label_press_cb(GtkWidget *widget, GdkEvent *event _U_, gpointer data)
651 GtkWidget *ip_lb = (GtkWidget *)g_object_get_data(G_OBJECT(widget), CAPTURE_IF_IP_ADDR_LABEL);
652 GSList *addr_list = (GSList *)data;
653 GSList *curr_addr, *start_addr;
655 guint selected_ip_addr = GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(ip_lb), CAPTURE_IF_SELECTED_IP_ADDR));
657 /* Select next IP address */
658 start_addr = g_slist_nth(addr_list, selected_ip_addr);
661 if (g_slist_length(addr_list) <= selected_ip_addr) {
663 selected_ip_addr = 0;
665 curr_addr = g_slist_nth(addr_list, selected_ip_addr);
666 if (curr_addr == start_addr) {
667 /* We wrapped all the way around */
671 addr = (if_addr_t *)curr_addr->data;
672 switch (addr->ifat_type) {
679 /* In case we add non-IP addresses */
685 set_ip_addr_label(addr_list, ip_lb, selected_ip_addr);
691 capture_if_stop_cb(GtkWidget *w _U_, gpointer d _U_)
695 if_dlg_data_t *if_data;
697 for (ifs = 0; ifs < g_list_length(if_data_list); ifs++) {
698 curr = g_list_nth(if_data_list, ifs);
699 if_data = (if_dlg_data_t *)(curr->data);
700 gtk_widget_set_sensitive(if_data->choose_bt, TRUE);
702 capture_stop_cb(NULL, NULL);
706 /* start getting capture stats from all interfaces */
708 capture_if_cb(GtkWidget *w _U_, gpointer d _U_)
718 GtkWidget *decryption_cb;
726 GtkRequisition requisition;
728 if_dlg_data_t *if_dlg_data = NULL;
732 GString *if_tool_str = g_string_new("");
733 const gchar *addr_str;
735 int preselected = 0, i;
736 interface_options interface_opts;
737 gboolean found = FALSE;
739 if (cap_if_w != NULL) {
740 /* There's already a "Capture Interfaces" dialog box; reactivate it. */
741 reactivate_window(cap_if_w);
745 preselected = global_capture_opts.ifaces->len;
746 /* LOAD THE INTERFACES */
747 if_list = capture_interface_list(&err, &err_str);
748 if_list = g_list_sort (if_list, if_list_comparator_alph);
749 if (if_list == NULL) {
752 case CANT_GET_INTERFACE_LIST:
754 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_str);
758 case NO_INTERFACES_FOUND:
759 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
760 "There are no interfaces on which a capture can be done.");
767 /* LOAD AIRPCAP INTERFACES */
768 airpcap_if_list = get_airpcap_interface_list(&err, &err_str);
769 if (airpcap_if_list == NULL)
770 airpcap_if_active = airpcap_if_selected = NULL;
772 decryption_cb = g_object_get_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_DECRYPTION_KEY);
773 update_decryption_mode_list(decryption_cb);
775 if (airpcap_if_list == NULL && err == CANT_GET_AIRPCAP_INTERFACE_LIST) {
777 /* XXX - Do we need to show an error here? */
778 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_str);
783 /* If no airpcap interface is present, gray everything */
784 if (airpcap_if_active == NULL) {
785 if (airpcap_if_list == NULL) {
786 /*No airpcap device found */
787 airpcap_enable_toolbar_widgets(airpcap_tb,FALSE);
789 /* default adapter is not airpcap... or is airpcap but is not found*/
790 airpcap_set_toolbar_stop_capture(airpcap_if_active);
791 airpcap_enable_toolbar_widgets(airpcap_tb,FALSE);
795 airpcap_set_toolbar_start_capture(airpcap_if_active);
798 cap_if_w = dlg_window_new("Wireshark: Capture Interfaces"); /* transient_for top_level */
799 gtk_window_set_destroy_with_parent (GTK_WINDOW(cap_if_w), TRUE);
801 main_sw = gtk_scrolled_window_new(NULL, NULL);
802 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(main_sw), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
803 gtk_container_add(GTK_CONTAINER(cap_if_w), main_sw);
805 main_vb = gtk_vbox_new(FALSE, 0);
806 gtk_container_set_border_width(GTK_CONTAINER(main_vb), 5);
807 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(main_sw), main_vb);
809 if_tb = gtk_table_new(1,9, FALSE);
810 gtk_table_set_row_spacings(GTK_TABLE(if_tb), 3);
811 gtk_table_set_col_spacings(GTK_TABLE(if_tb), 3);
812 gtk_box_pack_start(GTK_BOX(main_vb), if_tb, FALSE, FALSE, 0);
817 /* This is the icon column, used to display which kind of interface we have */
818 if_lb = gtk_label_new("");
819 gtk_table_attach_defaults(GTK_TABLE(if_tb), if_lb, 0, 1, row, row+1);
823 * On Windows, device names are generally not meaningful - NT 5
824 * uses long blobs with GUIDs in them, for example - so we don't
825 * bother showing them.
827 if_lb = gtk_label_new("Device");
828 gtk_table_attach_defaults(GTK_TABLE(if_tb), if_lb, 1, 4, row, row+1);
830 if_lb = gtk_label_new("Description");
831 gtk_table_attach_defaults(GTK_TABLE(if_tb), if_lb, 4, 5, row, row+1);
833 if_lb = gtk_label_new(" IP ");
834 gtk_table_attach_defaults(GTK_TABLE(if_tb), if_lb, 5, 6, row, row+1);
836 if_lb = gtk_label_new("Packets");
837 gtk_table_attach_defaults(GTK_TABLE(if_tb), if_lb, 6, 7, row, row+1);
839 if_lb = gtk_label_new(" Packets/s ");
840 gtk_table_attach_defaults(GTK_TABLE(if_tb), if_lb, 7, 8, row, row+1);
844 /* Start gathering statistics (using dumpcap) */
845 sc = capture_stat_start(if_list);
847 /* List the interfaces */
848 currently_selected = 0;
849 for (ifs = 0; (curr = g_list_nth(if_list, ifs)); ifs++) {
850 g_string_assign(if_tool_str, "");
851 if_info = (if_info_t *)curr->data;
853 /* Continue if capture device is hidden */
854 if (prefs_is_capture_device_hidden(if_info->name)) {
858 if_dlg_data = g_new0(if_dlg_data_t,1);
860 if (preselected > 0) {
862 for (i = 0; i < (gint)global_capture_opts.ifaces->len; i++) {
863 interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, i);
864 if ((interface_opts.name == NULL) ||
865 (strcmp(interface_opts.name, (char*)if_info->name) != 0)) {
869 currently_selected++;
874 if_dlg_data->selected = found;
876 if_dlg_data->selected = FALSE;
878 if_dlg_data->if_info = *if_info;
880 if_dlg_data->choose_bt = gtk_check_button_new();
881 gtk_table_attach_defaults(GTK_TABLE(if_tb), if_dlg_data->choose_bt, 0, 1, row, row+1);
882 if (gbl_capture_in_progress) {
883 gtk_widget_set_sensitive(if_dlg_data->choose_bt, FALSE);
885 gtk_widget_set_sensitive(if_dlg_data->choose_bt, TRUE);
887 gtk_toggle_button_set_active((GtkToggleButton *)if_dlg_data->choose_bt, if_dlg_data->selected);
888 g_signal_connect(if_dlg_data->choose_bt, "toggled", G_CALLBACK(store_selected), if_dlg_data);
889 /* Kind of adaptor (icon) */
891 if (get_airpcap_if_from_name(airpcap_if_list,if_info->name) != NULL)
892 icon = xpm_to_widget(capture_airpcap_16_xpm);
894 icon = capture_get_if_icon(if_info);
896 icon = capture_get_if_icon(if_info);
898 gtk_table_attach_defaults(GTK_TABLE(if_tb), icon, 1, 2, row, row+1);
901 if_dlg_data->device_lb = gtk_label_new(if_info->name);
902 if_dlg_data->device = if_info->name;
904 gtk_misc_set_alignment(GTK_MISC(if_dlg_data->device_lb), 0.0f, 0.5f);
905 gtk_table_attach_defaults(GTK_TABLE(if_tb), if_dlg_data->device_lb, 2, 4, row, row+1);
907 g_string_append(if_tool_str, "Device: ");
908 g_string_append(if_tool_str, if_info->name);
909 g_string_append(if_tool_str, "\n");
912 user_descr = capture_dev_user_descr_find(if_info->name);
914 if_dlg_data->descr_lb = gtk_label_new(user_descr);
917 if (if_info->description)
918 if_dlg_data->descr_lb = gtk_label_new(if_info->description);
920 if_dlg_data->descr_lb = gtk_label_new("");
922 gtk_misc_set_alignment(GTK_MISC(if_dlg_data->descr_lb), 0.0f, 0.5f);
923 gtk_table_attach_defaults(GTK_TABLE(if_tb), if_dlg_data->descr_lb, 4, 5, row, row+1);
925 if (if_info->description) {
926 g_string_append(if_tool_str, "Description: ");
927 g_string_append(if_tool_str, if_info->description);
928 g_string_append(if_tool_str, "\n");
932 /* Only one IP address will be shown, start with the first */
933 g_string_append(if_tool_str, "IP: ");
934 if_dlg_data->ip_lb = gtk_label_new("");
935 addr_str = set_ip_addr_label (if_info->addrs, if_dlg_data->ip_lb, 0);
937 gtk_widget_set_sensitive(if_dlg_data->ip_lb, TRUE);
938 g_string_append(if_tool_str, addr_str);
940 gtk_widget_set_sensitive(if_dlg_data->ip_lb, FALSE);
941 g_string_append(if_tool_str, "none");
943 eb = gtk_event_box_new ();
944 gtk_container_add(GTK_CONTAINER(eb), if_dlg_data->ip_lb);
945 gtk_table_attach_defaults(GTK_TABLE(if_tb), eb, 5, 6, row, row+1);
946 if (get_ip_addr_count(if_info->addrs) > 1) {
947 /* More than one IP address, make it possible to toggle */
948 g_object_set_data(G_OBJECT(eb), CAPTURE_IF_IP_ADDR_LABEL, if_dlg_data->ip_lb);
949 g_signal_connect(eb, "enter-notify-event", G_CALLBACK(ip_label_enter_cb), NULL);
950 g_signal_connect(eb, "leave-notify-event", G_CALLBACK(ip_label_leave_cb), NULL);
951 g_signal_connect(eb, "button-press-event", G_CALLBACK(ip_label_press_cb), if_info->addrs);
953 g_string_append(if_tool_str, "\n");
956 if_dlg_data->curr_lb = gtk_label_new("-");
957 gtk_table_attach_defaults(GTK_TABLE(if_tb), if_dlg_data->curr_lb, 6, 7, row, row+1);
960 if_dlg_data->last_lb = gtk_label_new("-");
961 gtk_table_attach_defaults(GTK_TABLE(if_tb), if_dlg_data->last_lb, 7, 8, row, row+1);
965 if_dlg_data->details_bt = gtk_button_new_from_stock(WIRESHARK_STOCK_CAPTURE_DETAILS);
966 gtk_widget_set_tooltip_text(if_dlg_data->details_bt, "Open the capture details dialog of this interface.");
967 gtk_table_attach_defaults(GTK_TABLE(if_tb), if_dlg_data->details_bt, 8, 9, row, row+1);
968 if (capture_if_has_details(if_dlg_data->device)) {
969 g_signal_connect(if_dlg_data->details_bt, "clicked", G_CALLBACK(capture_details_cb), if_dlg_data);
971 gtk_widget_set_sensitive(if_dlg_data->details_bt, FALSE);
975 if_data_list = g_list_append(if_data_list, if_dlg_data);
979 /* Lets add up 10 rows of interfaces, otherwise the window may become too high */
980 gtk_widget_get_preferred_size(GTK_WIDGET(if_dlg_data->choose_bt), &requisition, NULL);
981 height += requisition.height;
985 g_string_free(if_tool_str, TRUE);
987 /* Button row: close, help, stop, start, and options button */
988 bbox = dlg_button_row_new(GTK_STOCK_HELP, WIRESHARK_STOCK_CAPTURE_START, WIRESHARK_STOCK_CAPTURE_OPTIONS, WIRESHARK_STOCK_CAPTURE_STOP, GTK_STOCK_CLOSE, NULL);
990 gtk_box_pack_start(GTK_BOX(main_vb), bbox, FALSE, FALSE, 5);
991 help_bt = (GtkWidget *)g_object_get_data(G_OBJECT(bbox), GTK_STOCK_HELP);
992 g_signal_connect(help_bt, "clicked", G_CALLBACK(topic_cb), (gpointer)(HELP_CAPTURE_INTERFACES_DIALOG));
994 stop_bt = (GtkWidget *)g_object_get_data(G_OBJECT(bbox), WIRESHARK_STOCK_CAPTURE_STOP);
995 g_signal_connect(stop_bt, "clicked", G_CALLBACK(capture_if_stop_cb), NULL);
996 close_bt = (GtkWidget *)g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CLOSE);
997 window_set_cancel_button(cap_if_w, close_bt, window_cancel_button_cb);
998 gtk_widget_set_tooltip_text(close_bt, "Close this window.");
999 options_bt = (GtkWidget *)g_object_get_data(G_OBJECT(bbox), WIRESHARK_STOCK_CAPTURE_OPTIONS);
1000 g_signal_connect(options_bt, "clicked", G_CALLBACK(capture_prepare_cb), if_dlg_data);
1001 capture_bt = (GtkWidget *)g_object_get_data(G_OBJECT(bbox), WIRESHARK_STOCK_CAPTURE_START);
1002 g_signal_connect(capture_bt, "clicked", G_CALLBACK(capture_do_cb), if_dlg_data);
1003 gtk_widget_get_preferred_size(GTK_WIDGET(close_bt), &requisition, NULL);
1004 /* height + static offset + what the GTK MS Windows Engine needs in addition per interface */
1005 height += requisition.height + 40 + ifs;
1006 gtk_window_set_default_size(GTK_WINDOW(cap_if_w), -1, height);
1008 gtk_widget_grab_default(close_bt);
1010 g_signal_connect(cap_if_w, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
1011 g_signal_connect(cap_if_w, "destroy", G_CALLBACK(capture_if_destroy_cb), sc);
1013 gtk_widget_show_all(cap_if_w);
1014 window_present(cap_if_w);
1016 set_capture_if_dialog_for_capture_in_progress(gbl_capture_in_progress);
1018 /* update the interface list every 1000ms */
1019 timer_id = g_timeout_add(1000, update_all, sc);
1022 gboolean interfaces_dialog_window_present(void)
1024 return (cap_if_w?TRUE:FALSE);
1027 void refresh_if_window(void)
1029 capture_if_destroy_cb(NULL, NULL);
1030 capture_if_cb(NULL, NULL);
1033 void select_all_interfaces(gboolean enable)
1035 if_dlg_data_t *temp;
1039 for (ifs = 0; ifs < g_list_length(if_data_list); ifs++) {
1040 curr = g_list_nth(if_data_list, ifs);
1041 temp = (if_dlg_data_t *)(curr->data);
1042 update_selected_interface(temp->if_info.name, enable);
1046 void destroy_if_window(void)
1049 window_destroy(cap_if_w);
1052 #else /* HAVE_LIBPCAP */
1055 set_capture_if_dialog_for_capture_in_progress(gboolean capture_in_progress _U_)
1059 #endif /* HAVE_LIBPCAP */