Use the USB icon for usbmon devices on Linux.
[obnox/wireshark/wip.git] / gtk / capture_if_dlg.c
1 /* capture_if_dlg.c
2  * Routines for the capture interface dialog
3  *
4  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 1998 Gerald Combs
9  *
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.
14  *
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.
19  *
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.
23  */
24
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #include <gtk/gtk.h>
30
31 #ifdef HAVE_LIBPCAP
32
33 #include <string.h>
34
35 #ifdef __linux__
36 #include <sys/types.h>
37 #include <sys/stat.h>
38 #endif
39
40 #include <epan/prefs.h>
41
42 #include "../globals.h"
43 #include "../capture-pcap-util.h"
44 #include "../simple_dialog.h"
45 #include "../capture.h"
46 #include "../capture_errs.h"
47 #include "../capture_ui_utils.h"
48 #include "wsutil/file_util.h"
49 #include <wiretap/wtap.h>
50
51 #ifdef _WIN32
52 #include "../capture-wpcap.h"
53 #include "gtk/capture_if_details_dlg_win32.h"
54 #endif
55
56 #include "gtk/stock_icons.h"
57 #include "gtk/capture_dlg.h"
58 #include "gtk/capture_if_dlg.h"
59 #include "gtk/recent.h"
60 #include "gtk/gui_utils.h"
61 #include "gtk/dlg_utils.h"
62 #include "gtk/main.h"
63 #include "gtk/main_toolbar.h"
64 #include "gtk/help_dlg.h"
65 #include "gtk/keys.h"
66 #include "gtk/webbrowser.h"
67 #include "gtk/capture_globals.h"
68 #include "gtk/network_icons.h"
69
70 #ifdef HAVE_AIRPCAP
71 #include "../image/toolbar/capture_airpcap_16.xpm"
72 #endif
73
74 #ifdef _WIN32
75 #include "../image/toolbar/capture_ethernet_16.xpm"
76 #include "../image/toolbar/modem_16.xpm"
77 #endif
78
79 #include "../image/toolbar/network_virtual_16.xpm"
80
81 /* new buttons to be used instead of labels for 'Capture','Prepare',' */
82 /*#include "../image/toolbar/capture_capture_16.xpm"*/
83 /*#include "../image/toolbar/capture_prepare_16.xpm"*/
84 /*#include "../image/toolbar/capture_details_16.xpm"*/
85
86
87 #ifdef HAVE_AIRPCAP
88 #include "airpcap.h"
89 #include "airpcap_loader.h"
90 #include "airpcap_gui_utils.h"
91 #include "airpcap_dlg.h"
92 #endif
93
94 #define CAPTURE_IF_IP_ADDR_LABEL      "capture_if_ip_addr_label"
95 #define CAPTURE_IF_SELECTED_IP_ADDR   "capture_if_selected_ip_addr"
96
97 /*
98  * Keep a static pointer to the current "Capture Interfaces" window, if
99  * any, so that if somebody tries to do "Capture:Start" while there's
100  * already a "Capture Interfaces" window up, we just pop up the existing
101  * one, rather than creating a new one.
102  */
103 static GtkWidget *cap_if_w;
104
105 GList           *if_data = NULL;
106
107 guint           timer_id;
108
109 GtkWidget       *stop_bt;
110
111 GList           *if_list;
112
113 /*
114  * Timeout, in milliseconds, for reads from the stream of captured packets.
115  */
116 #define CAP_READ_TIMEOUT        250
117
118
119 /* the "runtime" data of one interface */
120 typedef struct if_dlg_data_s {
121     GtkWidget   *device_lb;
122     GtkWidget   *descr_lb;
123     GtkWidget   *ip_lb;
124     GtkWidget   *curr_lb;
125     GtkWidget   *last_lb;
126     GtkWidget   *capture_bt;
127     GtkWidget   *prepare_bt;
128 #ifdef _WIN32
129     GtkWidget   *details_bt;
130 #endif
131     guint32     last_packets;
132     gchar       *device;
133     if_info_t   if_info;
134 } if_dlg_data_t;
135
136
137 /* start capture button was pressed */
138 static void
139 capture_do_cb(GtkWidget *capture_bt _U_, gpointer if_data)
140 {
141   if_dlg_data_t *if_dlg_data = if_data;
142
143 #ifdef HAVE_AIRPCAP
144   airpcap_if_active = get_airpcap_if_from_name(airpcap_if_list, if_dlg_data->if_info.name);
145   airpcap_if_selected = airpcap_if_active;
146 #endif
147
148   g_free(global_capture_opts.iface);
149   g_free(global_capture_opts.iface_descr);
150
151   global_capture_opts.iface = g_strdup(if_dlg_data->device);
152   global_capture_opts.iface_descr = get_interface_descriptive_name(global_capture_opts.iface);
153
154   /* XXX - remove this? */
155   if (global_capture_opts.save_file) {
156     g_free(global_capture_opts.save_file);
157     global_capture_opts.save_file = NULL;
158   }
159
160   /* stop capturing from all interfaces, we are going to do real work now ... */
161   window_destroy(cap_if_w);
162
163   capture_start_cb(NULL, NULL);
164 }
165
166
167 /* prepare capture button was pressed */
168 static void
169 capture_prepare_cb(GtkWidget *prepare_bt _U_, gpointer if_data)
170 {
171   if_dlg_data_t *if_dlg_data = if_data;
172
173   g_free(global_capture_opts.iface);
174   g_free(global_capture_opts.iface_descr);
175
176   global_capture_opts.iface = g_strdup(if_dlg_data->device);
177   global_capture_opts.iface_descr = get_interface_descriptive_name(global_capture_opts.iface);
178
179   /* stop capturing from all interfaces, we are going to do real work now ... */
180   window_destroy(cap_if_w);
181
182   capture_prep_cb(NULL, NULL);
183 }
184
185
186 #ifdef _WIN32
187 /* capture details button was pressed */
188 static void
189 capture_details_cb(GtkWidget *details_bt _U_, gpointer if_data)
190 {
191   if_dlg_data_t *if_dlg_data = if_data;
192
193
194   capture_if_details_open(if_dlg_data->device);
195 }
196 #endif
197
198 /* update a single interface */
199 static void
200 update_if(if_dlg_data_t *if_dlg_data, if_stat_cache_t *sc)
201 {
202   struct pcap_stat stats;
203   gchar *str;
204   guint diff;
205
206
207   /*
208    * Note that some versions of libpcap, on some versions of UN*X,
209    * pcap_stats() returns the number of packets since the last
210    * pcap_stats call.
211    *
212    * That's a bug, and should be fixed; "pcap_stats()" is supposed
213    * to work the same way on all platforms.
214    */
215   if (sc) {
216     if(capture_stats(sc, if_dlg_data->device, &stats)) {
217       diff = stats.ps_recv - if_dlg_data->last_packets;
218       if_dlg_data->last_packets = stats.ps_recv;
219
220       str = g_strdup_printf("%u", if_dlg_data->last_packets);
221       gtk_label_set_text(GTK_LABEL(if_dlg_data->curr_lb), str);
222       g_free(str);
223       str = g_strdup_printf("%u", diff);
224       gtk_label_set_text(GTK_LABEL(if_dlg_data->last_lb), str);
225       g_free(str);
226
227       gtk_widget_set_sensitive(if_dlg_data->curr_lb, diff);
228       gtk_widget_set_sensitive(if_dlg_data->last_lb, diff);
229     } else {
230       gtk_label_set_text(GTK_LABEL(if_dlg_data->curr_lb), "error");
231       gtk_label_set_text(GTK_LABEL(if_dlg_data->last_lb), "error");
232     }
233   }
234 }
235
236 /* update all interfaces */
237 static gboolean
238 update_all(gpointer data)
239 {
240     GList *curr;
241     int ifs;
242     if_stat_cache_t *sc = data;
243
244     if(!cap_if_w) {
245         return FALSE;
246     }
247
248     for(ifs = 0; (curr = g_list_nth(if_data, ifs)); ifs++) {
249         update_if(curr->data, sc);
250     }
251
252     return TRUE;
253 }
254
255 gboolean g_capture_in_progress = FALSE;
256
257 /* a live capture has started or stopped */
258 void
259 set_capture_if_dialog_for_capture_in_progress(gboolean capture_in_progress)
260 {
261     GList *curr;
262     int ifs;
263
264     g_capture_in_progress = capture_in_progress;
265
266     if(cap_if_w) {
267         gtk_widget_set_sensitive(stop_bt, capture_in_progress);
268
269         for(ifs = 0; (curr = g_list_nth(if_data, ifs)); ifs++) {
270             if_dlg_data_t *if_dlg_data = curr->data;
271
272             gtk_widget_set_sensitive(if_dlg_data->capture_bt, !capture_in_progress);
273             gtk_widget_set_sensitive(if_dlg_data->prepare_bt, !capture_in_progress);
274         }
275     }
276 }
277
278
279 /* the window was closed, cleanup things */
280 static void
281 capture_if_destroy_cb(GtkWidget *win _U_, gpointer user_data)
282 {
283     GList *curr;
284     int ifs;
285     if_stat_cache_t *sc = user_data;
286
287     g_source_remove(timer_id);
288
289     for(ifs = 0; (curr = g_list_nth(if_data, ifs)); ifs++) {
290         g_free(curr->data);
291     }
292
293     if_data = NULL;
294
295     free_interface_list(if_list);
296
297     /* Note that we no longer have a "Capture Options" dialog box. */
298     cap_if_w = NULL;
299
300     capture_stat_stop(sc);
301
302 #ifdef HAVE_AIRPCAP
303     airpcap_set_toolbar_stop_capture(airpcap_if_active);
304 #endif
305 }
306
307
308 /*
309  * Sorts the Interface List in alphabetical order
310  */
311 gint if_list_comparator_alph (const void *first_arg, const void *second_arg){
312   const if_info_t *first = first_arg, *second = second_arg;
313
314   if (first != NULL && first->description != NULL &&
315       second != NULL && second->description != NULL) {
316     return g_ascii_strcasecmp(first->description, second->description);
317   } else {
318     return 0;
319   }
320 }
321
322
323 /*
324  * Used to retrieve the interface icon.
325  * This is hideously platform-dependent.
326  */
327 GtkWidget * capture_get_if_icon(const if_info_t* if_info _U_)
328 {
329 #if defined(_WIN32)
330   /*
331    * Much digging failed to reveal any obvious way to get something such
332    * as the SNMP MIB-II ifType value for an interface:
333    *
334    *    http://www.iana.org/assignments/ianaiftype-mib
335    *
336    * by making some NDIS request.
337    */
338   if ( if_info->description && ( strstr(if_info->description,"generic dialup") != NULL ||
339        strstr(if_info->description,"PPP/SLIP") != NULL ) ) {
340     return xpm_to_widget(modem_16_xpm);
341   }
342
343   if ( if_info->description && ( strstr(if_info->description,"Wireless") != NULL ||
344        strstr(if_info->description,"802.11") != NULL || strstr(if_info->description,"AirPcap") != NULL ) ) {
345     return pixbuf_to_widget(network_wireless_pb_data);
346   }
347
348   if ( strstr(if_info->name,"airpcap") != NULL ) {
349     return pixbuf_to_widget(network_wireless_pb_data);
350   }
351
352   if ( if_info->description && strstr(if_info->description, "Bluetooth") != NULL ) {
353     return pixbuf_to_widget(network_bluetooth_pb_data);
354   }
355 #elif defined(__APPLE__)
356   /*
357    * XXX - yes, fetching all the network addresses for an interface
358    * gets you an AF_LINK address, of type "struct sockaddr_dl", and,
359    * yes, that includes an SNMP MIB-II ifType value.
360    *
361    * However, it's IFT_ETHER, i.e. Ethernet, for AirPort interfaces,
362    * not IFT_IEEE80211 (which isn't defined in OS X in any case).
363    *
364    * Perhaps some other BSD-flavored OSes won't make this mistake;
365    * however, FreeBSD 7.0 and OpenBSD 4.2, at least, appear to have
366    * made the same mistake, at least for my Belkin ZyDAS stick.
367    *
368    * On Mac OS X, one might be able to get the information one wants from
369    * IOKit.
370    */
371   if ( strcmp(if_info->name, "en1") == 0) {
372     return pixbuf_to_widget(network_wireless_pb_data);
373   }
374
375   /*
376    * XXX - PPP devices have names beginning with "ppp" and an IFT_ of
377    * IFT_PPP, but they could be dial-up, or PPPoE, or mobile phone modem,
378    * or VPN, or... devices.  One might have to dive into the bowels of
379    * IOKit to find out.
380    */
381
382   /*
383    * XXX - there's currently no support for raw Bluetooth capture,
384    * and IP-over-Bluetooth devices just look like fake Ethernet
385    * devices.  There's also Bluetooth modem support, but that'll
386    * probably just give you a device that looks like a PPP device.
387    */
388 #elif defined(__linux__)
389   /*
390    * Look for /sys/class/net/{device}/wireless.
391    */
392   struct stat statb;
393   char *wireless_path;
394
395   wireless_path = g_strdup_printf("/sys/class/net/%s/wireless", if_info->name);
396   if (wireless_path != NULL) {
397     if (ws_stat(wireless_path, &statb) == 0) {
398       g_free(wireless_path);
399       return pixbuf_to_widget(network_wireless_pb_data);
400     }
401     g_free(wireless_path);
402   }
403
404   /*
405    * Bluetooth devices.
406    *
407    * XXX - this is for raw Bluetooth capture; what about IP-over-Bluetooth
408    * devices?
409    */
410   if ( strstr(if_info->name,"bluetooth") != NULL) {
411     return pixbuf_to_widget(network_bluetooth_pb_data);
412   }
413
414   /*
415    * USB devices.
416    */
417   if ( strstr(if_info->name,"usbmon") != NULL ) {
418     return pixbuf_to_widget(network_usb_pb_data);
419   }
420 #endif
421
422   /*
423    * TODO: find a better icon!
424    * Bridge, NAT, or host-only interfaces on VMWare hosts have the name
425    * vmnet[0-9]+ or VMnet[0-9+ on Windows. Guests might use a native
426    * (LANCE or E1000) driver or the vmxnet driver. These devices have an
427    * IFT_ of IFT_ETHER, so we have to check the name.
428    */
429   if ( g_ascii_strncasecmp(if_info->name, "vmnet", 5) == 0) {
430     return xpm_to_widget(network_virtual_16_xpm);
431   }
432
433   if ( g_ascii_strncasecmp(if_info->name, "vmxnet", 6) == 0) {
434     return xpm_to_widget(network_virtual_16_xpm);
435   }
436
437   if ( if_info->description && strstr(if_info->description, "VMware") != NULL ) {
438     return xpm_to_widget(network_virtual_16_xpm);
439   }
440
441   return pixbuf_to_widget(network_wired_pb_data);
442 }
443
444
445 static const gchar *
446 set_ip_addr_label(GSList *ip_addr_list, GtkWidget *ip_lb, guint selected_ip_addr)
447 {
448   GSList *curr_ip;
449   if_addr_t *ip_addr;
450   const gchar *addr_str = NULL;
451
452   curr_ip = g_slist_nth(ip_addr_list, selected_ip_addr);
453   if (curr_ip) {
454     ip_addr = (if_addr_t *)curr_ip->data;
455     switch (ip_addr->type) {
456
457     case AT_IPv4:
458       addr_str = ip_to_str((guint8 *)&ip_addr->ip_addr.ip4_addr);
459       break;
460
461     case AT_IPv6:
462       addr_str = ip6_to_str((struct e_in6_addr *)&ip_addr->ip_addr.ip6_addr);
463       break;
464
465     default:
466       g_assert_not_reached();
467     }
468   }
469
470   if (addr_str) {
471     gtk_label_set_text(GTK_LABEL(ip_lb), addr_str);
472   } else {
473     gtk_label_set_text(GTK_LABEL(ip_lb), "unknown");
474   }
475   g_object_set_data(G_OBJECT(ip_lb), CAPTURE_IF_SELECTED_IP_ADDR, GINT_TO_POINTER(selected_ip_addr));
476
477   return addr_str;
478 }
479
480
481 static gboolean
482 ip_label_enter_cb(GtkWidget *eb, GdkEventCrossing *event _U_, gpointer user_data _U_)
483 {
484     gtk_widget_set_state(eb, GTK_STATE_PRELIGHT);
485
486     return FALSE;
487 }
488
489
490 static gboolean
491 ip_label_leave_cb(GtkWidget *eb, GdkEvent *event _U_, gpointer user_data _U_)
492 {
493     gtk_widget_set_state(eb, GTK_STATE_NORMAL);
494
495     return FALSE;
496 }
497
498
499 static gboolean
500 ip_label_press_cb(GtkWidget *widget, GdkEvent *event _U_, gpointer data)
501 {
502   GtkWidget *ip_lb = g_object_get_data(G_OBJECT(widget), CAPTURE_IF_IP_ADDR_LABEL);
503   GSList *ip_addr_list = data;
504   guint selected_ip_addr = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(ip_lb), CAPTURE_IF_SELECTED_IP_ADDR));
505
506   /* Select next IP address */
507   selected_ip_addr++;
508   if (g_slist_length(ip_addr_list) <= selected_ip_addr) {
509     /* Probably have the last one, start over again */
510     selected_ip_addr = 0;
511   }
512
513   set_ip_addr_label(ip_addr_list, ip_lb, selected_ip_addr);
514
515   return FALSE;
516 }
517
518
519
520 /* start getting capture stats from all interfaces */
521 void
522 capture_if_cb(GtkWidget *w _U_, gpointer d _U_)
523 {
524   GtkWidget     *main_vb,
525                                 *main_sw,
526                                 *bbox,
527                                 *close_bt,
528                                 *help_bt,
529                                 *icon;
530
531 #ifdef HAVE_AIRPCAP
532   GtkWidget             *decryption_cb;
533 #endif
534
535   GtkWidget     *if_tb;
536   GtkWidget     *if_lb;
537   GtkWidget     *eb;
538   GtkTooltips   *tooltips;
539   int           err;
540   gchar         *err_str;
541   GtkRequisition requisition;
542   int           row, height;
543   if_dlg_data_t *if_dlg_data;
544   int           ifs;
545   GList         *curr;
546   if_info_t     *if_info;
547   GString       *if_tool_str = g_string_new("");
548   const gchar   *addr_str;
549   gchar         *tmp_str;
550   gchar         *user_descr;
551   if_stat_cache_t *sc;
552
553   if (cap_if_w != NULL) {
554     /* There's already a "Capture Interfaces" dialog box; reactivate it. */
555     reactivate_window(cap_if_w);
556     return;
557   }
558
559 #ifdef _WIN32
560   /* Is WPcap loaded? */
561   if (!has_wpcap) {
562     char *detailed_err;
563
564     detailed_err = cant_load_winpcap_err("Wireshark");
565     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", detailed_err);
566     g_free(detailed_err);
567     return;
568   }
569 #endif
570
571   /* LOAD THE INTERFACES */
572   if_list = capture_interface_list(&err, &err_str);
573   if_list = g_list_sort (if_list, if_list_comparator_alph);
574   if (if_list == NULL && err == CANT_GET_INTERFACE_LIST) {
575     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_str);
576     g_free(err_str);
577     return;
578   }
579
580 #ifdef HAVE_AIRPCAP
581   /* LOAD AIRPCAP INTERFACES */
582   airpcap_if_list = get_airpcap_interface_list(&err, &err_str);
583   if (airpcap_if_list == NULL)
584     airpcap_if_active = airpcap_if_selected = NULL;
585
586   decryption_cb = g_object_get_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_DECRYPTION_KEY);
587   update_decryption_mode_list(decryption_cb);
588
589   if (airpcap_if_list == NULL && err == CANT_GET_AIRPCAP_INTERFACE_LIST) {
590 #if 0
591     /* XXX - Do we need to show an error here? */
592     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_str);
593 #endif
594     g_free(err_str);
595   }
596
597   /* If no airpcap interface is present, gray everything */
598   if (airpcap_if_active == NULL) {
599     if (airpcap_if_list == NULL) {
600       /*No airpcap device found */
601       airpcap_enable_toolbar_widgets(airpcap_tb,FALSE);
602     } else {
603       /* default adapter is not airpcap... or is airpcap but is not found*/
604       airpcap_set_toolbar_stop_capture(airpcap_if_active);
605       airpcap_enable_toolbar_widgets(airpcap_tb,FALSE);
606     }
607   }
608
609   airpcap_set_toolbar_start_capture(airpcap_if_active);
610 #endif
611
612   cap_if_w = dlg_window_new("Wireshark: Capture Interfaces");  /* transient_for top_level */
613   gtk_window_set_destroy_with_parent (GTK_WINDOW(cap_if_w), TRUE);
614
615   tooltips = gtk_tooltips_new();
616
617   main_sw = gtk_scrolled_window_new(NULL, NULL);
618   gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(main_sw), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
619   gtk_container_add(GTK_CONTAINER(cap_if_w), main_sw);
620
621   main_vb = gtk_vbox_new(FALSE, 0);
622   gtk_container_set_border_width(GTK_CONTAINER(main_vb), 5);
623   gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(main_sw), main_vb);
624
625
626   if_tb = gtk_table_new(1,9, FALSE);
627   gtk_table_set_row_spacings(GTK_TABLE(if_tb), 3);
628   gtk_table_set_col_spacings(GTK_TABLE(if_tb), 3);
629   gtk_box_pack_start(GTK_BOX(main_vb), if_tb, FALSE, FALSE, 0);
630
631   row = 0;
632   height = 0;
633
634   /* This is the icon column, used to display which kind of interface we have */
635   if_lb = gtk_label_new("");
636   gtk_table_attach_defaults(GTK_TABLE(if_tb), if_lb, 0, 1, row, row+1);
637
638 #ifndef _WIN32
639   /*
640    * On Windows, device names are generally not meaningful - NT 5
641    * uses long blobs with GUIDs in them, for example - so we don't
642    * bother showing them.
643    */
644   if_lb = gtk_label_new("Device");
645   gtk_table_attach_defaults(GTK_TABLE(if_tb), if_lb, 1, 2, row, row+1);
646 #endif
647
648   if_lb = gtk_label_new("Description");
649   gtk_table_attach_defaults(GTK_TABLE(if_tb), if_lb, 2, 3, row, row+1);
650
651   if_lb = gtk_label_new(" IP ");
652   gtk_table_attach_defaults(GTK_TABLE(if_tb), if_lb, 3, 4, row, row+1);
653
654   if_lb = gtk_label_new("Packets");
655   gtk_table_attach_defaults(GTK_TABLE(if_tb), if_lb, 4, 5, row, row+1);
656
657   if_lb = gtk_label_new(" Packets/s ");
658   gtk_table_attach_defaults(GTK_TABLE(if_tb), if_lb, 5, 6, row, row+1);
659
660   stop_bt = gtk_button_new_from_stock(WIRESHARK_STOCK_CAPTURE_STOP);
661   gtk_tooltips_set_tip(tooltips, stop_bt,
662           "Stop a running capture.", NULL);
663 #ifdef _WIN32
664   gtk_table_attach_defaults(GTK_TABLE(if_tb), stop_bt, 6, 9, row, row+1);
665 #else
666   gtk_table_attach_defaults(GTK_TABLE(if_tb), stop_bt, 6, 8, row, row+1);
667 #endif
668   g_signal_connect(stop_bt, "clicked", G_CALLBACK(capture_stop_cb), NULL);
669
670   row++;
671   gtk_widget_size_request(stop_bt, &requisition);
672   height += requisition.height + 15;
673
674   /* Start gathering statistics (using dumpcap) */
675   sc = capture_stat_start(if_list);
676
677   /* List the interfaces */
678   for(ifs = 0; (curr = g_list_nth(if_list, ifs)); ifs++) {
679       g_string_assign(if_tool_str, "");
680       if_info = curr->data;
681
682       /* Continue if capture device is hidden */
683       if (prefs_is_capture_device_hidden(if_info->name)) {
684           continue;
685       }
686
687       if_dlg_data = g_malloc0(sizeof(if_dlg_data_t));
688       if_dlg_data->if_info = *if_info;
689
690       /* Kind of adaptor (icon) */
691 #ifdef HAVE_AIRPCAP
692       if(get_airpcap_if_from_name(airpcap_if_list,if_info->name) != NULL)
693         icon = xpm_to_widget(capture_airpcap_16_xpm);
694       else
695         icon = capture_get_if_icon(if_info);
696 #else
697       icon = capture_get_if_icon(if_info);
698 #endif
699
700       gtk_table_attach_defaults(GTK_TABLE(if_tb), icon, 0, 1, row, row+1);
701
702       /* device name */
703       if_dlg_data->device_lb = gtk_label_new(if_info->name);
704       if_dlg_data->device = if_info->name;
705 #ifndef _WIN32
706       gtk_misc_set_alignment(GTK_MISC(if_dlg_data->device_lb), 0.0f, 0.5f);
707       gtk_table_attach_defaults(GTK_TABLE(if_tb), if_dlg_data->device_lb, 1, 2, row, row+1);
708 #endif
709       g_string_append(if_tool_str, "Device: ");
710       g_string_append(if_tool_str, if_info->name);
711       g_string_append(if_tool_str, "\n");
712
713       /* description */
714       user_descr = capture_dev_user_descr_find(if_info->name);
715       if (user_descr) {
716         if_dlg_data->descr_lb = gtk_label_new(user_descr);
717         g_free (user_descr);
718       } else {
719         if (if_info->description)
720           if_dlg_data->descr_lb = gtk_label_new(if_info->description);
721         else
722           if_dlg_data->descr_lb = gtk_label_new("");
723       }
724       gtk_misc_set_alignment(GTK_MISC(if_dlg_data->descr_lb), 0.0f, 0.5f);
725       gtk_table_attach_defaults(GTK_TABLE(if_tb), if_dlg_data->descr_lb, 2, 3, row, row+1);
726
727       if (if_info->description) {
728         g_string_append(if_tool_str, "Description: ");
729         g_string_append(if_tool_str, if_info->description);
730         g_string_append(if_tool_str, "\n");
731       }
732
733       /* IP address */
734       /* Only one IP address will be shown, start with the first */
735       g_string_append(if_tool_str, "IP: ");
736       if_dlg_data->ip_lb = gtk_label_new("");
737       addr_str = set_ip_addr_label (if_info->ip_addr, if_dlg_data->ip_lb, 0);
738       if (addr_str) {
739         gtk_widget_set_sensitive(if_dlg_data->ip_lb, TRUE);
740         g_string_append(if_tool_str, addr_str);
741       } else {
742         gtk_widget_set_sensitive(if_dlg_data->ip_lb, FALSE);
743         g_string_append(if_tool_str, "unknown");
744       }
745       eb = gtk_event_box_new ();
746       gtk_container_add(GTK_CONTAINER(eb), if_dlg_data->ip_lb);
747       gtk_table_attach_defaults(GTK_TABLE(if_tb), eb, 3, 4, row, row+1);
748       if (g_slist_length(if_info->ip_addr) > 1) {
749         /* More than one IP address, make it possible to toggle */
750         g_object_set_data(G_OBJECT(eb), CAPTURE_IF_IP_ADDR_LABEL, if_dlg_data->ip_lb);
751         g_signal_connect(eb, "enter-notify-event", G_CALLBACK(ip_label_enter_cb), NULL);
752         g_signal_connect(eb, "leave-notify-event", G_CALLBACK(ip_label_leave_cb), NULL);
753         g_signal_connect(eb, "button-press-event", G_CALLBACK(ip_label_press_cb), if_info->ip_addr);
754       }
755       g_string_append(if_tool_str, "\n");
756
757       /* packets */
758       if_dlg_data->curr_lb = gtk_label_new("-");
759       gtk_table_attach_defaults(GTK_TABLE(if_tb), if_dlg_data->curr_lb, 4, 5, row, row+1);
760
761       /* packets/s */
762       if_dlg_data->last_lb = gtk_label_new("-");
763       gtk_table_attach_defaults(GTK_TABLE(if_tb), if_dlg_data->last_lb, 5, 6, row, row+1);
764
765       /* capture button */
766       if_dlg_data->capture_bt = gtk_button_new_from_stock(WIRESHARK_STOCK_CAPTURE_START);
767           g_signal_connect(if_dlg_data->capture_bt, "clicked", G_CALLBACK(capture_do_cb), if_dlg_data);
768       tmp_str = g_strdup_printf("Immediately start a capture from this interface:\n\n%s", if_tool_str->str);
769       gtk_tooltips_set_tip(tooltips, if_dlg_data->capture_bt,
770           tmp_str, NULL);
771       g_free(tmp_str);
772       gtk_table_attach_defaults(GTK_TABLE(if_tb), if_dlg_data->capture_bt, 6, 7, row, row+1);
773
774       /* prepare button */
775       if_dlg_data->prepare_bt = gtk_button_new_from_stock(WIRESHARK_STOCK_CAPTURE_OPTIONS);
776       g_signal_connect(if_dlg_data->prepare_bt, "clicked", G_CALLBACK(capture_prepare_cb), if_dlg_data);
777       gtk_tooltips_set_tip(tooltips, if_dlg_data->prepare_bt,
778           "Open the capture options dialog with this interface selected.", NULL);
779       gtk_table_attach_defaults(GTK_TABLE(if_tb), if_dlg_data->prepare_bt, 7, 8, row, row+1);
780
781       /* details button */
782 #ifdef _WIN32
783       if_dlg_data->details_bt = gtk_button_new_from_stock(WIRESHARK_STOCK_CAPTURE_DETAILS);
784       gtk_tooltips_set_tip(tooltips, if_dlg_data->details_bt,
785           "Open the capture details dialog of this interface.", NULL);
786       gtk_table_attach_defaults(GTK_TABLE(if_tb), if_dlg_data->details_bt, 8, 9, row, row+1);
787       if (capture_if_has_details(if_dlg_data->device)) {
788         g_signal_connect(if_dlg_data->details_bt, "clicked", G_CALLBACK(capture_details_cb), if_dlg_data);
789       } else {
790         gtk_widget_set_sensitive(if_dlg_data->details_bt, FALSE);
791       }
792 #endif
793
794       if_data = g_list_append(if_data, if_dlg_data);
795
796       row++;
797       if (row <= 10) {
798           /* Lets add up 10 rows of interfaces, otherwise the window may become too high */
799           gtk_widget_size_request(GTK_WIDGET(if_dlg_data->prepare_bt), &requisition);
800           height += requisition.height;
801       }
802   }
803
804   g_string_free(if_tool_str, TRUE);
805
806   /* Button row: close and help button */
807   bbox = dlg_button_row_new(GTK_STOCK_CLOSE, GTK_STOCK_HELP, NULL);
808   gtk_box_pack_start(GTK_BOX(main_vb), bbox, FALSE, FALSE, 5);
809
810   close_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CLOSE);
811   window_set_cancel_button(cap_if_w, close_bt, window_cancel_button_cb);
812   gtk_tooltips_set_tip(tooltips, close_bt, "Close this window.", NULL);
813
814   help_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_HELP);
815   g_signal_connect(help_bt, "clicked", G_CALLBACK(topic_cb), (gpointer)(HELP_CAPTURE_INTERFACES_DIALOG));
816
817   gtk_widget_size_request(GTK_WIDGET(close_bt), &requisition);
818   /* height + static offset + what the GTK MS Windows Engine needs in addition per interface */
819   height += requisition.height + 20 + ifs;
820   gtk_window_set_default_size(GTK_WINDOW(cap_if_w), -1, height);
821
822   gtk_widget_grab_default(close_bt);
823
824   g_signal_connect(cap_if_w, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
825   g_signal_connect(cap_if_w, "destroy", G_CALLBACK(capture_if_destroy_cb), sc);
826
827   gtk_widget_show_all(cap_if_w);
828   window_present(cap_if_w);
829
830   set_capture_if_dialog_for_capture_in_progress(g_capture_in_progress);
831
832     /* update the interface list every 1000ms */
833   timer_id = g_timeout_add(1000, update_all, sc);
834 }
835
836 #else /* HAVE_LIBPCAP */
837
838 void
839 set_capture_if_dialog_for_capture_in_progress(gboolean capture_in_progress _U_)
840 {
841 }
842
843 #endif /* HAVE_LIBPCAP */