Fix bug http://bugs.wireshark.org/bugzilla/show_bug.cgi?id=1757 :
[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 #ifdef HAVE_LIBPCAP
30
31 #ifdef HAVE_SYS_WAIT_H
32 # include <sys/wait.h>
33 #endif
34
35
36 #include <gtk/gtk.h>
37
38 #include "globals.h"
39 #include "capture-pcap-util.h"
40
41 #ifdef _WIN32
42 #include "capture-wpcap.h"
43 #endif
44
45 #include "compat_macros.h"
46 #include "simple_dialog.h"
47 #include "capture.h"
48 #include "capture_dlg.h"
49 #include "capture_if_details_dlg.h"
50 #include "capture_errs.h"
51 #include "capture_ui_utils.h"
52 #include "recent.h"
53 #include <epan/prefs.h>
54
55 #include "gui_utils.h"
56 #include "dlg_utils.h"
57
58 #include "main.h"
59 #include "wtap.h"
60 #include "help_dlg.h"
61 #include "toolbar.h"
62 #include "keys.h"
63
64 #include "webbrowser.h"
65
66 #ifdef HAVE_AIRPCAP
67 #include "../image/toolbar/capture_airpcap_16.xpm"
68 #endif
69 #include "../image/toolbar/capture_ethernet_16.xpm"
70
71 /* new buttons to be used instead of labels for 'Capture','Prepare',' */
72 #include "../image/toolbar/capture_capture_16.xpm"
73 #include "../image/toolbar/capture_prepare_16.xpm"
74 #include "../image/toolbar/capture_details_16.xpm"
75
76
77 #ifdef HAVE_AIRPCAP
78 #include <airpcap.h>
79 #include "airpcap_loader.h"
80 #include "airpcap_gui_utils.h"
81 #include "airpcap_dlg.h"
82 #endif
83
84 /*
85  * Keep a static pointer to the current "Capture Interfaces" window, if
86  * any, so that if somebody tries to do "Capture:Start" while there's
87  * already a "Capture Interfaces" window up, we just pop up the existing
88  * one, rather than creating a new one.
89  */
90 static GtkWidget *cap_if_w;
91 #ifdef HAVE_AIRPCAP
92 static GtkWidget *cap_air_w;
93 #endif
94
95 GList           *if_data = NULL;
96
97 guint           timer_id;
98
99 GtkWidget       *stop_bt;
100
101 GList           *if_list;
102
103 /*
104  * Timeout, in milliseconds, for reads from the stream of captured packets.
105  */
106 #define CAP_READ_TIMEOUT        250
107
108
109 /* the "runtime" data of one interface */
110 typedef struct if_dlg_data_s {
111     GtkWidget   *device_lb;
112     GtkWidget   *descr_lb;
113     GtkWidget   *ip_lb;
114     GtkWidget   *curr_lb;
115     GtkWidget   *last_lb;
116     GtkWidget   *capture_bt;
117     GtkWidget   *prepare_bt;
118 #ifdef _WIN32
119     GtkWidget   *details_bt;
120 #endif
121     guint32     last_packets;
122     gchar       *device;
123     if_info_t   if_info;
124 } if_dlg_data_t;
125
126
127 /* start capture button was pressed */
128 static void
129 capture_do_cb(GtkWidget *capture_bt _U_, gpointer if_data)
130 {
131   if_dlg_data_t *if_dlg_data = if_data;
132
133 #ifdef HAVE_AIRPCAP
134   airpcap_if_active = get_airpcap_if_from_name(airpcap_if_list, if_dlg_data->if_info.name);
135   airpcap_if_selected = airpcap_if_active;
136 #endif
137
138   if (capture_opts->iface)
139     g_free(capture_opts->iface);
140   if (capture_opts->iface_descr)
141     g_free(capture_opts->iface_descr);
142
143   capture_opts->iface = g_strdup(if_dlg_data->device);
144   capture_opts->iface_descr = get_interface_descriptive_name(capture_opts->iface);
145
146   /* XXX - remove this? */
147   if (capture_opts->save_file) {
148     g_free(capture_opts->save_file);
149     capture_opts->save_file = NULL;
150   }
151
152   /* stop capturing from all interfaces, we are going to do real work now ... */
153   window_destroy(cap_if_w);
154
155   capture_start_cb(NULL, NULL);
156 }
157
158
159 /* prepare capture button was pressed */
160 static void
161 capture_prepare_cb(GtkWidget *prepare_bt _U_, gpointer if_data)
162 {
163   if_dlg_data_t *if_dlg_data = if_data;
164
165   if (capture_opts->iface)
166     g_free(capture_opts->iface);
167   if (capture_opts->iface_descr)
168     g_free(capture_opts->iface_descr);
169
170   capture_opts->iface = g_strdup(if_dlg_data->device);
171   capture_opts->iface_descr = get_interface_descriptive_name(capture_opts->iface);
172
173   /* stop capturing from all interfaces, we are going to do real work now ... */
174   window_destroy(cap_if_w);
175
176   capture_prep_cb(NULL, NULL);
177 }
178
179
180 #ifdef _WIN32
181 /* capture details button was pressed */
182 static void
183 capture_details_cb(GtkWidget *details_bt _U_, gpointer if_data)
184 {
185   if_dlg_data_t *if_dlg_data = if_data;
186
187
188   capture_if_details_open(if_dlg_data->device);
189 }
190 #endif
191
192 /* update a single interface */
193 void
194 update_if(if_dlg_data_t *if_dlg_data, if_stat_cache_t *sc)
195 {
196   struct pcap_stat stats;
197   gchar *str;
198   guint diff;
199
200
201   /* pcap_stats() stats values differ on libpcap and winpcap!
202    * libpcap: returns the number of packets since pcap_open_live
203    * winpcap: returns the number of packets since the last pcap_stats call
204    * XXX - if that's true, that's a bug, and should be fixed; "pcap_stats()"
205    * is supposed to work the same way on all platforms, including Windows.
206    * Note that the WinPcap 3.0 documentation says "The values represent
207    * packet statistics from the start of the run to the time of the call."
208    * (Note also that some versions of libpcap, on some versions of UN*X,
209    * have the same bug.)
210    */
211   if (sc) {
212     if(capture_stats(sc, if_dlg_data->device, &stats)) {
213 #ifdef _WIN32
214       diff = stats.ps_recv - if_dlg_data->last_packets;
215       if_dlg_data->last_packets = stats.ps_recv;
216 #else
217       diff = stats.ps_recv;
218       if_dlg_data->last_packets = stats.ps_recv + if_dlg_data->last_packets;
219 #endif
220
221       str = g_strdup_printf("%u", if_dlg_data->last_packets);
222       gtk_label_set_text(GTK_LABEL(if_dlg_data->curr_lb), str);
223       g_free(str);
224       str = g_strdup_printf("%u", diff);
225       gtk_label_set_text(GTK_LABEL(if_dlg_data->last_lb), str);
226       g_free(str);
227
228       gtk_widget_set_sensitive(if_dlg_data->curr_lb, diff);
229       gtk_widget_set_sensitive(if_dlg_data->last_lb, diff);
230     } else {
231       gtk_label_set_text(GTK_LABEL(if_dlg_data->curr_lb), "error");
232       gtk_label_set_text(GTK_LABEL(if_dlg_data->last_lb), "error");
233     }
234   }
235 }
236
237 /* update all interfaces */
238 static gboolean
239 update_all(gpointer data)
240 {
241     GList *curr;
242     int ifs;
243     if_stat_cache_t *sc = data;
244
245     if(!cap_if_w) {
246         return FALSE;
247     }
248
249     for(ifs = 0; (curr = g_list_nth(if_data, ifs)); ifs++) {
250         update_if(curr->data, sc);
251     }
252
253     return TRUE;
254 }
255
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     if(cap_if_w) {
265         gtk_widget_set_sensitive(stop_bt, capture_in_progress);
266
267         for(ifs = 0; (curr = g_list_nth(if_data, ifs)); ifs++) {
268             if_dlg_data_t *if_dlg_data = curr->data;
269
270             gtk_widget_set_sensitive(if_dlg_data->capture_bt, !capture_in_progress);
271             gtk_widget_set_sensitive(if_dlg_data->prepare_bt, !capture_in_progress);
272         }
273     }
274 }
275
276
277 /* the window was closed, cleanup things */
278 static void
279 capture_if_destroy_cb(GtkWidget *win _U_, gpointer user_data)
280 {
281     GList *curr;
282     int ifs;
283     if_stat_cache_t *sc = user_data;
284
285     gtk_timeout_remove(timer_id);
286
287     for(ifs = 0; (curr = g_list_nth(if_data, ifs)); ifs++) {
288         g_free(curr->data);
289     }
290
291     if_data = NULL;
292
293     free_interface_list(if_list);
294
295     /* Note that we no longer have a "Capture Options" dialog box. */
296     cap_if_w = NULL;
297
298     capture_stat_stop(sc);
299
300 #ifdef HAVE_AIRPCAP
301     airpcap_set_toolbar_stop_capture(airpcap_if_active);
302 #endif
303 }
304
305 GtkWidget*
306 combo_channel_new(void)
307 {
308           GtkWidget* channel_cb;
309           GList*     popdown;
310
311
312       channel_cb = gtk_combo_new();
313           gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(channel_cb)->entry), "1");
314
315           popdown = NULL;
316
317           popdown = g_list_append(popdown, "1");
318       popdown = g_list_append(popdown, "2");
319       popdown = g_list_append(popdown, "3");
320       popdown = g_list_append(popdown, "4");
321           popdown = g_list_append(popdown, "5");
322           popdown = g_list_append(popdown, "6");
323           popdown = g_list_append(popdown, "7");
324           popdown = g_list_append(popdown, "8");
325           popdown = g_list_append(popdown, "9");
326           popdown = g_list_append(popdown, "10");
327           popdown = g_list_append(popdown, "11");
328           popdown = g_list_append(popdown, "12");
329           popdown = g_list_append(popdown, "13");
330           popdown = g_list_append(popdown, "14");
331
332       gtk_combo_set_popdown_strings( GTK_COMBO(channel_cb), popdown) ;
333
334           #if GTK_MAJOR_VERSION < 2
335           gtk_widget_set_usize( GTK_WIDGET(channel_cb),
336                                   45,
337                                   10 );
338           #else
339           gtk_widget_set_size_request( GTK_WIDGET(channel_cb),
340                                   45,
341                                   10 );
342       #endif
343
344
345           return channel_cb;
346 }
347
348 /*
349  * Sorts the Interface List in alphabetical order
350  */
351 gint if_list_comparator_alph (const void *first_arg, const void *second_arg){
352   const if_info_t *first = first_arg, *second = second_arg;
353
354   if (first != NULL && first->description != NULL &&
355       second != NULL && second->description != NULL) {
356     return g_strcasecmp(first->description, second->description);
357   } else {
358     return 0;
359   }
360 }
361
362 /* start getting capture stats from all interfaces */
363 void
364 capture_if_cb(GtkWidget *w _U_, gpointer d _U_)
365 {
366   GtkWidget     *main_vb,
367                                 *main_sw,
368                                 *bbox,
369                                 *close_bt,
370                                 *help_bt,
371                                 *icon;
372
373 #ifdef HAVE_AIRPCAP
374   GtkWidget             *decryption_cm;
375 #endif
376
377   GtkWidget     *if_tb;
378   GtkWidget     *if_lb;
379 #if GTK_MAJOR_VERSION < 2
380   GtkAccelGroup *accel_group;
381 #endif
382   GtkTooltips   *tooltips;
383   int           err;
384   gchar         *err_str;
385   GtkRequisition requisition;
386   int           row, height;
387   if_dlg_data_t *if_dlg_data;
388   int           ifs;
389   GList         *curr;
390   if_info_t     *if_info;
391   GSList        *curr_ip;
392   if_addr_t     *ip_addr;
393   GString       *if_tool_str = g_string_new("");
394   gchar         *tmp_str;
395   if_stat_cache_t *sc;
396
397   if (cap_if_w != NULL) {
398     /* There's already a "Capture Interfaces" dialog box; reactivate it. */
399     reactivate_window(cap_if_w);
400     return;
401   }
402
403 #ifdef _WIN32
404   /* Is WPcap loaded? */
405   if (!has_wpcap) {
406     char *detailed_err;
407
408     detailed_err = cant_load_winpcap_err("Wireshark");
409     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", detailed_err);
410     g_free(detailed_err);
411     return;
412   }
413 #endif
414
415   /* LOAD THE INTERFACES */
416   if_list = capture_interface_list(&err, &err_str);
417   if_list = g_list_sort (if_list, if_list_comparator_alph);
418   if (if_list == NULL && err == CANT_GET_INTERFACE_LIST) {
419     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_str);
420     g_free(err_str);
421     return;
422   }
423
424 #ifdef HAVE_AIRPCAP
425   /* LOAD AIRPCAP INTERFACES */
426   airpcap_if_list = get_airpcap_interface_list(&err, &err_str);
427   if (airpcap_if_list == NULL)
428     airpcap_if_active = airpcap_if_selected = NULL;
429
430   decryption_cm = OBJECT_GET_DATA(airpcap_tb,AIRPCAP_TOOLBAR_DECRYPTION_KEY);
431   update_decryption_mode_list(decryption_cm);
432
433   if (airpcap_if_list == NULL && err == CANT_GET_AIRPCAP_INTERFACE_LIST) {
434 #if 0
435     /* XXX - Do we need to show an error here? */
436     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_str);
437 #endif
438     g_free(err_str);
439   }
440
441   /* If no airpcap interface is present, gray everything */
442   if (airpcap_if_active == NULL) {
443     if (airpcap_if_list == NULL) {
444       /*No airpcap device found */
445       airpcap_enable_toolbar_widgets(airpcap_tb,FALSE);
446     } else {
447       /* default adapter is not airpcap... or is airpcap but is not found*/
448       airpcap_set_toolbar_stop_capture(airpcap_if_active);
449       airpcap_enable_toolbar_widgets(airpcap_tb,FALSE);
450     }
451   }
452
453   airpcap_set_toolbar_start_capture(airpcap_if_active);
454 #endif
455
456   cap_if_w = window_new(GTK_WINDOW_TOPLEVEL, "Wireshark: Capture Interfaces");
457
458   tooltips = gtk_tooltips_new();
459
460 #if GTK_MAJOR_VERSION < 2
461   /* Accelerator group for the accelerators (or, as they're called in
462      Windows and, I think, in Motif, "mnemonics"; Alt+<key> is a mnemonic,
463      Ctrl+<key> is an accelerator). */
464   accel_group = gtk_accel_group_new();
465   gtk_window_add_accel_group(GTK_WINDOW(cap_if_w), accel_group);
466 #endif
467
468   main_sw = gtk_scrolled_window_new(NULL, NULL);
469   gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(main_sw), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
470   gtk_container_add(GTK_CONTAINER(cap_if_w), main_sw);
471
472   main_vb = gtk_vbox_new(FALSE, 0);
473   gtk_container_border_width(GTK_CONTAINER(main_vb), 5);
474   gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(main_sw), main_vb);
475
476
477   if_tb = gtk_table_new(1,9, FALSE);
478   gtk_table_set_row_spacings(GTK_TABLE(if_tb), 3);
479   gtk_table_set_col_spacings(GTK_TABLE(if_tb), 3);
480   gtk_box_pack_start(GTK_BOX(main_vb), if_tb, FALSE, FALSE, 0);
481
482   row = 0;
483   height = 0;
484
485   /* This is the icon column, used to display which kind of interface we have */
486   if_lb = gtk_label_new("");
487   gtk_table_attach_defaults(GTK_TABLE(if_tb), if_lb, 0, 1, row, row+1);
488
489 #ifndef _WIN32
490   /*
491    * On Windows, device names are generally not meaningful - NT 5
492    * uses long blobs with GUIDs in them, for example - so we don't
493    * bother showing them.
494    */
495   if_lb = gtk_label_new("Device");
496   gtk_table_attach_defaults(GTK_TABLE(if_tb), if_lb, 1, 2, row, row+1);
497 #endif
498
499   if_lb = gtk_label_new("Description");
500   gtk_table_attach_defaults(GTK_TABLE(if_tb), if_lb, 2, 3, row, row+1);
501
502   if_lb = gtk_label_new(" IP ");
503   gtk_table_attach_defaults(GTK_TABLE(if_tb), if_lb, 3, 4, row, row+1);
504
505   if_lb = gtk_label_new("Packets");
506   gtk_table_attach_defaults(GTK_TABLE(if_tb), if_lb, 4, 5, row, row+1);
507
508   if_lb = gtk_label_new(" Packets/s ");
509   gtk_table_attach_defaults(GTK_TABLE(if_tb), if_lb, 5, 6, row, row+1);
510
511   stop_bt = BUTTON_NEW_FROM_STOCK(WIRESHARK_STOCK_CAPTURE_STOP);
512   gtk_tooltips_set_tip(tooltips, stop_bt,
513           "Stop a running capture.", NULL);
514 #ifdef _WIN32
515   gtk_table_attach_defaults(GTK_TABLE(if_tb), stop_bt, 6, 9, row, row+1);
516 #else
517   gtk_table_attach_defaults(GTK_TABLE(if_tb), stop_bt, 6, 8, row, row+1);
518 #endif
519   SIGNAL_CONNECT(stop_bt, "clicked", capture_stop_cb, NULL);
520
521   row++;
522   gtk_widget_size_request(stop_bt, &requisition);
523   height += requisition.height + 15;
524
525   /* Start gathering statistics (using dumpcap) */
526   sc = capture_stat_start(if_list);
527
528   /* List the interfaces */
529   for(ifs = 0; (curr = g_list_nth(if_list, ifs)); ifs++) {
530       g_string_assign(if_tool_str, "");
531       if_info = curr->data;
532       if_dlg_data = g_malloc0(sizeof(if_dlg_data_t));
533       if_dlg_data->if_info = *if_info;
534
535       /* Kind of adaptor (icon) */
536 #ifdef HAVE_AIRPCAP
537       if(get_airpcap_if_from_name(airpcap_if_list,if_info->name) != NULL)
538         icon = xpm_to_widget(capture_airpcap_16_xpm);
539       else
540         icon = xpm_to_widget(capture_ethernet_16_xpm);
541 #else
542       icon = xpm_to_widget(capture_ethernet_16_xpm);
543 #endif
544
545       gtk_table_attach_defaults(GTK_TABLE(if_tb), icon, 0, 1, row, row+1);
546
547       /* device name */
548       if_dlg_data->device_lb = gtk_label_new(if_info->name);
549       if_dlg_data->device = if_info->name;
550 #ifndef _WIN32
551       gtk_misc_set_alignment(GTK_MISC(if_dlg_data->device_lb), 0.0, 0.5);
552       gtk_table_attach_defaults(GTK_TABLE(if_tb), if_dlg_data->device_lb, 1, 2, row, row+1);
553 #endif
554       g_string_append(if_tool_str, "Device: ");
555       g_string_append(if_tool_str, if_info->name);
556       g_string_append(if_tool_str, "\n");
557
558       /* description */
559       if (if_info->description != NULL)
560         if_dlg_data->descr_lb = gtk_label_new(if_info->description);
561       else
562         if_dlg_data->descr_lb = gtk_label_new("");
563       gtk_misc_set_alignment(GTK_MISC(if_dlg_data->descr_lb), 0.0, 0.5);
564       gtk_table_attach_defaults(GTK_TABLE(if_tb), if_dlg_data->descr_lb, 2, 3, row, row+1);
565
566       if (if_info->description) {
567         g_string_append(if_tool_str, "Description: ");
568         g_string_append(if_tool_str, if_info->description);
569         g_string_append(if_tool_str, "\n");
570       }
571
572       /* IP address */
573       /* only the first IP address will be shown */
574       g_string_append(if_tool_str, "IP: ");
575       curr_ip = g_slist_nth(if_info->ip_addr, 0);
576       if(curr_ip) {
577         ip_addr = (if_addr_t *)curr_ip->data;
578         switch (ip_addr->type) {
579
580         case AT_IPv4:
581           tmp_str = ip_to_str((guint8 *)&ip_addr->ip_addr.ip4_addr);
582           break;
583
584         case AT_IPv6:
585           tmp_str = ip6_to_str((struct e_in6_addr *)&ip_addr->ip_addr.ip6_addr);
586           break;
587
588         default:
589           g_assert_not_reached();
590           tmp_str = NULL;
591         }
592         if_dlg_data->ip_lb = gtk_label_new(tmp_str);
593         gtk_widget_set_sensitive(if_dlg_data->ip_lb, TRUE);
594         g_string_append(if_tool_str, tmp_str);
595       } else {
596         if_dlg_data->ip_lb = gtk_label_new("unknown");
597         gtk_widget_set_sensitive(if_dlg_data->ip_lb, FALSE);
598         g_string_append(if_tool_str, "unknown");
599       }
600       gtk_table_attach_defaults(GTK_TABLE(if_tb), if_dlg_data->ip_lb, 3, 4, row, row+1);
601       g_string_append(if_tool_str, "\n");
602
603       /* packets */
604       if_dlg_data->curr_lb = gtk_label_new("-");
605       gtk_table_attach_defaults(GTK_TABLE(if_tb), if_dlg_data->curr_lb, 4, 5, row, row+1);
606
607       /* packets/s */
608       if_dlg_data->last_lb = gtk_label_new("-");
609       gtk_table_attach_defaults(GTK_TABLE(if_tb), if_dlg_data->last_lb, 5, 6, row, row+1);
610
611       /* capture button */
612       if_dlg_data->capture_bt = BUTTON_NEW_FROM_STOCK(WIRESHARK_STOCK_CAPTURE_START);
613           SIGNAL_CONNECT(if_dlg_data->capture_bt, "clicked", capture_do_cb, if_dlg_data);
614       tmp_str = g_strdup_printf("Immediately start a capture from this interface:\n\n%s", if_tool_str->str);
615       gtk_tooltips_set_tip(tooltips, if_dlg_data->capture_bt,
616           tmp_str, NULL);
617       g_free(tmp_str);
618       gtk_table_attach_defaults(GTK_TABLE(if_tb), if_dlg_data->capture_bt, 6, 7, row, row+1);
619
620       /* prepare button */
621       if_dlg_data->prepare_bt = BUTTON_NEW_FROM_STOCK(WIRESHARK_STOCK_CAPTURE_OPTIONS);
622       SIGNAL_CONNECT(if_dlg_data->prepare_bt, "clicked", capture_prepare_cb, if_dlg_data);
623       gtk_tooltips_set_tip(tooltips, if_dlg_data->prepare_bt,
624           "Open the capture options dialog with this interface selected.", NULL);
625       gtk_table_attach_defaults(GTK_TABLE(if_tb), if_dlg_data->prepare_bt, 7, 8, row, row+1);
626
627       /* details button */
628 #ifdef _WIN32
629       if_dlg_data->details_bt = BUTTON_NEW_FROM_STOCK(WIRESHARK_STOCK_CAPTURE_DETAILS);
630           SIGNAL_CONNECT(if_dlg_data->details_bt, "clicked", capture_details_cb, if_dlg_data);
631       gtk_tooltips_set_tip(tooltips, if_dlg_data->details_bt,
632           "Open the capture details dialog of this interface.", NULL);
633       gtk_table_attach_defaults(GTK_TABLE(if_tb), if_dlg_data->details_bt, 8, 9, row, row+1);
634 #endif
635
636       if_data = g_list_append(if_data, if_dlg_data);
637
638       row++;
639       if (row <= 10) {
640           /* Lets add up 10 rows of interfaces, otherwise the window may become too high */
641           gtk_widget_size_request(GTK_WIDGET(if_dlg_data->prepare_bt), &requisition);
642           height += requisition.height;
643       }
644   }
645
646   g_string_free(if_tool_str, TRUE);
647
648   /* Button row: close button */
649   if(topic_available(HELP_CAPTURE_INTERFACES_DIALOG)) {
650     bbox = dlg_button_row_new(GTK_STOCK_CLOSE, GTK_STOCK_HELP, NULL);
651   } else {
652     bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL);
653   }
654   gtk_box_pack_start(GTK_BOX(main_vb), bbox, FALSE, FALSE, 5);
655
656   close_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_CLOSE);
657   window_set_cancel_button(cap_if_w, close_bt, window_cancel_button_cb);
658   gtk_tooltips_set_tip(tooltips, close_bt, "Close this window.", NULL);
659
660   if(topic_available(HELP_CAPTURE_INTERFACES_DIALOG)) {
661     help_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_HELP);
662     SIGNAL_CONNECT(help_bt, "clicked", topic_cb, HELP_CAPTURE_INTERFACES_DIALOG);
663   }
664
665   gtk_widget_size_request(GTK_WIDGET(close_bt), &requisition);
666   /* height + static offset + what GTK-Wimp needs in addition per interface */
667   height += requisition.height + 20 + ifs;
668   gtk_window_set_default_size(GTK_WINDOW(cap_if_w), -1, height);
669
670   gtk_widget_grab_default(close_bt);
671
672   SIGNAL_CONNECT(cap_if_w, "delete_event", window_delete_event_cb, NULL);
673   SIGNAL_CONNECT(cap_if_w, "destroy", capture_if_destroy_cb, sc);
674
675   gtk_widget_show_all(cap_if_w);
676   window_present(cap_if_w);
677
678   set_capture_if_dialog_for_capture_in_progress(is_capture_in_progress());
679
680     /* update the interface list every 1000ms */
681   timer_id = gtk_timeout_add(1000, update_all, sc);
682 }
683
684
685 #endif /* HAVE_LIBPCAP */