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