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