In Wireshark and TShark, run dumpcap to get interface lists and lists of
[obnox/wireshark/wip.git] / gtk / capture_dlg.c
1 /* capture_dlg.c
2  * Routines for packet capture windows
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_TYPES_H
32 #include <sys/types.h>
33 #endif
34
35 #include <string.h>
36
37 #include <stdio.h>
38
39 #include <gtk/gtk.h>
40
41 #include <epan/packet.h>
42 #include <epan/addr_resolv.h>
43 #include <epan/prefs.h>
44 #include <epan/filesystem.h>
45
46 #include "../capture.h"
47 #include "../globals.h"
48 #include "../capture_errs.h"
49 #include "../capture_ifinfo.h"
50 #include "../simple_dialog.h"
51 #include "../capture-pcap-util.h"
52 #include "../capture_ui_utils.h"
53 #include "../ringbuffer.h"
54
55 #include "gtk/main.h"
56 #include "gtk/menus.h"
57 #include "gtk/gui_utils.h"
58 #include "gtk/capture_dlg.h"
59 #include "gtk/filter_dlg.h"
60 #include "gtk/dlg_utils.h"
61 #include "gtk/file_dlg.h"
62 #include "gtk/stock_icons.h"
63 #include "gtk/capture_file_dlg.h"
64 #include "gtk/help_dlg.h"
65 #include "gtk/gtkglobals.h"
66 #include "gtk/capture_globals.h"
67 #include "gtk/cfilter_combo_utils.h"
68
69 #ifdef _WIN32
70 #include "../capture-wpcap.h"
71 #endif
72
73 #include "gtk/keys.h"
74
75 #ifdef HAVE_AIRPCAP
76 #include <airpcap.h>
77 #include "airpcap_loader.h"
78 #include "airpcap_gui_utils.h"
79 #include "airpcap_dlg.h"
80 #endif
81
82 /* Capture callback data keys */
83 #define E_CAP_IFACE_KEY                 "cap_iface"
84 #define E_CAP_IFACE_IP_KEY              "cap_iface_ip"
85 #define E_CAP_SNAP_CB_KEY               "cap_snap_cb"
86 #define E_CAP_LT_OM_KEY                 "cap_lt_om"
87 #define E_CAP_LT_OM_LABEL_KEY           "cap_lt_om_label"
88 #ifdef _WIN32
89 #define E_CAP_BUFFER_SIZE_SB_KEY        "cap_buffer_size_sb"
90 #endif
91 #define E_CAP_SNAP_SB_KEY               "cap_snap_sb"
92 #define E_CAP_PROMISC_KEY               "cap_promisc"
93 #define E_CAP_PCAP_NG_KEY               "cap_pcap_ng"
94 #define E_CAP_FILT_KEY                  "cap_filter_te"
95 #define E_CAP_FILE_TE_KEY               "cap_file_te"
96 #define E_CAP_MULTI_FILES_ON_CB_KEY     "cap_multi_files_on_cb"
97 #define E_CAP_RING_FILESIZE_CB_KEY      "cap_ring_filesize_cb"
98 #define E_CAP_RING_FILESIZE_SB_KEY      "cap_ring_filesize_sb"
99 #define E_CAP_RING_FILESIZE_CBX_KEY     "cap_ring_filesize_cbx"
100 #define E_CAP_FILE_DURATION_CB_KEY      "cap_file_duration_cb"
101 #define E_CAP_FILE_DURATION_SB_KEY      "cap_file_duration_sb"
102 #define E_CAP_FILE_DURATION_CBX_KEY     "cap_file_duration_cbx"
103 #define E_CAP_RING_NBF_CB_KEY           "cap_ring_nbf_cb"
104 #define E_CAP_RING_NBF_SB_KEY           "cap_ring_nbf_sb"
105 #define E_CAP_RING_NBF_LB_KEY           "cap_ring_nbf_lb"
106 #define E_CAP_STOP_FILES_CB_KEY         "cap_stop_files_cb"
107 #define E_CAP_STOP_FILES_SB_KEY         "cap_stop_files_sb"
108 #define E_CAP_STOP_FILES_LB_KEY         "cap_stop_files_lb"
109 #define E_CAP_SYNC_KEY                  "cap_sync"
110 #define E_CAP_AUTO_SCROLL_KEY           "cap_auto_scroll"
111 #define E_CAP_HIDE_INFO_KEY             "cap_hide_info"
112 #define E_CAP_STOP_PACKETS_CB_KEY       "cap_stop_packets_cb"
113 #define E_CAP_STOP_PACKETS_SB_KEY       "cap_stop_packets_sb"
114 #define E_CAP_STOP_PACKETS_LB_KEY       "cap_stop_packets_lb"
115 #define E_CAP_STOP_FILESIZE_CB_KEY      "cap_stop_filesize_cb"
116 #define E_CAP_STOP_FILESIZE_SB_KEY      "cap_stop_filesize_sb"
117 #define E_CAP_STOP_FILESIZE_CBX_KEY     "cap_stop_filesize_cbx"
118 #define E_CAP_STOP_DURATION_CB_KEY      "cap_stop_duration_cb"
119 #define E_CAP_STOP_DURATION_SB_KEY      "cap_stop_duration_sb"
120 #define E_CAP_STOP_DURATION_CBX_KEY     "cap_stop_duration_cbx"
121 #define E_CAP_M_RESOLVE_KEY             "cap_m_resolve"
122 #define E_CAP_N_RESOLVE_KEY             "cap_n_resolve"
123 #define E_CAP_T_RESOLVE_KEY             "cap_t_resolve"
124
125 #ifdef HAVE_PCAP_REMOTE
126 #define E_CAP_IFTYPE_CBX_KEY            "cap_iftype_cbx"
127 #define E_CAP_IF_LIST_KEY               "cap_if_list"
128 #define E_CAP_DATATX_UDP_CB_KEY         "cap_datatx_udp_cb"
129 #define E_CAP_NOCAP_RPCAP_CB_KEY        "cap_nocap_rpcap_cb"
130 #define E_CAP_REMOTE_DIALOG_PTR_KEY     "cap_remote_dialog"
131 #define E_CAP_REMOTE_CALLER_PTR_KEY     "cap_remote_caller"
132 #define E_REMOTE_HOST_TE_KEY            "cap_remote_host"
133 #define E_REMOTE_PORT_TE_KEY            "cap_remote_port"
134 #define E_REMOTE_AUTH_NULL_KEY          "cap_remote_auth_null"
135 #define E_REMOTE_AUTH_PASSWD_KEY        "cap_remote_auth_passwd"
136 #define E_REMOTE_USERNAME_LB_KEY        "cap_remote_username_lb"
137 #define E_REMOTE_USERNAME_TE_KEY        "cap_remote_username_te"
138 #define E_REMOTE_PASSWD_LB_KEY          "cap_remote_passwd_lb"
139 #define E_REMOTE_PASSWD_TE_KEY          "cap_remote_passwd_te"
140 #define E_CAP_CBX_IFTYPE_VALUE_KEY      "cap_cbx_iftype_value"
141 #define E_CAP_CBX_PREV_IFTYPE_VALUE_KEY "cap_cbx_prev_iftype_value"
142 #define E_CAP_CBX_IFTYPE_NOUPDATE_KEY   "cap_cbx_iftype_noupdate"
143 #define E_OPT_REMOTE_BT_KEY             "cap_remote_opt_bt"
144 #define E_OPT_REMOTE_DIALOG_PTR_KEY     "cap_remote_opt_dialog"
145 #define E_OPT_REMOTE_CALLER_PTR_KEY     "cap_remote_opt_caller"
146 #endif
147 #ifdef HAVE_PCAP_SETSAMPLING
148 #define E_CAP_SAMP_NONE_RB_KEY          "cap_samp_none_rb"
149 #define E_CAP_SAMP_COUNT_RB_KEY         "cap_samp_count_rb"
150 #define E_CAP_SAMP_COUNT_SB_KEY         "cap_samp_count_sb"
151 #define E_CAP_SAMP_TIMER_RB_KEY         "cap_samp_timer_rb"
152 #define E_CAP_SAMP_TIMER_SB_KEY         "cap_samp_timer_sb"
153 #endif
154
155 #define E_CAP_OM_LT_VALUE_KEY           "cap_om_lt_value"
156
157
158 /*
159  * Keep a static pointer to the current "Capture Options" window, if
160  * any, so that if somebody tries to do "Capture:Start" while there's
161  * already a "Capture Options" window up, we just pop up the existing
162  * one, rather than creating a new one.
163  */
164 static GtkWidget *cap_open_w;
165 static GtkWidget * dl_hdr_menu=NULL;
166 static GHashTable *linktype_history=NULL;
167
168 #ifdef HAVE_PCAP_REMOTE
169 static GHashTable *remote_host_list=NULL;
170 #endif
171
172 static void
173 capture_prep_file_cb(GtkWidget *file_bt, GtkWidget *file_te);
174
175 static void
176 select_link_type_cb(GtkWidget *w, gpointer data);
177
178 #ifdef HAVE_PCAP_REMOTE
179 static void
180 select_if_type_cb(GtkComboBox *iftype_cbx, gpointer data);
181
182 static void
183 capture_remote_cb(GtkWidget *w, gboolean focus_username);
184 #endif
185
186 static void
187 capture_cancel_cb(GtkWidget *win, gpointer data);
188
189 static void
190 capture_prep_adjust_sensitivity(GtkWidget *tb, gpointer parent_w);
191
192 static void
193 capture_prep_destroy_cb(GtkWidget *win, gpointer user_data);
194
195 static void
196 capture_prep_interface_changed_cb(GtkWidget *entry, gpointer parent_w);
197
198 static gboolean
199 capture_dlg_prep(gpointer parent_w);
200
201
202 /* stop the currently running capture */
203 void
204 capture_stop_cb(GtkWidget *w _U_, gpointer d _U_)
205 {
206 #ifdef HAVE_AIRPCAP
207     airpcap_set_toolbar_stop_capture(airpcap_if_active);
208 #endif
209
210     capture_stop(&global_capture_opts);
211 }
212
213 /* restart (stop - delete old file - start) running capture */
214 void
215 capture_restart_cb(GtkWidget *w _U_, gpointer d _U_)
216 {
217 #ifdef HAVE_AIRPCAP
218     airpcap_set_toolbar_start_capture(airpcap_if_active);
219 #endif
220
221     capture_restart(&global_capture_opts);
222 }
223
224 gint
225 capture_get_linktype (gchar *if_name)
226 {
227   gint linktype, *linktype_p;
228
229   if (linktype_history) {
230     linktype_p = g_hash_table_lookup(linktype_history, if_name);
231   } else {
232     linktype_p = NULL;
233   }
234
235   if (linktype_p) {
236     linktype = *linktype_p;
237   } else {
238     linktype = capture_dev_user_linktype_find(if_name);
239   }
240
241   return linktype;
242 }
243
244 /* init the link type list */
245 /* (often this list has only one entry and will therefore be disabled) */
246 static void
247 set_link_type_list(GtkWidget *linktype_om, GtkWidget *entry)
248 {
249   gchar *entry_text;
250   gchar *if_text;
251   gchar *if_name;
252   GList *if_list;
253   GList *if_entry;
254   if_info_t *if_info;
255   GList *lt_list;
256   int err;
257   GtkWidget *lt_menu, *lt_menu_item;
258   GList *lt_entry;
259   gint linktype, linktype_select, linktype_count;
260   data_link_info_t *data_link_info;
261   gchar *linktype_menu_label;
262   guint num_supported_link_types;
263   GtkWidget *linktype_lb = g_object_get_data(G_OBJECT(linktype_om), E_CAP_LT_OM_LABEL_KEY);
264   GtkWidget *if_ip_lb;
265   GString *ip_str = g_string_new("IP address: ");
266   int ips = 0;
267   GSList *curr_addr;
268   if_addr_t *addr;
269 #ifdef HAVE_PCAP_REMOTE
270   GtkWidget *iftype_cbx;
271   int iftype;
272 #endif
273 #ifdef HAVE_AIRPCAP
274   GtkWidget *advanced_bt;
275 #endif
276
277   /* Deallocate the existing menu for Datalink header type */
278   if (dl_hdr_menu != NULL)
279     gtk_widget_destroy(dl_hdr_menu);
280
281   lt_menu = gtk_menu_new();
282   dl_hdr_menu= lt_menu;
283   entry_text = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry)));
284   if_text = g_strstrip(entry_text);
285   if_name = g_strdup(get_if_name(if_text));
286   linktype = capture_get_linktype(if_name);
287
288 #ifdef HAVE_AIRPCAP
289   /* is it an airpcap interface??? */
290   /* retrieve the advanced button pointer */
291   advanced_bt = g_object_get_data(G_OBJECT(entry),AIRPCAP_OPTIONS_ADVANCED_KEY);
292   airpcap_if_selected = get_airpcap_if_from_name(airpcap_if_list,if_name);
293   airpcap_enable_toolbar_widgets(airpcap_tb,FALSE);
294   if (airpcap_if_selected != NULL) {
295     gtk_widget_set_sensitive(advanced_bt,TRUE);
296   } else {
297     gtk_widget_set_sensitive(advanced_bt,FALSE);
298   }
299 #endif
300
301   /*
302    * If the interface name is in the list of known interfaces, get
303    * its list of link-layer types and set the option menu to display it.
304    *
305    * If it's not, don't bother - the user might be in the middle of
306    * editing the list, or it might be a remote device in which case
307    * getting the list could take an arbitrarily-long period of time.
308    * The list currently won't contain any remote devices (as
309    * "pcap_findalldevs()" doesn't know about remote devices, and neither
310    * does the code we use if "pcap_findalldevs()" isn't available), but
311    * should contain all the local devices on which you can capture.
312    */
313   lt_list = NULL;
314   if (*if_name != '\0') {
315     /*
316      * Try to get the list of known interfaces.
317      */
318 #ifdef HAVE_PCAP_REMOTE
319     iftype_cbx = g_object_get_data(G_OBJECT(cap_open_w), E_CAP_IFTYPE_CBX_KEY);
320     iftype = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(iftype_cbx),
321                                                E_CAP_CBX_IFTYPE_VALUE_KEY));
322     if (iftype >= CAPTURE_IFREMOTE)
323       if_list = (GList *) g_object_get_data(G_OBJECT(cap_open_w), E_CAP_IF_LIST_KEY);
324     else
325       if_list = capture_interface_list(&err, NULL);
326 #else
327     if_list = capture_interface_list(&err, NULL);
328 #endif
329     if (if_list != NULL) {
330       /*
331        * We have the list - check it.
332        */
333       for (if_entry = if_list; if_entry != NULL;
334            if_entry = g_list_next(if_entry)) {
335         if_info = if_entry->data;
336         if (strcmp(if_info->name, if_name) == 0) {
337           /*
338            * It's in the list.
339            * Get the list of link-layer types for it.
340            */
341 #ifdef HAVE_PCAP_REMOTE
342           if (iftype == CAPTURE_IFLOCAL)
343             /* Not able to get link-layer for remote interfaces */
344 #endif
345           lt_list = capture_pcap_linktype_list(if_name, NULL);
346
347           /* create string of list of IP addresses of this interface */
348           for (; (curr_addr = g_slist_nth(if_info->addrs, ips)) != NULL; ips++) {
349             if (ips != 0)
350               g_string_append(ip_str, ", ");
351
352             addr = (if_addr_t *)curr_addr->data;
353             switch (addr->ifat_type) {
354
355             case IF_AT_IPv4:
356               g_string_append(ip_str,
357                 ip_to_str((guint8 *)&addr->addr.ip4_addr));
358               break;
359
360             case IF_AT_IPv6:
361               g_string_append(ip_str,
362                   ip6_to_str((struct e_in6_addr *)&addr->addr.ip6_addr));
363               break;
364
365             default:
366               /* In case we add non-IP addresses */
367               break;
368             }
369           }
370
371           if (if_info->loopback)
372             g_string_append(ip_str, " (loopback)");
373         }
374       }
375 #ifdef HAVE_PCAP_REMOTE
376       /* Only delete if fetched local */
377       if (iftype == CAPTURE_IFLOCAL)
378 #endif
379       free_interface_list(if_list);
380     }
381   }
382   g_free(entry_text);
383   g_free(if_name);
384
385   num_supported_link_types = 0;
386   linktype_select = 0;
387   linktype_count = 0;
388   for (lt_entry = lt_list; lt_entry != NULL; lt_entry = g_list_next(lt_entry)) {
389     data_link_info = lt_entry->data;
390     if (data_link_info->description != NULL) {
391       lt_menu_item = gtk_menu_item_new_with_label(data_link_info->description);
392       g_object_set_data(G_OBJECT(lt_menu_item), E_CAP_LT_OM_KEY, linktype_om);
393       g_signal_connect(lt_menu_item, "activate", G_CALLBACK(select_link_type_cb),
394                      GINT_TO_POINTER(data_link_info->dlt));
395       num_supported_link_types++;
396     } else {
397       /* Not supported - tell them about it but don't let them select it. */
398       linktype_menu_label = g_strdup_printf("%s (not supported)",
399                                             data_link_info->name);
400       lt_menu_item = gtk_menu_item_new_with_label(linktype_menu_label);
401       g_free(linktype_menu_label);
402     }
403     if (data_link_info->dlt == linktype) {
404       /* Found a matching dlt, selecth this */
405       linktype_select = linktype_count;
406     }
407     gtk_menu_shell_append(GTK_MENU_SHELL(lt_menu), lt_menu_item);
408     gtk_widget_show(lt_menu_item);
409     linktype_count++;
410   }
411   if (lt_list == NULL) {
412     lt_menu_item = gtk_menu_item_new_with_label("(not supported)");
413     gtk_menu_shell_append(GTK_MENU_SHELL(lt_menu), lt_menu_item);
414     gtk_widget_show(lt_menu_item);
415   } else {
416     free_pcap_linktype_list(lt_list);
417   }
418   gtk_option_menu_set_menu(GTK_OPTION_MENU(linktype_om), lt_menu);
419   gtk_widget_set_sensitive(linktype_lb, num_supported_link_types >= 2);
420   gtk_widget_set_sensitive(linktype_om, num_supported_link_types >= 2);
421
422   g_object_set_data(G_OBJECT(linktype_om), E_CAP_OM_LT_VALUE_KEY, GINT_TO_POINTER(linktype));
423   global_capture_opts.linktype = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(linktype_om), E_CAP_OM_LT_VALUE_KEY));
424
425   /* Restore the menu to the last index used */
426   gtk_option_menu_set_history(GTK_OPTION_MENU(linktype_om),linktype_select);
427   if_ip_lb = g_object_get_data(G_OBJECT(linktype_om), E_CAP_IFACE_KEY);
428   if(ips == 0) {
429     g_string_append(ip_str, "unknown");
430   }
431   gtk_label_set_text(GTK_LABEL(if_ip_lb), ip_str->str);
432 #if GTK_CHECK_VERSION(2,6,0)
433   gtk_label_set_ellipsize(GTK_LABEL(if_ip_lb), PANGO_ELLIPSIZE_MIDDLE);
434 #endif
435   g_string_free(ip_str, TRUE);
436 }
437
438
439 #define TIME_UNIT_SECOND    0
440 #define TIME_UNIT_MINUTE    1
441 #define TIME_UNIT_HOUR      2
442 #define TIME_UNIT_DAY       3
443 #define MAX_TIME_UNITS 4
444 static const char *time_unit_name[MAX_TIME_UNITS] = {
445         "second(s)",
446         "minute(s)",
447         "hour(s)",
448         "day(s)",
449 };
450
451 /* create one of the duration options */
452 /* (and select the matching unit depending on the given value) */
453 static GtkWidget *time_unit_combo_box_new(guint32 value) {
454     GtkWidget *unit_combo_box;
455     int i;
456
457         unit_combo_box = gtk_combo_box_new_text ();
458         for(i=0;i<MAX_TIME_UNITS;i++){
459                 gtk_combo_box_append_text (GTK_COMBO_BOX (unit_combo_box), time_unit_name[i]);
460         }
461     /* the selected combo_box item can't be changed, once the combo_box
462        is created, so set the matching combo_box item now */
463     /* days */
464     if(value >= 60 * 60 * 24) {
465                  gtk_combo_box_set_active(GTK_COMBO_BOX(unit_combo_box), TIME_UNIT_DAY);
466     } else {
467         /* hours */
468         if(value >= 60 * 60) {
469                         gtk_combo_box_set_active(GTK_COMBO_BOX(unit_combo_box), TIME_UNIT_HOUR);
470         } else {
471             /* minutes */
472             if(value >= 60) {
473                                 gtk_combo_box_set_active(GTK_COMBO_BOX(unit_combo_box), TIME_UNIT_MINUTE);
474             } else {
475                 /* seconds */
476                                 gtk_combo_box_set_active(GTK_COMBO_BOX(unit_combo_box), TIME_UNIT_SECOND);
477             }
478         }
479     }
480
481         return unit_combo_box;
482 }
483
484 /* convert time value from raw to displayed (e.g. 60s -> 1min) */
485 static guint32 time_unit_combo_box_convert_value(
486 guint32 value)
487 {
488     /* days */
489     if(value >= 60 * 60 * 24) {
490         return value / (60 * 60 * 24);
491     }
492
493     /* hours */
494     if(value >= 60 * 60) {
495         return value / (60 * 60);
496     }
497
498     /* minutes */
499     if(value >= 60) {
500         return value / 60;
501     }
502
503     /* seconds */
504     return value;
505 }
506
507 /* get raw value from unit and value fields */
508 static guint32 time_unit_combo_box_get_value(
509 GtkWidget *unit_combo_box,
510 guint32 value)
511 {
512     int unit;
513
514         unit = gtk_combo_box_get_active (GTK_COMBO_BOX(unit_combo_box));
515
516     switch(unit) {
517     case(TIME_UNIT_SECOND):
518         return value;
519     case(TIME_UNIT_MINUTE):
520         return value * 60;
521     case(TIME_UNIT_HOUR):
522         return value * 60 * 60;
523     case(TIME_UNIT_DAY):
524         return value * 60 * 60 * 24;
525     default:
526         g_assert_not_reached();
527         return 0;
528     }
529 }
530
531
532 #define SIZE_UNIT_KILOBYTES 0
533 #define SIZE_UNIT_MEGABYTES 1
534 #define SIZE_UNIT_GIGABYTES 2
535 #define MAX_SIZE_UNITS 3
536 static const char *size_unit_name[MAX_SIZE_UNITS] = {
537         "kilobyte(s)",
538         "megabyte(s)",
539         "gigabyte(s)",
540 };
541
542 /* create one of the size options */
543 /* (and select the matching unit depending on the given value) */
544 static GtkWidget *size_unit_combo_box_new(guint32 value) {
545     GtkWidget *unit_combo_box;
546     int i;
547
548         unit_combo_box=gtk_combo_box_new_text();
549         for(i=0;i<MAX_SIZE_UNITS;i++){
550                 gtk_combo_box_append_text (GTK_COMBO_BOX (unit_combo_box), size_unit_name[i]);
551         }
552
553     /* the selected combo_box item can't be changed, once the combo_box
554        is created, so set the matching combo_box item now */
555     /* gigabytes */
556     if(value >= 1024 * 1024) {
557                 gtk_combo_box_set_active(GTK_COMBO_BOX(unit_combo_box), SIZE_UNIT_GIGABYTES);
558     } else {
559         /* megabytes */
560         if(value >= 1024) {
561                         gtk_combo_box_set_active(GTK_COMBO_BOX(unit_combo_box), SIZE_UNIT_MEGABYTES);
562         } else {
563             /* kilobytes */
564                         gtk_combo_box_set_active(GTK_COMBO_BOX(unit_combo_box), SIZE_UNIT_KILOBYTES);
565         }
566     }
567
568      return unit_combo_box;
569 }
570
571 /* convert size value from raw to displayed (e.g. 1024 Bytes -> 1 KB) */
572 static guint32 size_unit_combo_box_set_value(
573 guint32 value)
574 {
575     /* gigabytes */
576     if(value >= 1024 * 1024) {
577         return value / (1024 * 1024);
578     }
579
580     /* megabytes */
581     if(value >= 1024) {
582         return value / (1024);
583     }
584
585     /* kilobytes */
586     return value;
587 }
588
589 /* get raw value from unit and value fields */
590 static guint32 size_unit_combo_box_convert_value(
591 GtkWidget *unit_combo_box,
592 guint32 value)
593 {
594     int unit;
595
596         unit = gtk_combo_box_get_active (GTK_COMBO_BOX(unit_combo_box));
597
598     switch(unit) {
599     case(SIZE_UNIT_KILOBYTES):
600         return value;
601     case(SIZE_UNIT_MEGABYTES):
602         if(value > G_MAXINT / 1024) {
603             return 0;
604         } else {
605             return value * 1024;
606         }
607     case(SIZE_UNIT_GIGABYTES):
608         if(value > G_MAXINT / (1024 * 1024)) {
609             return 0;
610         } else {
611             return value * 1024 * 1024;
612         }
613     default:
614         g_assert_not_reached();
615         return 0;
616     }
617 }
618
619 #ifdef HAVE_AIRPCAP
620 /*
621  * Sets the toolbar before calling the advanced dialog with for the right interface
622  */
623 void
624 options_airpcap_advanced_cb(GtkWidget *w _U_, gpointer d _U_)
625 {
626   int *from_widget;
627
628   from_widget = (gint*)g_malloc(sizeof(gint));
629   *from_widget = AIRPCAP_ADVANCED_FROM_OPTIONS;
630   g_object_set_data(G_OBJECT(airpcap_tb),AIRPCAP_ADVANCED_FROM_KEY,from_widget);
631
632   airpcap_if_active = airpcap_if_selected;
633   airpcap_enable_toolbar_widgets(airpcap_tb,FALSE);
634   display_airpcap_advanced_cb(w,d);
635 }
636 #endif
637
638 #ifdef HAVE_PCAP_REMOTE
639 /* PCAP interface type menu item */
640 struct iftype_info {
641     capture_source  id;
642     const char     *name;
643 };
644
645 /* List of available types of PCAP interface */
646 static struct iftype_info iftype[] = {
647     { CAPTURE_IFLOCAL, "Local" },
648     { CAPTURE_IFREMOTE, "Remote..." }
649 };
650
651 #if GTK_CHECK_VERSION(2,6,0)
652 #define REMOTE_HOST_START ((sizeof(iftype) / sizeof(iftype[0])) + 1)
653 #define REMOTE_HOST_SEPARATOR "---"
654 #else
655 #define REMOTE_HOST_START ((sizeof(iftype) / sizeof(iftype[0])))
656 #endif
657
658 static void
659 iftype_combo_box_add_remote_separators (GtkWidget *iftype_cbx)
660 {
661 #if GTK_CHECK_VERSION(2,6,0)
662   gtk_combo_box_append_text(GTK_COMBO_BOX(iftype_cbx), REMOTE_HOST_SEPARATOR);
663   gtk_combo_box_append_text(GTK_COMBO_BOX(iftype_cbx), REMOTE_HOST_SEPARATOR);
664 #endif
665   gtk_combo_box_append_text(GTK_COMBO_BOX(iftype_cbx), "Clear list");
666 }
667
668 static void
669 iftype_combo_box_add (GtkWidget *iftype_cbx)
670 {
671   GtkTreeModel *model;
672   GtkTreeIter iter;
673   struct remote_host *rh;
674   gboolean create_new = FALSE;
675   gchar *string;
676   guint i, pos = REMOTE_HOST_START;
677
678   rh = g_hash_table_lookup (remote_host_list, global_capture_opts.remote_host);
679   if (!rh) {
680     rh = g_malloc0 (sizeof (*rh));
681     if (g_hash_table_size (remote_host_list) == 0) {
682       iftype_combo_box_add_remote_separators (iftype_cbx);
683     }
684     gtk_combo_box_insert_text(GTK_COMBO_BOX(iftype_cbx), pos, global_capture_opts.remote_host);
685     rh->remote_host = g_strdup (global_capture_opts.remote_host);
686     create_new = TRUE;
687   } else {
688     model = gtk_combo_box_get_model(GTK_COMBO_BOX(iftype_cbx));
689     if (gtk_tree_model_get_iter_first(model, &iter)) {
690       /* Skip the first entries */
691       for (i = 0; i < REMOTE_HOST_START; i++)
692         gtk_tree_model_iter_next(model, &iter);
693       do {
694         gtk_tree_model_get(model, &iter, 0, &string, -1);
695         if (string) {
696           if (strcmp (global_capture_opts.remote_host, string) == 0) {
697             /* Found match, show this position in combo box */
698             g_free (string);
699             break;
700           }
701           g_free (string);
702         }
703         pos++;
704       } while (gtk_tree_model_iter_next(model, &iter));
705     }
706
707     g_free (rh->remote_port);
708     g_free (rh->auth_username);
709     g_free (rh->auth_password);
710   }
711
712   rh->remote_port = g_strdup (global_capture_opts.remote_port);
713   rh->auth_type = global_capture_opts.auth_type;
714   rh->auth_username = g_strdup (global_capture_opts.auth_username);
715   rh->auth_password = g_strdup (global_capture_opts.auth_password);
716
717   if (create_new) {
718     g_hash_table_insert (remote_host_list, g_strdup (global_capture_opts.remote_host), rh);
719   }
720
721   g_object_set_data(G_OBJECT(iftype_cbx), E_CAP_CBX_IFTYPE_VALUE_KEY, GINT_TO_POINTER(pos));
722   g_object_set_data(G_OBJECT(iftype_cbx), E_CAP_CBX_IFTYPE_NOUPDATE_KEY, GINT_TO_POINTER(1));
723   gtk_combo_box_set_active(GTK_COMBO_BOX(iftype_cbx), pos);
724   g_object_set_data(G_OBJECT(iftype_cbx), E_CAP_CBX_IFTYPE_NOUPDATE_KEY, GINT_TO_POINTER(0));
725 }
726
727 static void
728 iftype_combo_box_add_remote_host (gpointer key, gpointer value _U_, gpointer user_data)
729 {
730   gtk_combo_box_insert_text(GTK_COMBO_BOX(user_data), REMOTE_HOST_START, key);
731
732   if (global_capture_opts.src_type == CAPTURE_IFREMOTE) {
733     /* Ensure we select the correct entry */
734     if (strcmp ((char *)key, global_capture_opts.remote_host) == 0) {
735       gtk_combo_box_set_active(GTK_COMBO_BOX(user_data), REMOTE_HOST_START);
736     }
737   }
738 }
739
740 /* Fill the menu of available types of interfaces */
741 static GtkWidget *
742 iftype_combo_box_new(void)
743 {
744   GtkWidget *iftype_cbx;
745   unsigned int i;
746
747   iftype_cbx = gtk_combo_box_new_text();
748
749   for (i = 0; i < sizeof(iftype) / sizeof(iftype[0]); i++) {
750     gtk_combo_box_append_text(GTK_COMBO_BOX(iftype_cbx), iftype[i].name);
751   }
752
753   if (g_hash_table_size (remote_host_list) > 0) {
754     /* Add remote hosts */
755     iftype_combo_box_add_remote_separators (iftype_cbx);
756     g_hash_table_foreach (remote_host_list, iftype_combo_box_add_remote_host, iftype_cbx);
757   }
758
759   if (global_capture_opts.src_type == CAPTURE_IFLOCAL) {
760     gtk_combo_box_set_active(GTK_COMBO_BOX(iftype_cbx), CAPTURE_IFLOCAL);
761   } else {
762     int iftype = gtk_combo_box_get_active(GTK_COMBO_BOX(iftype_cbx));
763     g_object_set_data(G_OBJECT(iftype_cbx), E_CAP_CBX_IFTYPE_VALUE_KEY, GINT_TO_POINTER(iftype));
764   }
765   g_signal_connect(iftype_cbx, "changed", G_CALLBACK(select_if_type_cb), NULL);
766   
767   return iftype_cbx;
768 }
769
770 #if GTK_CHECK_VERSION(2,6,0)
771 static gboolean
772 iftype_combo_is_separator (GtkTreeModel *model, GtkTreeIter *iter, gpointer data _U_)
773 {
774   gboolean result = FALSE;
775   gchar *string;
776
777   gtk_tree_model_get(model, iter, 0, &string, -1);
778   if (string) {
779     result = !strcmp (string, REMOTE_HOST_SEPARATOR);
780     g_free (string);
781   }
782
783   return result;
784   
785 }
786 #endif
787
788 static void
789 error_list_remote_interface_cb (gpointer dialog _U_, gint btn _U_, gpointer data)
790 {
791   capture_remote_cb(GTK_WIDGET(data), FALSE);
792 }
793
794 /* Retrieve the list of local or remote interfaces according to selected
795  * options and re-fill inteface name combobox */
796 static void
797 update_interface_list()
798 {
799   GtkWidget *if_cb, *iftype_cbx, *remote_bt;
800   GList     *if_list, *combo_list;
801   int        iftype, prev_iftype, err;
802   gchar     *err_str;
803
804   if (cap_open_w == NULL)
805     return;
806
807   if_cb = (GtkWidget *)g_object_get_data(G_OBJECT(cap_open_w), E_CAP_IFACE_KEY);
808   iftype_cbx = g_object_get_data(G_OBJECT(cap_open_w), E_CAP_IFTYPE_CBX_KEY);
809   remote_bt = g_object_get_data(G_OBJECT(iftype_cbx), E_OPT_REMOTE_BT_KEY);
810   iftype = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(iftype_cbx),
811                                              E_CAP_CBX_IFTYPE_VALUE_KEY));
812
813   if_list = (GList *) g_object_get_data(G_OBJECT(cap_open_w), E_CAP_IF_LIST_KEY);
814   if (if_list) {
815     free_interface_list(if_list);
816   }
817   if (iftype >= CAPTURE_IFREMOTE) {
818     if_list = get_remote_interface_list(global_capture_opts.remote_host,
819                                         global_capture_opts.remote_port,
820                                         global_capture_opts.auth_type,
821                                         global_capture_opts.auth_username,
822                                         global_capture_opts.auth_password,
823                                         &err, &err_str);
824     g_object_set_data(G_OBJECT(cap_open_w), E_CAP_IF_LIST_KEY, if_list);
825   } else {
826     if_list = capture_interface_list(&err, &err_str);
827     g_object_set_data(G_OBJECT(cap_open_w), E_CAP_IF_LIST_KEY, NULL);
828   }
829
830   if (if_list == NULL && err == CANT_GET_INTERFACE_LIST) {
831     gpointer dialog = simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_str);
832     g_free(err_str);
833
834     if (iftype >= CAPTURE_IFREMOTE) {
835       /* Fall back to previous interface list */
836       simple_dialog_set_cb(dialog, error_list_remote_interface_cb, iftype_cbx);
837       prev_iftype = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(iftype_cbx),
838                                                       E_CAP_CBX_PREV_IFTYPE_VALUE_KEY));
839       g_object_set_data(G_OBJECT(iftype_cbx), E_CAP_CBX_IFTYPE_VALUE_KEY, GINT_TO_POINTER(prev_iftype));
840       return;
841     }
842
843     gtk_combo_set_popdown_strings(GTK_COMBO(if_cb), NULL);
844     gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(if_cb)->entry), "");
845   } else if (iftype == CAPTURE_IFREMOTE) {
846     /* New remote interface */
847     iftype_combo_box_add (iftype_cbx);
848   }
849   combo_list = build_capture_combo_list(if_list, TRUE);
850   gtk_combo_set_popdown_strings(GTK_COMBO(if_cb), combo_list);
851   if (combo_list == NULL)
852     gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(if_cb)->entry), "");
853   
854   free_capture_combo_list(combo_list);
855
856   if (iftype == CAPTURE_IFLOCAL) {
857     /* Only delete if fetched local */
858     free_interface_list(if_list);
859     gtk_widget_set_sensitive(remote_bt, FALSE);
860   } else {
861     gtk_widget_set_sensitive(remote_bt, TRUE);
862   }
863 }
864
865 /* User changed an interface entry of "Remote interface" dialog */
866 static void
867 capture_remote_adjust_sensitivity(GtkWidget *tb _U_, gpointer parent_w)
868 {
869   GtkWidget *auth_passwd_rb,
870             *username_lb, *username_te,
871             *passwd_lb, *passwd_te;
872   gboolean  state;
873
874   auth_passwd_rb = (GtkWidget *)g_object_get_data(G_OBJECT(parent_w),
875                                                   E_REMOTE_AUTH_PASSWD_KEY);
876   username_lb = (GtkWidget *)g_object_get_data(G_OBJECT(parent_w),
877                                                E_REMOTE_USERNAME_LB_KEY);
878   username_te = (GtkWidget *)g_object_get_data(G_OBJECT(parent_w),
879                                                E_REMOTE_USERNAME_TE_KEY);
880   passwd_lb = (GtkWidget *)g_object_get_data(G_OBJECT(parent_w), E_REMOTE_PASSWD_LB_KEY);
881   passwd_te = (GtkWidget *)g_object_get_data(G_OBJECT(parent_w), E_REMOTE_PASSWD_TE_KEY);
882
883   state =  gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(auth_passwd_rb));
884   gtk_widget_set_sensitive(GTK_WIDGET(username_lb), state);
885   gtk_widget_set_sensitive(GTK_WIDGET(username_te), state);
886   gtk_widget_set_sensitive(GTK_WIDGET(passwd_lb), state);
887   gtk_widget_set_sensitive(GTK_WIDGET(passwd_te), state);
888 }
889
890 /* user requested to destroy the dialog */
891 static void
892 capture_remote_destroy_cb(GtkWidget *win, gpointer user_data _U_)
893 {
894     GtkWidget *caller;
895
896     caller = g_object_get_data(G_OBJECT(win), E_CAP_REMOTE_CALLER_PTR_KEY);
897     g_object_set_data(G_OBJECT(caller), E_CAP_REMOTE_DIALOG_PTR_KEY, NULL);
898 }
899
900 /* user requested to accept remote interface options */
901 static void
902 capture_remote_ok_cb(GtkWidget *win _U_, GtkWidget *remote_w)
903 {
904   GtkWidget *host_te, *port_te, *auth_pwd_rb, *username_te, *passwd_te,
905             *auth_null_rb, *auth_passwd_rb, *iftype_cbx;
906   int prev_iftype;
907
908   if (remote_w == NULL)
909     return;
910
911   host_te = (GtkWidget *)g_object_get_data(G_OBJECT(remote_w), E_REMOTE_HOST_TE_KEY);
912   port_te = (GtkWidget *)g_object_get_data(G_OBJECT(remote_w), E_REMOTE_PORT_TE_KEY);
913   auth_pwd_rb = (GtkWidget *)g_object_get_data(G_OBJECT(remote_w),
914                                                E_REMOTE_AUTH_PASSWD_KEY);
915   username_te = (GtkWidget *)g_object_get_data(G_OBJECT(remote_w),
916                                                E_REMOTE_USERNAME_TE_KEY);
917   passwd_te = (GtkWidget *)g_object_get_data(G_OBJECT(remote_w), E_REMOTE_PASSWD_TE_KEY);
918   auth_null_rb = (GtkWidget *) g_object_get_data(G_OBJECT(remote_w), E_REMOTE_AUTH_NULL_KEY);
919   auth_passwd_rb = (GtkWidget *) g_object_get_data(G_OBJECT(remote_w), E_REMOTE_AUTH_PASSWD_KEY);
920   iftype_cbx = g_object_get_data(G_OBJECT(cap_open_w), E_CAP_IFTYPE_CBX_KEY);
921   prev_iftype = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(iftype_cbx), 
922                                                   E_CAP_CBX_IFTYPE_VALUE_KEY));
923
924   g_free(global_capture_opts.remote_host);
925   global_capture_opts.remote_host = g_strdup(gtk_entry_get_text(GTK_ENTRY(host_te)));
926   g_free(global_capture_opts.remote_port);
927   global_capture_opts.remote_port = g_strdup(gtk_entry_get_text(GTK_ENTRY(port_te)));
928   if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(auth_passwd_rb)))
929     global_capture_opts.auth_type = CAPTURE_AUTH_PWD;
930   else
931     global_capture_opts.auth_type = CAPTURE_AUTH_NULL;
932
933   g_free(global_capture_opts.auth_username);
934   global_capture_opts.auth_username =
935     g_strdup(gtk_entry_get_text(GTK_ENTRY(username_te)));
936
937   g_free(global_capture_opts.auth_password);
938   global_capture_opts.auth_password =
939     g_strdup(gtk_entry_get_text(GTK_ENTRY(passwd_te)));
940
941   g_object_set_data(G_OBJECT(iftype_cbx), E_CAP_CBX_PREV_IFTYPE_VALUE_KEY,
942                     GINT_TO_POINTER(prev_iftype));
943   g_object_set_data(G_OBJECT(iftype_cbx), E_CAP_CBX_IFTYPE_VALUE_KEY,
944                     GINT_TO_POINTER(CAPTURE_IFREMOTE));
945
946   window_destroy(GTK_WIDGET(remote_w));
947   update_interface_list();
948 }
949
950 static void
951 capture_remote_cancel_cb(GtkWidget *win, gpointer data)
952 {
953   GtkWidget *iftype_cbx;
954   int old_iftype;
955
956   iftype_cbx = g_object_get_data(G_OBJECT(cap_open_w), E_CAP_IFTYPE_CBX_KEY);
957   old_iftype = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(iftype_cbx),
958                                                  E_CAP_CBX_PREV_IFTYPE_VALUE_KEY));
959   gtk_combo_box_set_active(GTK_COMBO_BOX(iftype_cbx), old_iftype);
960
961   window_cancel_button_cb (win, data);
962 }
963
964 /* Show remote capture interface parameters dialog */
965 static void
966 capture_remote_cb(GtkWidget *w, gboolean focus_username)
967 {
968   GtkWidget   *caller, *remote_w,
969               *main_vb, *host_tb,
970               *host_lb, *host_te, *port_lb, *port_te,
971               *auth_fr, *auth_vb,
972               *auth_null_rb, *auth_passwd_rb, *auth_passwd_tb,
973               *user_lb, *user_te, *passwd_lb, *passwd_te,
974               *bbox, *ok_bt, *cancel_bt;
975   gchar       *title;
976   GtkTooltips *tooltips;
977   GSList      *auth_group;
978
979   caller = gtk_widget_get_toplevel(w);
980   remote_w = g_object_get_data(G_OBJECT(caller), E_CAP_REMOTE_DIALOG_PTR_KEY);
981   if (remote_w != NULL) {
982     reactivate_window(remote_w);
983     return;
984   }
985
986   title = create_user_window_title("Wireshark: Remote Interface");
987   remote_w = dlg_window_new(title);
988   g_object_set_data(G_OBJECT(remote_w), E_CAP_REMOTE_CALLER_PTR_KEY, caller);
989   g_object_set_data(G_OBJECT(caller), E_CAP_REMOTE_DIALOG_PTR_KEY, remote_w);
990   g_free(title);
991
992   tooltips = gtk_tooltips_new();
993
994   main_vb = gtk_vbox_new(FALSE, 0);
995   gtk_container_set_border_width(GTK_CONTAINER(main_vb), 5);
996   gtk_container_add(GTK_CONTAINER(remote_w), main_vb);
997
998   /* Host/port table */
999   host_tb = gtk_table_new(2, 2, FALSE);
1000   gtk_table_set_row_spacings(GTK_TABLE(host_tb), 3);
1001   gtk_table_set_col_spacings(GTK_TABLE(host_tb), 3);
1002   gtk_box_pack_start(GTK_BOX(main_vb), host_tb, FALSE, FALSE, 0);
1003
1004   /* Host row */
1005   host_lb = gtk_label_new("Host:");
1006   gtk_table_attach_defaults(GTK_TABLE(host_tb), host_lb, 0, 1, 0, 1);
1007
1008   host_te = gtk_entry_new();
1009   gtk_tooltips_set_tip(tooltips, host_te,
1010                        "Enter the hostname or host IP address to be used as a source "
1011                        "for remote capture.", NULL);
1012   gtk_table_attach_defaults(GTK_TABLE(host_tb), host_te, 1, 2, 0, 1);
1013   if (global_capture_opts.remote_host != NULL)
1014     gtk_entry_set_text(GTK_ENTRY(host_te), global_capture_opts.remote_host);
1015
1016   /* Port row */
1017   port_lb = gtk_label_new("Port:");
1018   gtk_table_attach_defaults(GTK_TABLE(host_tb), port_lb, 0, 1, 1, 2);
1019
1020   port_te = gtk_entry_new();
1021   gtk_tooltips_set_tip(tooltips, port_te,
1022                        "Enter the TCP port number used by RPCAP server at remote host "
1023                        "(leave it empty for default port number).", NULL);
1024   gtk_table_attach_defaults(GTK_TABLE(host_tb), port_te, 1, 2, 1, 2);
1025   if (global_capture_opts.remote_port != NULL)
1026     gtk_entry_set_text(GTK_ENTRY(port_te), global_capture_opts.remote_port);
1027
1028   /* Authentication options frame */
1029   auth_fr = gtk_frame_new("Authentication");
1030   gtk_container_add(GTK_CONTAINER(main_vb), auth_fr);
1031
1032   auth_vb = gtk_vbox_new(FALSE, 3);
1033   gtk_container_set_border_width(GTK_CONTAINER(auth_vb), 5);
1034   gtk_container_add(GTK_CONTAINER(auth_fr), auth_vb);
1035
1036   auth_null_rb = gtk_radio_button_new_with_label(NULL,
1037                                                  "Null authentication");
1038   gtk_box_pack_start(GTK_BOX(auth_vb), auth_null_rb, TRUE, TRUE, 0);
1039
1040   auth_group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(auth_null_rb));
1041   auth_passwd_rb = gtk_radio_button_new_with_label(auth_group,
1042                                                    "Password authentication");
1043   gtk_box_pack_start(GTK_BOX(auth_vb), auth_passwd_rb, TRUE, TRUE, 0);
1044   g_signal_connect(auth_passwd_rb, "toggled",
1045                    G_CALLBACK(capture_remote_adjust_sensitivity), remote_w);
1046
1047   auth_passwd_tb = gtk_table_new(2, 2, FALSE);
1048   gtk_table_set_row_spacings(GTK_TABLE(auth_passwd_tb), 3);
1049   gtk_table_set_col_spacings(GTK_TABLE(auth_passwd_tb), 3);
1050   gtk_box_pack_start(GTK_BOX(auth_vb), auth_passwd_tb, FALSE, FALSE, 0);
1051
1052   user_lb = gtk_label_new("Username:");
1053   gtk_table_attach_defaults(GTK_TABLE(auth_passwd_tb), user_lb, 0, 1, 0, 1);
1054
1055   user_te = gtk_entry_new();
1056   gtk_table_attach_defaults(GTK_TABLE(auth_passwd_tb), user_te, 1, 2, 0, 1);
1057   if (global_capture_opts.auth_username != NULL)
1058     gtk_entry_set_text(GTK_ENTRY(user_te), global_capture_opts.auth_username);
1059
1060   passwd_lb = gtk_label_new("Password:");
1061   gtk_table_attach_defaults(GTK_TABLE(auth_passwd_tb), passwd_lb, 0, 1, 1, 2);
1062
1063   passwd_te = gtk_entry_new();
1064   gtk_entry_set_visibility(GTK_ENTRY(passwd_te), FALSE);
1065   gtk_table_attach_defaults(GTK_TABLE(auth_passwd_tb), passwd_te, 1, 2, 1, 2);
1066   if (global_capture_opts.auth_password != NULL)
1067     gtk_entry_set_text(GTK_ENTRY(passwd_te), global_capture_opts.auth_password);
1068
1069   /* Button row: "Start" and "Cancel" buttons */
1070   bbox = dlg_button_row_new(GTK_STOCK_OK, GTK_STOCK_CANCEL, NULL);
1071   gtk_box_pack_start(GTK_BOX(main_vb), bbox, FALSE, FALSE, 5);
1072
1073   ok_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_OK);
1074   g_signal_connect(ok_bt, "clicked", G_CALLBACK(capture_remote_ok_cb), remote_w);
1075   gtk_tooltips_set_tip(tooltips, ok_bt,
1076                        "Accept remote host parameters and lookup "
1077                        "remote interfaces.", NULL);
1078
1079   cancel_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CANCEL);
1080   gtk_tooltips_set_tip(tooltips, cancel_bt,
1081                        "Cancel and exit dialog.", NULL);
1082   window_set_cancel_button(remote_w, cancel_bt, capture_remote_cancel_cb);
1083
1084   if (focus_username) {
1085     /* Give the initial focus to the "Username" entry box. */
1086     gtk_widget_grab_focus(user_te);
1087   }
1088
1089   gtk_widget_grab_default(ok_bt);
1090
1091   /* Catch the "activate" signal on the text
1092      entries, so that if the user types Return there, we act as if the
1093      "OK" button had been selected, as happens if Return is typed if some
1094      widget that *doesn't* handle the Return key has the input focus. */
1095   dlg_set_activate(host_te, ok_bt);
1096   dlg_set_activate(port_te, ok_bt);
1097   dlg_set_activate(user_te, ok_bt);
1098   dlg_set_activate(passwd_te, ok_bt);
1099
1100   g_signal_connect(remote_w, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
1101   g_signal_connect(remote_w, "destroy", G_CALLBACK(capture_remote_destroy_cb), NULL);
1102
1103   g_object_set_data(G_OBJECT(remote_w), E_REMOTE_HOST_TE_KEY, host_te);
1104   g_object_set_data(G_OBJECT(remote_w), E_REMOTE_PORT_TE_KEY, port_te);
1105   g_object_set_data(G_OBJECT(remote_w), E_REMOTE_AUTH_NULL_KEY, auth_null_rb);
1106   g_object_set_data(G_OBJECT(remote_w), E_REMOTE_AUTH_PASSWD_KEY, auth_passwd_rb);
1107   g_object_set_data(G_OBJECT(remote_w), E_REMOTE_USERNAME_LB_KEY, user_lb);
1108   g_object_set_data(G_OBJECT(remote_w), E_REMOTE_USERNAME_TE_KEY, user_te);
1109   g_object_set_data(G_OBJECT(remote_w), E_REMOTE_PASSWD_LB_KEY, passwd_lb);
1110   g_object_set_data(G_OBJECT(remote_w), E_REMOTE_PASSWD_TE_KEY, passwd_te);
1111   
1112   if (global_capture_opts.auth_type == CAPTURE_AUTH_PWD)
1113     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(auth_passwd_rb), TRUE);
1114   else
1115     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(auth_null_rb), TRUE);
1116   capture_remote_adjust_sensitivity(NULL, remote_w);
1117
1118   gtk_widget_show_all(remote_w);
1119   window_present(remote_w);
1120 }
1121
1122 /* user requested to destroy the dialog */
1123 static void
1124 options_remote_destroy_cb(GtkWidget *win, gpointer user_data _U_)
1125 {
1126   GtkWidget *caller;
1127
1128   caller = g_object_get_data(G_OBJECT(win), E_OPT_REMOTE_CALLER_PTR_KEY);
1129   g_object_set_data(G_OBJECT(caller), E_OPT_REMOTE_DIALOG_PTR_KEY, NULL);
1130 }
1131
1132 /* user requested to accept remote interface options */
1133 static void
1134 options_remote_ok_cb(GtkWidget *win _U_, GtkWidget *parent_w)
1135 {
1136   GtkWidget *datatx_udp_cb, *nocap_rpcap_cb;
1137 #ifdef HAVE_PCAP_SETSAMPLING
1138   GtkWidget *samp_none_rb, *samp_count_rb, *samp_timer_rb,
1139             *samp_count_sb, *samp_timer_sb;
1140 #endif
1141
1142   if (parent_w == NULL)
1143     return;
1144
1145   datatx_udp_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_DATATX_UDP_CB_KEY);
1146   nocap_rpcap_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_NOCAP_RPCAP_CB_KEY);
1147
1148   global_capture_opts.datatx_udp =
1149     gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(datatx_udp_cb));
1150   global_capture_opts.nocap_rpcap =
1151     gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(nocap_rpcap_cb));
1152
1153 #ifdef HAVE_PCAP_SETSAMPLING
1154   samp_none_rb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_SAMP_NONE_RB_KEY);
1155   samp_count_rb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_SAMP_COUNT_RB_KEY);
1156   samp_timer_rb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_SAMP_TIMER_RB_KEY);
1157   samp_count_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_SAMP_COUNT_SB_KEY);
1158   samp_timer_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_SAMP_TIMER_SB_KEY);
1159
1160   if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(samp_none_rb)))
1161     global_capture_opts.sampling_method = CAPTURE_SAMP_NONE;
1162   else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(samp_count_rb))) {
1163     global_capture_opts.sampling_method = CAPTURE_SAMP_BY_COUNT;
1164     global_capture_opts.sampling_param = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(samp_count_sb));
1165   } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(samp_timer_rb))) {
1166     global_capture_opts.sampling_method = CAPTURE_SAMP_BY_TIMER;
1167     global_capture_opts.sampling_param = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(samp_timer_sb));
1168   }
1169 #endif
1170
1171   window_destroy(GTK_WIDGET(parent_w));
1172 }
1173
1174 #ifdef HAVE_PCAP_SETSAMPLING
1175 static void
1176 options_prep_adjust_sensitivity(GtkWidget *tb _U_, gpointer parent_w)
1177 {
1178   GtkWidget *samp_count_rb, *samp_timer_rb,
1179             *samp_count_sb, *samp_timer_sb;
1180
1181   samp_count_rb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_SAMP_COUNT_RB_KEY);
1182   samp_timer_rb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_SAMP_TIMER_RB_KEY);
1183   samp_count_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_SAMP_COUNT_SB_KEY);
1184   samp_timer_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_SAMP_TIMER_SB_KEY);
1185
1186   if (samp_count_sb && samp_count_rb)
1187    gtk_widget_set_sensitive(GTK_WIDGET(samp_count_sb),
1188       gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(samp_count_rb)));
1189
1190   if (samp_timer_sb && samp_timer_rb)
1191    gtk_widget_set_sensitive(GTK_WIDGET(samp_timer_sb),
1192       gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(samp_timer_rb)));
1193 }
1194 #endif
1195
1196 void
1197 options_remote_cb(GtkWidget *w _U_, gpointer d _U_)
1198 {
1199   GtkWidget *opt_remote_w, *main_vb;
1200   GtkWidget   *caller, *bbox, *ok_bt, *cancel_bt;
1201   GtkTooltips *tooltips;
1202   GtkWidget     *capture_fr, *capture_vb;
1203   GtkWidget     *nocap_rpcap_cb, *datatx_udp_cb;
1204 #ifdef HAVE_PCAP_SETSAMPLING
1205   GtkWidget     *sampling_fr, *sampling_vb, *sampling_tb, *sampling_lb,
1206                 *samp_none_rb, *samp_count_rb, *samp_timer_rb,
1207                 *samp_count_sb, *samp_timer_sb;
1208   GtkAdjustment *samp_count_adj, *samp_timer_adj;
1209   GSList        *samp_group;
1210 #endif
1211
1212   caller = gtk_widget_get_toplevel(w);
1213   opt_remote_w = g_object_get_data(G_OBJECT(caller), E_OPT_REMOTE_DIALOG_PTR_KEY);
1214   if (opt_remote_w != NULL) {
1215     reactivate_window(opt_remote_w);
1216     return;
1217   }
1218
1219   opt_remote_w = dlg_window_new("Remote Capture Settings");
1220   g_object_set_data(G_OBJECT(opt_remote_w), E_OPT_REMOTE_CALLER_PTR_KEY, caller);
1221   g_object_set_data(G_OBJECT(caller), E_OPT_REMOTE_DIALOG_PTR_KEY, opt_remote_w);
1222
1223   tooltips = gtk_tooltips_new();
1224
1225   main_vb = gtk_vbox_new(FALSE, 0);
1226   gtk_container_set_border_width(GTK_CONTAINER(main_vb), 5);
1227   gtk_container_add(GTK_CONTAINER(opt_remote_w), main_vb);
1228
1229   /* Remote capture options */
1230   capture_fr = gtk_frame_new("Capture Options");
1231   gtk_container_add(GTK_CONTAINER(main_vb), capture_fr);
1232
1233   capture_vb = gtk_vbox_new(FALSE, 0);
1234   gtk_container_set_border_width(GTK_CONTAINER(capture_vb), 5);
1235   gtk_container_add(GTK_CONTAINER(capture_fr), capture_vb);
1236
1237   nocap_rpcap_cb = gtk_check_button_new_with_mnemonic("Do not capture own RPCAP traffic");
1238   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(nocap_rpcap_cb),
1239           global_capture_opts.nocap_rpcap);
1240   gtk_container_add(GTK_CONTAINER(capture_vb), nocap_rpcap_cb);
1241
1242   datatx_udp_cb = gtk_check_button_new_with_mnemonic("Use UDP for data transfer");
1243   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(datatx_udp_cb),
1244           global_capture_opts.datatx_udp);
1245   gtk_container_add(GTK_CONTAINER(capture_vb), datatx_udp_cb);
1246
1247 #ifdef HAVE_PCAP_SETSAMPLING
1248   /* Sampling options */
1249   sampling_fr = gtk_frame_new("Sampling Options");
1250   gtk_container_add(GTK_CONTAINER(main_vb), sampling_fr);
1251
1252   sampling_vb = gtk_vbox_new(FALSE, 0);
1253   gtk_container_set_border_width(GTK_CONTAINER(sampling_vb), 5);
1254   gtk_container_add(GTK_CONTAINER(sampling_fr), sampling_vb);
1255
1256   sampling_tb = gtk_table_new(3, 3, FALSE);
1257   gtk_table_set_row_spacings(GTK_TABLE(sampling_tb), 1);
1258   gtk_table_set_col_spacings(GTK_TABLE(sampling_tb), 3);
1259   gtk_box_pack_start(GTK_BOX(sampling_vb), sampling_tb, FALSE, FALSE, 0);
1260
1261   /* "No sampling" row */
1262   samp_none_rb = gtk_radio_button_new_with_label(NULL, "None");
1263   if (global_capture_opts.sampling_method == CAPTURE_SAMP_NONE)
1264     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(samp_none_rb), TRUE);
1265   g_signal_connect(samp_none_rb, "toggled",
1266                  G_CALLBACK(options_prep_adjust_sensitivity), opt_remote_w);
1267   gtk_table_attach_defaults(GTK_TABLE(sampling_tb), samp_none_rb, 0, 1, 0, 1);
1268
1269   /* "Sampling by counter" row */
1270   samp_group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(samp_none_rb));
1271   samp_count_rb = gtk_radio_button_new_with_label(samp_group, "1 of");
1272   if (global_capture_opts.sampling_method == CAPTURE_SAMP_BY_COUNT)
1273     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(samp_count_rb), TRUE);
1274   g_signal_connect(samp_count_rb, "toggled",
1275                  G_CALLBACK(options_prep_adjust_sensitivity), opt_remote_w);
1276   gtk_table_attach_defaults(GTK_TABLE(sampling_tb), samp_count_rb, 0, 1, 1, 2);
1277
1278   samp_count_adj = (GtkAdjustment *) gtk_adjustment_new(
1279                         (gfloat)global_capture_opts.sampling_param,
1280                         1, (gfloat)INT_MAX, 1.0, 10.0, 0.0);
1281   samp_count_sb = gtk_spin_button_new(samp_count_adj, 0, 0);
1282   gtk_spin_button_set_wrap(GTK_SPIN_BUTTON(samp_count_sb), TRUE);
1283   gtk_table_attach_defaults(GTK_TABLE(sampling_tb), samp_count_sb, 1, 2, 1, 2);
1284
1285   sampling_lb = gtk_label_new("packets");
1286   gtk_misc_set_alignment(GTK_MISC(sampling_lb), 0, 0.5);
1287   gtk_table_attach_defaults(GTK_TABLE(sampling_tb), sampling_lb, 2, 3, 1, 2);
1288
1289   /* "Sampling by timer" row */
1290   samp_group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(samp_count_rb));
1291   samp_timer_rb = gtk_radio_button_new_with_label(samp_group, "1 every");
1292   if (global_capture_opts.sampling_method == CAPTURE_SAMP_BY_TIMER)
1293     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(samp_timer_rb), TRUE);
1294   g_signal_connect(samp_timer_rb, "toggled",
1295                  G_CALLBACK(options_prep_adjust_sensitivity), opt_remote_w);
1296   gtk_table_attach_defaults(GTK_TABLE(sampling_tb), samp_timer_rb, 0, 1, 2, 3);
1297
1298   samp_timer_adj = (GtkAdjustment *) gtk_adjustment_new(
1299                         (gfloat)global_capture_opts.sampling_param,
1300                         1, (gfloat)INT_MAX, 1.0, 10.0, 0.0);
1301   samp_timer_sb = gtk_spin_button_new(samp_timer_adj, 0, 0);
1302   gtk_spin_button_set_wrap(GTK_SPIN_BUTTON(samp_timer_sb), TRUE);
1303   gtk_table_attach_defaults(GTK_TABLE(sampling_tb), samp_timer_sb, 1, 2, 2, 3);
1304
1305   sampling_lb = gtk_label_new("milliseconds");
1306   gtk_misc_set_alignment(GTK_MISC(sampling_lb), 0, 0.5);
1307   gtk_table_attach_defaults(GTK_TABLE(sampling_tb), sampling_lb, 2, 3, 2, 3);
1308 #endif
1309
1310   /* Button row: "Start" and "Cancel" buttons */
1311   bbox = dlg_button_row_new(GTK_STOCK_OK, GTK_STOCK_CANCEL, NULL);
1312   gtk_box_pack_start(GTK_BOX(main_vb), bbox, FALSE, FALSE, 5);
1313
1314   ok_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_OK);
1315   g_signal_connect(ok_bt, "clicked", G_CALLBACK(options_remote_ok_cb), opt_remote_w);
1316   gtk_tooltips_set_tip(tooltips, ok_bt,
1317                        "Accept parameters and close dialog.", NULL);
1318
1319   cancel_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CANCEL);
1320   gtk_tooltips_set_tip(tooltips, cancel_bt,
1321                          "Cancel and exit dialog.", NULL);
1322   window_set_cancel_button(opt_remote_w, cancel_bt, window_cancel_button_cb);
1323
1324   gtk_widget_grab_default(ok_bt);
1325
1326   g_signal_connect(opt_remote_w, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
1327   g_signal_connect(opt_remote_w, "destroy", G_CALLBACK(options_remote_destroy_cb), NULL);
1328
1329   g_object_set_data(G_OBJECT(opt_remote_w), E_CAP_NOCAP_RPCAP_CB_KEY, nocap_rpcap_cb);
1330   g_object_set_data(G_OBJECT(opt_remote_w), E_CAP_DATATX_UDP_CB_KEY, datatx_udp_cb);
1331
1332 #ifdef HAVE_PCAP_SETSAMPLING
1333   g_object_set_data(G_OBJECT(opt_remote_w), E_CAP_SAMP_NONE_RB_KEY, samp_none_rb);
1334   g_object_set_data(G_OBJECT(opt_remote_w), E_CAP_SAMP_COUNT_RB_KEY, samp_count_rb);
1335   g_object_set_data(G_OBJECT(opt_remote_w), E_CAP_SAMP_COUNT_SB_KEY, samp_count_sb);
1336   g_object_set_data(G_OBJECT(opt_remote_w), E_CAP_SAMP_TIMER_RB_KEY, samp_timer_rb);
1337   g_object_set_data(G_OBJECT(opt_remote_w), E_CAP_SAMP_TIMER_SB_KEY, samp_timer_sb);
1338 #endif
1339
1340 #ifdef HAVE_PCAP_SETSAMPLING
1341   /* Set the sensitivity of various widgets as per the settings of other
1342      widgets. */
1343   options_prep_adjust_sensitivity(NULL, opt_remote_w);
1344 #endif
1345
1346   gtk_widget_show_all(opt_remote_w);
1347   window_present(opt_remote_w);
1348 }
1349
1350 static void
1351 recent_print_remote_host (gpointer key _U_, gpointer value, gpointer user)
1352 {
1353   FILE *rf = user;
1354   struct remote_host *ri = value;
1355
1356   fprintf (rf, RECENT_KEY_REMOTE_HOST ": %s,%s,%d\n", ri->remote_host, ri->remote_port, ri->auth_type);
1357 }
1358
1359 void
1360 capture_remote_combo_recent_write_all(FILE *rf)
1361 {
1362   if (remote_host_list && g_hash_table_size (remote_host_list) > 0) {
1363     /* Write all remote interfaces to the recent file */
1364     g_hash_table_foreach (remote_host_list, recent_print_remote_host, rf);
1365   }
1366 }
1367
1368 gboolean
1369 capture_remote_combo_add_recent(gchar *s) 
1370 {
1371   GList *vals = prefs_get_string_list (s);
1372   GList *valp = vals;
1373   struct remote_host *rh;
1374   gint auth_type;
1375   char *p;
1376
1377   if (valp == NULL)
1378     return FALSE;
1379
1380   if (remote_host_list == NULL) {
1381     remote_host_list = g_hash_table_new (g_str_hash, g_str_equal);
1382   }
1383
1384   rh = g_malloc (sizeof (*rh));
1385
1386   /* First value is the host */
1387   rh->remote_host = g_strdup (valp->data);
1388   if (strlen(rh->remote_host) == 0)
1389     /* Empty remote host */
1390     return FALSE;
1391   rh->auth_type = CAPTURE_AUTH_NULL;
1392   valp = valp->next;
1393
1394   if (valp) {
1395     /* Found value 2, this is the port number */
1396     rh->remote_port = g_strdup (valp->data);
1397     valp = valp->next;
1398   } else {
1399     /* Did not find a port number */
1400     rh->remote_port = g_strdup ("");
1401   }
1402   
1403   if (valp) {
1404     /* Found value 3, this is the authentication type */
1405     auth_type = strtol(valp->data, &p, 0);
1406     if (p != valp->data && *p == '\0') {
1407       rh->auth_type = auth_type;
1408     }
1409   }
1410
1411   /* Do not store username and password */
1412   rh->auth_username = g_strdup ("");
1413   rh->auth_password = g_strdup ("");
1414
1415   prefs_clear_string_list(vals);
1416
1417   g_hash_table_insert (remote_host_list, g_strdup(rh->remote_host), rh);
1418
1419   return TRUE;
1420 }
1421
1422 #endif
1423
1424 /* show capture prepare (options) dialog */
1425 void
1426 capture_prep_cb(GtkWidget *w _U_, gpointer d _U_)
1427 {
1428   GtkWidget     *main_vb,
1429                 *main_hb, *left_vb, *right_vb,
1430
1431                 *capture_fr, *capture_vb,
1432                 *if_hb, *if_cb, *if_lb,
1433                 *if_ip_hb, *if_ip_lb, *if_ip_eb,
1434                 *linktype_hb, *linktype_lb, *linktype_om,
1435                 *snap_hb, *snap_cb, *snap_sb, *snap_lb,
1436                 *promisc_cb, *pcap_ng_cb,
1437                 *filter_hb, *filter_bt, *filter_te, *filter_cm,
1438
1439                 *file_fr, *file_vb,
1440                 *file_hb, *file_bt, *file_lb, *file_te,
1441                 *multi_tb, *multi_files_on_cb,
1442                 *ring_filesize_cb, *ring_filesize_sb, *ring_filesize_cbx,
1443                 *file_duration_cb, *file_duration_sb, *file_duration_cbx,
1444                 *ringbuffer_nbf_cb, *ringbuffer_nbf_sb, *ringbuffer_nbf_lb,
1445                 *stop_files_cb, *stop_files_sb, *stop_files_lb,
1446
1447                 *limit_fr, *limit_vb, *limit_tb,
1448                 *stop_packets_cb, *stop_packets_sb, *stop_packets_lb,
1449                 *stop_filesize_cb, *stop_filesize_sb, *stop_filesize_cbx,
1450                 *stop_duration_cb, *stop_duration_sb, *stop_duration_cbx,
1451
1452                 *display_fr, *display_vb,
1453                 *sync_cb, *auto_scroll_cb, *hide_info_cb,
1454
1455                 *resolv_fr, *resolv_vb,
1456                 *m_resolv_cb, *n_resolv_cb, *t_resolv_cb,
1457                 *bbox, *ok_bt, *cancel_bt,
1458                 *help_bt;
1459 #ifdef HAVE_AIRPCAP
1460   GtkWidget     *advanced_bt;
1461   GtkWidget     *decryption_cb;
1462 #endif
1463 #ifdef HAVE_PCAP_REMOTE
1464   GtkWidget     *iftype_cbx;
1465   GtkWidget     *remote_bt;
1466 #endif
1467   GtkTooltips   *tooltips;
1468   GtkAdjustment *snap_adj, *ringbuffer_nbf_adj,
1469                 *stop_packets_adj, *stop_filesize_adj, *stop_duration_adj, *stop_files_adj, *ring_filesize_adj, *file_duration_adj;
1470   GList         *if_list, *combo_list, *cfilter_list;
1471   int           row;
1472   int           err;
1473   gchar         *err_str;
1474 #ifdef _WIN32
1475   GtkAdjustment *buffer_size_adj;
1476   GtkWidget     *buffer_size_lb, *buffer_size_sb, *buffer_size_hb;
1477 #endif
1478   guint32       value;
1479   gchar         *cap_title;
1480   gchar         *if_device;
1481
1482   if (cap_open_w != NULL) {
1483     /* There's already a "Capture Options" dialog box; reactivate it. */
1484     reactivate_window(cap_open_w);
1485     return;
1486   }
1487
1488 #ifdef _WIN32
1489   /* Is WPcap loaded? */
1490   if (!has_wpcap) {
1491     char *detailed_err;
1492
1493     detailed_err = cant_load_winpcap_err("Wireshark");
1494     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", detailed_err);
1495     g_free(detailed_err);
1496     return;
1497   }
1498 #endif
1499
1500   /* use user-defined title if preference is set */
1501   cap_title = create_user_window_title("Wireshark: Capture Options");
1502
1503   cap_open_w = dlg_window_new(cap_title);
1504   g_free(cap_title);
1505
1506   tooltips = gtk_tooltips_new();
1507
1508 #ifdef HAVE_PCAP_REMOTE
1509   if (global_capture_opts.src_type == CAPTURE_IFREMOTE) {
1510     if_list = get_remote_interface_list(global_capture_opts.remote_host,
1511                                         global_capture_opts.remote_port,
1512                                         global_capture_opts.auth_type,
1513                                         global_capture_opts.auth_username,
1514                                         global_capture_opts.auth_password,
1515                                         &err, NULL);
1516     if (if_list == NULL && err == CANT_GET_INTERFACE_LIST) {
1517       /* Silently fall back to local interface list */
1518       if (global_capture_opts.iface) {
1519         g_free (global_capture_opts.iface);
1520         global_capture_opts.iface = NULL;
1521       }
1522       if (global_capture_opts.iface_descr) {
1523         g_free (global_capture_opts.iface_descr);
1524         global_capture_opts.iface_descr = NULL;
1525       }
1526       if_list = capture_interface_list(&err, &err_str);
1527       global_capture_opts.src_type = CAPTURE_IFLOCAL;
1528       g_object_set_data(G_OBJECT(cap_open_w), E_CAP_IF_LIST_KEY, NULL);
1529     } else {
1530       g_object_set_data(G_OBJECT(cap_open_w), E_CAP_IF_LIST_KEY, if_list);
1531     }
1532   } else {
1533     if_list = capture_interface_list(&err, &err_str);
1534     g_object_set_data(G_OBJECT(cap_open_w), E_CAP_IF_LIST_KEY, NULL);
1535   }
1536 #else
1537   if_list = capture_interface_list(&err, &err_str);
1538 #endif
1539   if (if_list == NULL && err == CANT_GET_INTERFACE_LIST) {
1540     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_str);
1541     g_free(err_str);
1542   }
1543
1544 #ifdef HAVE_AIRPCAP
1545   /* update airpcap interface list */
1546
1547   /* load the airpcap interfaces */
1548   airpcap_if_list = get_airpcap_interface_list(&err, &err_str);
1549
1550   decryption_cb = g_object_get_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_DECRYPTION_KEY);
1551   update_decryption_mode_list(decryption_cb);
1552
1553   if (airpcap_if_list == NULL && err == CANT_GET_AIRPCAP_INTERFACE_LIST) {
1554     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_str);
1555     g_free(err_str);
1556   }
1557
1558   /* select the first ad default (THIS SHOULD BE CHANGED) */
1559   airpcap_if_active = airpcap_get_default_if(airpcap_if_list);
1560 #endif
1561
1562   main_vb = gtk_vbox_new(FALSE, 0);
1563   gtk_container_set_border_width(GTK_CONTAINER(main_vb), 5);
1564   gtk_container_add(GTK_CONTAINER(cap_open_w), main_vb);
1565
1566   /* Capture-related options frame */
1567   capture_fr = gtk_frame_new("Capture");
1568   gtk_container_add(GTK_CONTAINER(main_vb), capture_fr);
1569
1570   capture_vb = gtk_vbox_new(FALSE, 3);
1571   gtk_container_set_border_width(GTK_CONTAINER(capture_vb), 5);
1572   gtk_container_add(GTK_CONTAINER(capture_fr), capture_vb);
1573
1574   /* Interface row */
1575   if_hb = gtk_hbox_new(FALSE, 3);
1576   gtk_container_add(GTK_CONTAINER(capture_vb), if_hb);
1577
1578   if_lb = gtk_label_new("Interface:");
1579   gtk_box_pack_start(GTK_BOX(if_hb), if_lb, FALSE, FALSE, 3);
1580
1581 #ifdef HAVE_PCAP_REMOTE
1582   if (remote_host_list == NULL) {
1583     remote_host_list = g_hash_table_new (g_str_hash, g_str_equal);
1584   }
1585
1586   iftype_cbx = iftype_combo_box_new();
1587 #if GTK_CHECK_VERSION(2,6,0)
1588   gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (iftype_cbx), 
1589                                         iftype_combo_is_separator, NULL, NULL);
1590 #endif
1591   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_IFTYPE_CBX_KEY, iftype_cbx);
1592   gtk_tooltips_set_tip(tooltips, iftype_cbx,
1593                        "Choose to capture from local or remote interfaces.", NULL);
1594   gtk_box_pack_start(GTK_BOX(if_hb), iftype_cbx, FALSE, FALSE, 0);
1595 #endif
1596
1597   if_cb = gtk_combo_new();
1598   combo_list = build_capture_combo_list(if_list, TRUE);
1599   if (combo_list != NULL)
1600     gtk_combo_set_popdown_strings(GTK_COMBO(if_cb), combo_list);
1601   if (global_capture_opts.iface == NULL && prefs.capture_device != NULL) {
1602     /* No interface was specified on the command line or in a previous
1603        capture, but there is one specified in the preferences file;
1604        make the one from the preferences file the default */
1605     if_device = g_strdup(prefs.capture_device);
1606     global_capture_opts.iface = g_strdup(get_if_name(if_device));
1607     global_capture_opts.iface_descr = get_interface_descriptive_name(global_capture_opts.iface);
1608     g_free(if_device);
1609   }
1610
1611 #ifdef HAVE_AIRPCAP
1612   /* get the airpcap interface (if it IS an airpcap interface, and update the
1613      toolbar... and of course enable the advanced button...)*/
1614   airpcap_if_selected = get_airpcap_if_from_name(airpcap_if_list,global_capture_opts.iface);
1615 #endif
1616
1617   if (global_capture_opts.iface != NULL) {
1618     if_device = build_capture_combo_name(if_list, global_capture_opts.iface);
1619     gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(if_cb)->entry), if_device);
1620     g_free(if_device);
1621   } else if (combo_list != NULL) {
1622     gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(if_cb)->entry),
1623                        (char *)combo_list->data);
1624   }
1625   free_capture_combo_list(combo_list);
1626 #ifdef HAVE_PCAP_REMOTE
1627   /* Only delete if fetched local */
1628   if (global_capture_opts.src_type == CAPTURE_IFLOCAL)
1629 #endif
1630   free_interface_list(if_list);
1631   gtk_tooltips_set_tip(tooltips, GTK_COMBO(if_cb)->entry,
1632     "Choose which interface (network card) will be used to capture packets from. "
1633     "Be sure to select the correct one, as it's a common mistake to select the wrong interface.", NULL);
1634   gtk_box_pack_start(GTK_BOX(if_hb), if_cb, TRUE, TRUE, 3);
1635
1636   if_ip_hb = gtk_hbox_new(FALSE, 3);
1637   gtk_box_pack_start(GTK_BOX(capture_vb), if_ip_hb, FALSE, FALSE, 0);
1638
1639   if_ip_eb = gtk_event_box_new();
1640   gtk_event_box_set_visible_window (GTK_EVENT_BOX(if_ip_eb), FALSE);
1641   gtk_box_pack_start(GTK_BOX(if_ip_hb), if_ip_eb, TRUE, TRUE, 3);
1642   gtk_tooltips_set_tip(tooltips, if_ip_eb, "Lists the IP address(es) "
1643                        "assigned to the selected interface.  If there are "
1644                        "more addresses than will fit in the window, the "
1645                        "first few and the last few will be shown with \"...\" "
1646                        "between them.",
1647                        NULL);
1648
1649   if_ip_lb = gtk_label_new("");
1650   gtk_misc_set_alignment(GTK_MISC(if_ip_lb), 0, 0); /* Left justified */
1651   gtk_container_add(GTK_CONTAINER(if_ip_eb), if_ip_lb);
1652
1653   main_hb = gtk_hbox_new(FALSE, 5);
1654   gtk_container_set_border_width(GTK_CONTAINER(main_hb), 0);
1655   gtk_container_add(GTK_CONTAINER(capture_vb), main_hb);
1656
1657   left_vb = gtk_vbox_new(FALSE, 0);
1658   gtk_container_set_border_width(GTK_CONTAINER(left_vb), 0);
1659   gtk_box_pack_start(GTK_BOX(main_hb), left_vb, TRUE, TRUE, 0);
1660
1661 #if defined (HAVE_AIRPCAP) || defined (HAVE_PCAP_REMOTE) || defined (_WIN32)
1662   /* Avoid adding the right vbox if not needed, because it steals 3 pixels */
1663   right_vb = gtk_vbox_new(FALSE, 3);
1664   gtk_container_set_border_width(GTK_CONTAINER(right_vb), 0);
1665   gtk_box_pack_start(GTK_BOX(main_hb), right_vb, FALSE, FALSE, 3);
1666 #endif
1667
1668   /* Linktype row */
1669   linktype_hb = gtk_hbox_new(FALSE, 3);
1670   gtk_box_pack_start(GTK_BOX(left_vb), linktype_hb, FALSE, FALSE, 0);
1671
1672   linktype_lb = gtk_label_new("Link-layer header type:");
1673   gtk_box_pack_start(GTK_BOX(linktype_hb), linktype_lb, FALSE, FALSE, 3);
1674
1675   linktype_om = gtk_option_menu_new();
1676   g_object_set_data(G_OBJECT(linktype_om), E_CAP_LT_OM_LABEL_KEY, linktype_lb);
1677   /* Default to "use the default" */
1678   /* Datalink menu index is not resetted, it will be restored with last used value */
1679   /* g_object_set_data(G_OBJECT(linktype_om), E_CAP_OM_LT_VALUE_KEY, GINT_TO_POINTER(-1)); */
1680
1681   g_object_set_data(G_OBJECT(linktype_om), E_CAP_IFACE_KEY, if_ip_lb);
1682   dl_hdr_menu=NULL;
1683   if (linktype_history == NULL) {
1684     linktype_history = g_hash_table_new(g_str_hash, g_str_equal);
1685   }
1686   set_link_type_list(linktype_om, GTK_COMBO(if_cb)->entry);
1687   /*
1688    * XXX - in some cases, this is "multiple link-layer header types", e.g.
1689    * some 802.11 interfaces on FreeBSD 5.2 and later, where you can request
1690    * fake Ethernet, 802.11, or 802.11-plus-radio-information headers.
1691    *
1692    * In other cases, it's "multiple link-layer types", e.g., with recent
1693    * versions of libpcap, a DAG card on an "HDLC" WAN, where you can
1694    * request Cisco HDLC or PPP depending on what type of traffic is going
1695    * over the WAN, or an Ethernet interface, where you can request Ethernet
1696    * or DOCSIS, the latter being for some Cisco cable modem equipment that
1697    * can be configured to send raw DOCSIS frames over an Ethernet inside
1698    * Ethernet low-level framing, for traffic capture purposes.
1699    *
1700    * We leave it as "multiple link-layer types" for now.
1701    */
1702   gtk_tooltips_set_tip(tooltips, linktype_om,
1703     "The selected interface supports multiple link-layer types; select the desired one.", NULL);
1704   gtk_box_pack_start (GTK_BOX(linktype_hb), linktype_om, FALSE, FALSE, 0);
1705   g_signal_connect(GTK_ENTRY(GTK_COMBO(if_cb)->entry), "changed",
1706                  G_CALLBACK(capture_prep_interface_changed_cb), linktype_om);
1707
1708   /* Promiscuous mode row */
1709   promisc_cb = gtk_check_button_new_with_mnemonic(
1710       "Capture packets in _promiscuous mode");
1711   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(promisc_cb),
1712                 global_capture_opts.promisc_mode);
1713   gtk_tooltips_set_tip(tooltips, promisc_cb,
1714     "Usually a network card will only capture the traffic sent to its own network address. "
1715     "If you want to capture all traffic that the network card can \"see\", mark this option. "
1716     "See the FAQ for some more details of capturing packets from a switched network.", NULL);
1717   gtk_container_add(GTK_CONTAINER(left_vb), promisc_cb);
1718
1719   /* Pcap-NG row */
1720   pcap_ng_cb = gtk_check_button_new_with_mnemonic("Capture packets in pcap-ng format (experimental)");
1721   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pcap_ng_cb), global_capture_opts.use_pcapng);
1722   gtk_tooltips_set_tip(tooltips, pcap_ng_cb, "Capture packets in the next-generation capture file format. "
1723                        "This is still experimental.", NULL);
1724   gtk_container_add(GTK_CONTAINER(left_vb), pcap_ng_cb);
1725
1726   /* Capture length row */
1727   snap_hb = gtk_hbox_new(FALSE, 3);
1728   gtk_container_add(GTK_CONTAINER(left_vb), snap_hb);
1729
1730   snap_cb = gtk_check_button_new_with_mnemonic("_Limit each packet to");
1731   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(snap_cb),
1732                 global_capture_opts.has_snaplen);
1733   g_signal_connect(snap_cb, "toggled", G_CALLBACK(capture_prep_adjust_sensitivity), cap_open_w);
1734   gtk_tooltips_set_tip(tooltips, snap_cb,
1735     "Limit the maximum number of bytes to be captured from each packet. This size includes the "
1736     "link-layer header and all subsequent headers. ", NULL);
1737   gtk_box_pack_start(GTK_BOX(snap_hb), snap_cb, FALSE, FALSE, 0);
1738
1739   snap_adj = (GtkAdjustment *) gtk_adjustment_new((gfloat) global_capture_opts.snaplen,
1740     MIN_PACKET_SIZE, WTAP_MAX_PACKET_SIZE, 1.0, 10.0, 0.0);
1741   snap_sb = gtk_spin_button_new (snap_adj, 0, 0);
1742   gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (snap_sb), TRUE);
1743   gtk_widget_set_size_request(snap_sb, 80, -1);
1744   gtk_box_pack_start (GTK_BOX(snap_hb), snap_sb, FALSE, FALSE, 0);
1745
1746   snap_lb = gtk_label_new("bytes");
1747   gtk_misc_set_alignment(GTK_MISC(snap_lb), 0, 0.5f);
1748   gtk_box_pack_start(GTK_BOX(snap_hb), snap_lb, FALSE, FALSE, 0);
1749
1750   /* Filter row */
1751   filter_hb = gtk_hbox_new(FALSE, 3);
1752   gtk_box_pack_start(GTK_BOX(capture_vb), filter_hb, FALSE, FALSE, 0);
1753
1754   filter_bt = gtk_button_new_from_stock(WIRESHARK_STOCK_CAPTURE_FILTER_ENTRY);
1755   g_signal_connect(filter_bt, "clicked", G_CALLBACK(capture_filter_construct_cb), NULL);
1756   g_signal_connect(filter_bt, "destroy", G_CALLBACK(filter_button_destroy_cb), NULL);
1757   gtk_tooltips_set_tip(tooltips, filter_bt,
1758     "Select a capture filter to reduce the amount of packets to be captured. "
1759     "See \"Capture Filters\" in the online help for further information how to use it.",
1760     NULL);
1761   gtk_box_pack_start(GTK_BOX(filter_hb), filter_bt, FALSE, FALSE, 3);
1762
1763   /* Create the capture filter combo */
1764   filter_cm = gtk_combo_new();
1765
1766   cfilter_list = g_object_get_data(G_OBJECT(top_level), E_CFILTER_FL_KEY);
1767   gtk_combo_disable_activate(GTK_COMBO(filter_cm));
1768   gtk_combo_set_case_sensitive(GTK_COMBO(filter_cm), TRUE);
1769   g_object_set_data(G_OBJECT(top_level), E_CFILTER_FL_KEY, cfilter_list);
1770   g_object_set_data(G_OBJECT(top_level), E_CFILTER_CM_KEY, filter_cm);
1771   filter_te = GTK_COMBO(filter_cm)->entry;
1772
1773   if (cfilter_list != NULL)
1774     gtk_combo_set_popdown_strings(GTK_COMBO(filter_cm), cfilter_list);
1775   if (global_capture_opts.cfilter)
1776     gtk_entry_set_text(GTK_ENTRY(filter_te), global_capture_opts.cfilter);
1777   gtk_tooltips_set_tip(tooltips, filter_te,
1778     "Enter a capture filter to reduce the amount of packets to be captured. "
1779     "See \"Capture Filters\" in the online help for further information how to use it.",
1780     NULL);
1781   gtk_box_pack_start(GTK_BOX(filter_hb), filter_cm, TRUE, TRUE, 3);
1782
1783   /* let an eventually capture filters dialog know the text entry to fill in */
1784   g_object_set_data(G_OBJECT(filter_bt), E_FILT_TE_PTR_KEY, filter_te);
1785
1786   /* advanced row */
1787 #ifdef HAVE_AIRPCAP
1788   advanced_bt = gtk_button_new_with_label("Wireless Settings");
1789
1790   /* Both the callback and the data are global */
1791   g_signal_connect(advanced_bt,"clicked", G_CALLBACK(options_airpcap_advanced_cb),airpcap_tb);
1792   g_object_set_data(G_OBJECT(GTK_ENTRY(GTK_COMBO(if_cb)->entry)),AIRPCAP_OPTIONS_ADVANCED_KEY,advanced_bt);
1793
1794   if(airpcap_if_selected != NULL) {
1795     /* It is an airpcap interface */
1796     gtk_widget_set_sensitive(advanced_bt,TRUE);
1797   } else {
1798     gtk_widget_set_sensitive(advanced_bt,FALSE);
1799   }
1800
1801   gtk_box_pack_start(GTK_BOX(right_vb),advanced_bt,FALSE,FALSE,0);
1802   gtk_widget_show(advanced_bt);
1803 #endif
1804
1805 #ifdef HAVE_PCAP_REMOTE
1806   remote_bt = gtk_button_new_with_label("Remote Settings");
1807   gtk_tooltips_set_tip(tooltips, remote_bt, "Various settings for remote capture.", NULL);
1808
1809   /* Both the callback and the data are global */
1810   g_signal_connect(remote_bt,"clicked", G_CALLBACK(options_remote_cb),NULL);
1811   g_object_set_data(G_OBJECT(iftype_cbx), E_OPT_REMOTE_BT_KEY, remote_bt);
1812
1813   if (global_capture_opts.src_type == CAPTURE_IFREMOTE) {
1814     gtk_widget_set_sensitive(remote_bt, TRUE);
1815   } else {
1816     gtk_widget_set_sensitive(remote_bt, FALSE);
1817   }
1818
1819   gtk_box_pack_start(GTK_BOX(right_vb),remote_bt,FALSE,FALSE,0);
1820   gtk_widget_show(remote_bt);
1821 #endif
1822
1823 #ifdef _WIN32
1824   buffer_size_hb = gtk_hbox_new(FALSE, 3);
1825   buffer_size_lb = gtk_label_new("Buffer size:");
1826   gtk_box_pack_start (GTK_BOX(buffer_size_hb), buffer_size_lb, FALSE, FALSE, 0);
1827
1828   buffer_size_adj = (GtkAdjustment *) gtk_adjustment_new((gfloat) global_capture_opts.buffer_size,
1829     1, 65535, 1.0, 10.0, 0.0);
1830   buffer_size_sb = gtk_spin_button_new (buffer_size_adj, 0, 0);
1831   gtk_spin_button_set_value(GTK_SPIN_BUTTON (buffer_size_sb), (gfloat) global_capture_opts.buffer_size);
1832   gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (buffer_size_sb), TRUE);
1833   gtk_widget_set_size_request(buffer_size_sb, 80, -1);
1834   gtk_tooltips_set_tip(tooltips, buffer_size_sb,
1835     "The memory buffer size used while capturing. If you notice packet drops, you can try to increase this size.", NULL);
1836   gtk_box_pack_start (GTK_BOX(buffer_size_hb), buffer_size_sb, FALSE, FALSE, 0);
1837
1838   buffer_size_lb = gtk_label_new("megabyte(s)");
1839   gtk_box_pack_start (GTK_BOX(buffer_size_hb), buffer_size_lb, FALSE, FALSE, 3);
1840   gtk_box_pack_start (GTK_BOX(right_vb), buffer_size_hb, FALSE, FALSE, 0);
1841 #endif
1842
1843   main_hb = gtk_hbox_new(FALSE, 5);
1844   gtk_container_set_border_width(GTK_CONTAINER(main_hb), 0);
1845   gtk_container_add(GTK_CONTAINER(main_vb), main_hb);
1846
1847   left_vb = gtk_vbox_new(FALSE, 0);
1848   gtk_container_set_border_width(GTK_CONTAINER(left_vb), 0);
1849   gtk_box_pack_start(GTK_BOX(main_hb), left_vb, TRUE, TRUE, 0);
1850
1851   right_vb = gtk_vbox_new(FALSE, 0);
1852   gtk_container_set_border_width(GTK_CONTAINER(right_vb), 0);
1853   gtk_box_pack_start(GTK_BOX(main_hb), right_vb, FALSE, FALSE, 0);
1854
1855   /* Capture file-related options frame */
1856   file_fr = gtk_frame_new("Capture File(s)");
1857   gtk_container_add(GTK_CONTAINER(left_vb), file_fr);
1858
1859   file_vb = gtk_vbox_new(FALSE, 3);
1860   gtk_container_set_border_width(GTK_CONTAINER(file_vb), 5);
1861   gtk_container_add(GTK_CONTAINER(file_fr), file_vb);
1862
1863   /* File row */
1864   file_hb = gtk_hbox_new(FALSE, 3);
1865   gtk_box_pack_start(GTK_BOX(file_vb), file_hb, FALSE, FALSE, 0);
1866
1867   file_lb = gtk_label_new("File:");
1868   gtk_box_pack_start(GTK_BOX(file_hb), file_lb, FALSE, FALSE, 3);
1869
1870   file_te = gtk_entry_new();
1871   gtk_tooltips_set_tip(tooltips, file_te,
1872     "Enter the file name to which captured data will be written. "
1873     "If you don't enter something here, a temporary file will be used.",
1874     NULL);
1875   gtk_box_pack_start(GTK_BOX(file_hb), file_te, TRUE, TRUE, 3);
1876
1877   file_bt = gtk_button_new_from_stock(WIRESHARK_STOCK_BROWSE);
1878   gtk_tooltips_set_tip(tooltips, file_bt,
1879     "Select a file to which captured data will be written, "
1880     "instead of entering the file name directly. ",
1881     NULL);
1882   gtk_box_pack_start(GTK_BOX(file_hb), file_bt, FALSE, FALSE, 0);
1883
1884   g_signal_connect(file_bt, "clicked", G_CALLBACK(capture_prep_file_cb), file_te);
1885
1886   /* multiple files table */
1887   multi_tb = gtk_table_new(5, 3, FALSE);
1888   gtk_table_set_row_spacings(GTK_TABLE(multi_tb), 1);
1889   gtk_table_set_col_spacings(GTK_TABLE(multi_tb), 3);
1890   gtk_box_pack_start(GTK_BOX(file_vb), multi_tb, FALSE, FALSE, 0);
1891   row = 0;
1892
1893   /* multiple files row */
1894   multi_files_on_cb = gtk_check_button_new_with_mnemonic("Use _multiple files");
1895   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(multi_files_on_cb),
1896                 global_capture_opts.multi_files_on);
1897   g_signal_connect(multi_files_on_cb, "toggled", G_CALLBACK(capture_prep_adjust_sensitivity),
1898                  cap_open_w);
1899   gtk_tooltips_set_tip(tooltips, multi_files_on_cb,
1900     "Instead of using a single capture file, multiple files will be created. "
1901     "The generated file names will contain an incrementing number and the start time of the capture.", NULL);
1902   gtk_table_attach_defaults(GTK_TABLE(multi_tb), multi_files_on_cb, 0, 1, row, row+1);
1903   row++;
1904
1905   /* Ring buffer filesize row */
1906   ring_filesize_cb = gtk_check_button_new_with_label("Next file every");
1907   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ring_filesize_cb),
1908                 global_capture_opts.has_autostop_filesize || !global_capture_opts.has_file_duration);
1909   g_signal_connect(ring_filesize_cb, "toggled", G_CALLBACK(capture_prep_adjust_sensitivity), cap_open_w);
1910   gtk_tooltips_set_tip(tooltips, ring_filesize_cb,
1911     "If the selected file size is exceeded, capturing switches to the next file.\n"
1912     "PLEASE NOTE: at least one of the \"Next file every\" options MUST be selected.",
1913     NULL);
1914   gtk_table_attach_defaults(GTK_TABLE(multi_tb), ring_filesize_cb, 0, 1, row, row+1);
1915
1916   ring_filesize_adj = (GtkAdjustment *) gtk_adjustment_new(0.0,
1917     1, (gfloat)INT_MAX, 1.0, 10.0, 0.0);
1918   ring_filesize_sb = gtk_spin_button_new (ring_filesize_adj, 0, 0);
1919   gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (ring_filesize_sb), TRUE);
1920   gtk_widget_set_size_request(ring_filesize_sb, 80, -1);
1921   gtk_table_attach_defaults(GTK_TABLE(multi_tb), ring_filesize_sb, 1, 2, row, row+1);
1922
1923   ring_filesize_cbx = size_unit_combo_box_new(global_capture_opts.autostop_filesize);
1924   gtk_table_attach_defaults(GTK_TABLE(multi_tb), ring_filesize_cbx, 2, 3, row, row+1);
1925
1926   value = size_unit_combo_box_set_value(global_capture_opts.autostop_filesize);
1927   gtk_adjustment_set_value(ring_filesize_adj, (gfloat) value);
1928
1929   row++;
1930
1931   /* Ring buffer duration row */
1932   file_duration_cb = gtk_check_button_new_with_label("Next file every");
1933   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(file_duration_cb),
1934                               global_capture_opts.has_file_duration);
1935   g_signal_connect(file_duration_cb, "toggled",
1936                  G_CALLBACK(capture_prep_adjust_sensitivity), cap_open_w);
1937   gtk_tooltips_set_tip(tooltips, file_duration_cb,
1938     "If the selected duration is exceeded, capturing switches to the next file.\n"
1939     "PLEASE NOTE: at least one of the \"Next file every\" options MUST be selected.",
1940     NULL);
1941   gtk_table_attach_defaults(GTK_TABLE(multi_tb), file_duration_cb, 0, 1, row, row+1);
1942
1943   file_duration_adj = (GtkAdjustment *)gtk_adjustment_new(0.0,
1944     1, (gfloat)INT_MAX, 1.0, 10.0, 0.0);
1945   file_duration_sb = gtk_spin_button_new (file_duration_adj, 0, 0);
1946   gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (file_duration_sb), TRUE);
1947   gtk_widget_set_size_request(file_duration_sb, 80, -1);
1948   gtk_table_attach_defaults(GTK_TABLE(multi_tb), file_duration_sb, 1, 2, row, row+1);
1949
1950   file_duration_cbx = time_unit_combo_box_new(global_capture_opts.file_duration);
1951   gtk_table_attach_defaults(GTK_TABLE(multi_tb), file_duration_cbx, 2, 3, row, row+1);
1952
1953   value = time_unit_combo_box_convert_value(global_capture_opts.file_duration);
1954   gtk_adjustment_set_value(file_duration_adj, (gfloat) value);
1955   row++;
1956
1957   /* Ring buffer files row */
1958   ringbuffer_nbf_cb = gtk_check_button_new_with_label("Ring buffer with");
1959   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ringbuffer_nbf_cb),
1960                 global_capture_opts.has_ring_num_files);
1961   g_signal_connect(ringbuffer_nbf_cb, "toggled", G_CALLBACK(capture_prep_adjust_sensitivity), cap_open_w);
1962   gtk_tooltips_set_tip(tooltips, ringbuffer_nbf_cb,
1963     "After capturing has switched to the next file and the given number of files has exceeded, "
1964     "the oldest file will be removed.",
1965     NULL);
1966   gtk_table_attach_defaults(GTK_TABLE(multi_tb), ringbuffer_nbf_cb, 0, 1, row, row+1);
1967
1968   ringbuffer_nbf_adj = (GtkAdjustment *) gtk_adjustment_new((gfloat) global_capture_opts.ring_num_files,
1969     2/*RINGBUFFER_MIN_NUM_FILES*/, RINGBUFFER_MAX_NUM_FILES, 1.0, 10.0, 0.0);
1970   ringbuffer_nbf_sb = gtk_spin_button_new (ringbuffer_nbf_adj, 0, 0);
1971   gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (ringbuffer_nbf_sb), TRUE);
1972   gtk_widget_set_size_request(ringbuffer_nbf_sb, 80, -1);
1973   g_signal_connect(ringbuffer_nbf_sb, "changed", G_CALLBACK(capture_prep_adjust_sensitivity), cap_open_w);
1974   gtk_table_attach_defaults(GTK_TABLE(multi_tb), ringbuffer_nbf_sb, 1, 2, row, row+1);
1975
1976   ringbuffer_nbf_lb = gtk_label_new("files");
1977   gtk_misc_set_alignment(GTK_MISC(ringbuffer_nbf_lb), 0, 0.5f);
1978   gtk_table_attach_defaults(GTK_TABLE(multi_tb), ringbuffer_nbf_lb, 2, 3, row, row+1);
1979   row++;
1980
1981   /* Files row */
1982   stop_files_cb = gtk_check_button_new_with_label("Stop capture after");
1983   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(stop_files_cb),
1984                 global_capture_opts.has_autostop_files);
1985   g_signal_connect(stop_files_cb, "toggled", G_CALLBACK(capture_prep_adjust_sensitivity), cap_open_w);
1986   gtk_tooltips_set_tip(tooltips, stop_files_cb,
1987     "Stop capturing after the given number of \"file switches\" have been done.", NULL);
1988   gtk_table_attach_defaults(GTK_TABLE(multi_tb), stop_files_cb, 0, 1, row, row+1);
1989
1990   stop_files_adj = (GtkAdjustment *) gtk_adjustment_new((gfloat)global_capture_opts.autostop_files,
1991     1, (gfloat)INT_MAX, 1.0, 10.0, 0.0);
1992   stop_files_sb = gtk_spin_button_new (stop_files_adj, 0, 0);
1993   gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (stop_files_sb), TRUE);
1994   gtk_widget_set_size_request(stop_files_sb, 80, -1);
1995   gtk_table_attach_defaults(GTK_TABLE(multi_tb), stop_files_sb, 1, 2, row, row+1);
1996
1997   stop_files_lb = gtk_label_new("file(s)");
1998   gtk_misc_set_alignment(GTK_MISC(stop_files_lb), 0, 0.5f);
1999   gtk_table_attach_defaults(GTK_TABLE(multi_tb), stop_files_lb, 2, 3, row, row+1);
2000   row++;
2001
2002   /* Capture limits frame */
2003   limit_fr = gtk_frame_new("Stop Capture ...");
2004   gtk_container_add(GTK_CONTAINER(left_vb), limit_fr);
2005
2006   limit_vb = gtk_vbox_new(FALSE, 3);
2007   gtk_container_set_border_width(GTK_CONTAINER(limit_vb), 5);
2008   gtk_container_add(GTK_CONTAINER(limit_fr), limit_vb);
2009
2010   /* limits table */
2011   limit_tb = gtk_table_new(3, 3, FALSE);
2012   gtk_table_set_row_spacings(GTK_TABLE(limit_tb), 1);
2013   gtk_table_set_col_spacings(GTK_TABLE(limit_tb), 3);
2014   gtk_box_pack_start(GTK_BOX(limit_vb), limit_tb, FALSE, FALSE, 0);
2015   row = 0;
2016
2017   /* Packet count row */
2018   stop_packets_cb = gtk_check_button_new_with_label("... after");
2019   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(stop_packets_cb),
2020                 global_capture_opts.has_autostop_packets);
2021   g_signal_connect(stop_packets_cb, "toggled", G_CALLBACK(capture_prep_adjust_sensitivity), cap_open_w);
2022   gtk_tooltips_set_tip(tooltips, stop_packets_cb,
2023     "Stop capturing after the given number of packets have been captured.", NULL);
2024   gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_packets_cb, 0, 1, row, row+1);
2025
2026   stop_packets_adj = (GtkAdjustment *) gtk_adjustment_new((gfloat)global_capture_opts.autostop_packets,
2027     1, (gfloat)INT_MAX, 1.0, 10.0, 0.0);
2028   stop_packets_sb = gtk_spin_button_new (stop_packets_adj, 0, 0);
2029   gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (stop_packets_sb), TRUE);
2030   gtk_widget_set_size_request(stop_packets_sb, 80, -1);
2031   gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_packets_sb, 1, 2, row, row+1);
2032
2033   stop_packets_lb = gtk_label_new("packet(s)");
2034   gtk_misc_set_alignment(GTK_MISC(stop_packets_lb), 0, 0.5f);
2035   gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_packets_lb, 2, 3, row, row+1);
2036   row++;
2037
2038   /* Filesize row */
2039   stop_filesize_cb = gtk_check_button_new_with_label("... after");
2040   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(stop_filesize_cb),
2041                 global_capture_opts.has_autostop_filesize);
2042   g_signal_connect(stop_filesize_cb, "toggled", G_CALLBACK(capture_prep_adjust_sensitivity), cap_open_w);
2043   gtk_tooltips_set_tip(tooltips, stop_filesize_cb,
2044     "Stop capturing after the given amount of capture data has been captured.", NULL);
2045   gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_filesize_cb, 0, 1, row, row+1);
2046
2047   stop_filesize_adj = (GtkAdjustment *) gtk_adjustment_new(0.0,
2048     1, (gfloat)INT_MAX, 1.0, 10.0, 0.0);
2049   stop_filesize_sb = gtk_spin_button_new (stop_filesize_adj, 0, 0);
2050   gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (stop_filesize_sb), TRUE);
2051   gtk_widget_set_size_request(stop_filesize_sb, 80, -1);
2052   gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_filesize_sb, 1, 2, row, row+1);
2053
2054   stop_filesize_cbx = size_unit_combo_box_new(global_capture_opts.autostop_filesize);
2055   gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_filesize_cbx, 2, 3, row, row+1);
2056
2057   value = size_unit_combo_box_set_value(global_capture_opts.autostop_filesize);
2058   gtk_adjustment_set_value(stop_filesize_adj, (gfloat) value);
2059
2060   row++;
2061
2062   /* Duration row */
2063   stop_duration_cb = gtk_check_button_new_with_label("... after");
2064   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(stop_duration_cb),
2065                 global_capture_opts.has_autostop_duration);
2066   g_signal_connect(stop_duration_cb, "toggled", G_CALLBACK(capture_prep_adjust_sensitivity), cap_open_w);
2067   gtk_tooltips_set_tip(tooltips, stop_duration_cb,
2068     "Stop capturing after the given time is exceeded.", NULL);
2069   gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_duration_cb, 0, 1, row, row+1);
2070
2071   stop_duration_adj = (GtkAdjustment *) gtk_adjustment_new(0.0,
2072     1, (gfloat)INT_MAX, 1.0, 10.0, 0.0);
2073   stop_duration_sb = gtk_spin_button_new (stop_duration_adj, 0, 0);
2074   gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (stop_duration_sb), TRUE);
2075   gtk_widget_set_size_request(stop_duration_sb, 80, -1);
2076   gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_duration_sb, 1, 2, row, row+1);
2077
2078   stop_duration_cbx = time_unit_combo_box_new(global_capture_opts.autostop_duration);
2079   gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_duration_cbx, 2, 3, row, row+1);
2080
2081   value = time_unit_combo_box_convert_value(global_capture_opts.autostop_duration);
2082   gtk_adjustment_set_value(stop_duration_adj, (gfloat) value);
2083   row++;
2084
2085   /* Display-related options frame */
2086   display_fr = gtk_frame_new("Display Options");
2087   gtk_container_add(GTK_CONTAINER(right_vb), display_fr);
2088
2089   display_vb = gtk_vbox_new(FALSE, 0);
2090   gtk_container_set_border_width(GTK_CONTAINER(display_vb), 5);
2091   gtk_container_add(GTK_CONTAINER(display_fr), display_vb);
2092
2093   /* "Update display in real time" row */
2094   sync_cb = gtk_check_button_new_with_mnemonic(
2095       "_Update list of packets in real time");
2096   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(sync_cb),
2097                 global_capture_opts.real_time_mode);
2098   g_signal_connect(sync_cb, "toggled", G_CALLBACK(capture_prep_adjust_sensitivity), cap_open_w);
2099   gtk_tooltips_set_tip(tooltips, sync_cb,
2100     "Using this option will show the captured packets immediately on the main screen. "
2101     "Please note: this will slow down capturing, so increased packet drops might appear.", NULL);
2102   gtk_container_add(GTK_CONTAINER(display_vb), sync_cb);
2103
2104   /* "Auto-scroll live update" row */
2105   auto_scroll_cb = gtk_check_button_new_with_mnemonic(
2106                 "_Automatic scrolling in live capture");
2107   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(auto_scroll_cb), auto_scroll_live);
2108   gtk_tooltips_set_tip(tooltips, auto_scroll_cb,
2109     "This will scroll the \"Packet List\" automatically to the latest captured packet, "
2110     "when the \"Update List of packets in real time\" option is used.", NULL);
2111   gtk_container_add(GTK_CONTAINER(display_vb), auto_scroll_cb);
2112
2113   /* "Hide capture info" row */
2114   hide_info_cb = gtk_check_button_new_with_mnemonic(
2115                 "_Hide capture info dialog");
2116   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(hide_info_cb), !global_capture_opts.show_info);
2117   gtk_tooltips_set_tip(tooltips, hide_info_cb,
2118     "Hide the capture info dialog while capturing.", NULL);
2119   gtk_container_add(GTK_CONTAINER(display_vb), hide_info_cb);
2120
2121   /* Name Resolution frame */
2122   resolv_fr = gtk_frame_new("Name Resolution");
2123   gtk_container_add(GTK_CONTAINER(right_vb), resolv_fr);
2124
2125   resolv_vb = gtk_vbox_new(FALSE, 0);
2126   gtk_container_set_border_width(GTK_CONTAINER(resolv_vb), 5);
2127   gtk_container_add(GTK_CONTAINER(resolv_fr), resolv_vb);
2128
2129   m_resolv_cb = gtk_check_button_new_with_mnemonic(
2130                 "Enable _MAC name resolution");
2131   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_resolv_cb),
2132                 g_resolv_flags & RESOLV_MAC);
2133   gtk_tooltips_set_tip(tooltips, m_resolv_cb,
2134     "Perform MAC layer name resolution while capturing.", NULL);
2135   gtk_container_add(GTK_CONTAINER(resolv_vb), m_resolv_cb);
2136
2137   n_resolv_cb = gtk_check_button_new_with_mnemonic(
2138                 "Enable _network name resolution");
2139   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(n_resolv_cb),
2140                 g_resolv_flags & RESOLV_NETWORK);
2141   gtk_tooltips_set_tip(tooltips, n_resolv_cb,
2142     "Perform network layer name resolution while capturing.", NULL);
2143   gtk_container_add(GTK_CONTAINER(resolv_vb), n_resolv_cb);
2144
2145   t_resolv_cb = gtk_check_button_new_with_mnemonic(
2146                 "Enable _transport name resolution");
2147   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(t_resolv_cb),
2148                 g_resolv_flags & RESOLV_TRANSPORT);
2149   gtk_tooltips_set_tip(tooltips, t_resolv_cb,
2150     "Perform transport layer name resolution while capturing.", NULL);
2151   gtk_container_add(GTK_CONTAINER(resolv_vb), t_resolv_cb);
2152
2153   /* Button row: "Start", "Cancel" and "Help" buttons */
2154   bbox = dlg_button_row_new(WIRESHARK_STOCK_CAPTURE_START, GTK_STOCK_CANCEL, GTK_STOCK_HELP, NULL);
2155   gtk_box_pack_start(GTK_BOX(main_vb), bbox, FALSE, FALSE, 5);
2156
2157   ok_bt = g_object_get_data(G_OBJECT(bbox), WIRESHARK_STOCK_CAPTURE_START);
2158   g_signal_connect(ok_bt, "clicked", G_CALLBACK(capture_start_cb), cap_open_w);
2159   gtk_tooltips_set_tip(tooltips, ok_bt,
2160     "Start the capture process.", NULL);
2161
2162   cancel_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CANCEL);
2163   gtk_tooltips_set_tip(tooltips, cancel_bt,
2164     "Cancel and exit dialog.", NULL);
2165   window_set_cancel_button(cap_open_w, cancel_bt, capture_cancel_cb);
2166
2167   help_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_HELP);
2168   gtk_tooltips_set_tip(tooltips, help_bt,
2169     "Show help about capturing.", NULL);
2170   g_signal_connect(help_bt, "clicked", G_CALLBACK(topic_cb), (gpointer)HELP_CAPTURE_OPTIONS_DIALOG);
2171
2172   gtk_widget_grab_default(ok_bt);
2173
2174   /* Attach pointers to needed widgets to the capture prefs window/object */
2175   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_IFACE_KEY, if_cb);
2176 #ifdef HAVE_PCAP_REMOTE
2177   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_REMOTE_DIALOG_PTR_KEY, NULL);
2178 #endif
2179   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_SNAP_CB_KEY, snap_cb);
2180   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_SNAP_SB_KEY, snap_sb);
2181   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_LT_OM_KEY, linktype_om);
2182 #ifdef _WIN32
2183   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_BUFFER_SIZE_SB_KEY, buffer_size_sb);
2184 #endif
2185   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_PROMISC_KEY, promisc_cb);
2186   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_PCAP_NG_KEY, pcap_ng_cb);
2187   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_FILT_KEY,  filter_te);
2188   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_FILE_TE_KEY,  file_te);
2189   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_MULTI_FILES_ON_CB_KEY,  multi_files_on_cb);
2190   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_RING_NBF_CB_KEY,  ringbuffer_nbf_cb);
2191   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_RING_NBF_SB_KEY,  ringbuffer_nbf_sb);
2192   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_RING_NBF_LB_KEY,  ringbuffer_nbf_lb);
2193   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_RING_FILESIZE_CB_KEY,  ring_filesize_cb);
2194   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_RING_FILESIZE_SB_KEY,  ring_filesize_sb);
2195   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_RING_FILESIZE_CBX_KEY,  ring_filesize_cbx);
2196   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_FILE_DURATION_CB_KEY,  file_duration_cb);
2197   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_FILE_DURATION_SB_KEY,  file_duration_sb);
2198   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_FILE_DURATION_CBX_KEY,  file_duration_cbx);
2199   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_SYNC_KEY,  sync_cb);
2200   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_AUTO_SCROLL_KEY, auto_scroll_cb);
2201   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_HIDE_INFO_KEY, hide_info_cb);
2202   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_STOP_PACKETS_CB_KEY, stop_packets_cb);
2203   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_STOP_PACKETS_SB_KEY, stop_packets_sb);
2204   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_STOP_PACKETS_LB_KEY, stop_packets_lb);
2205   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_STOP_FILESIZE_CB_KEY, stop_filesize_cb);
2206   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_STOP_FILESIZE_SB_KEY, stop_filesize_sb);
2207   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_STOP_FILESIZE_CBX_KEY, stop_filesize_cbx);
2208   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_STOP_DURATION_CB_KEY,  stop_duration_cb);
2209   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_STOP_DURATION_SB_KEY,  stop_duration_sb);
2210   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_STOP_DURATION_CBX_KEY,  stop_duration_cbx);
2211   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_STOP_FILES_CB_KEY, stop_files_cb);
2212   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_STOP_FILES_SB_KEY, stop_files_sb);
2213   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_STOP_FILES_LB_KEY, stop_files_lb);
2214   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_M_RESOLVE_KEY,  m_resolv_cb);
2215   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_N_RESOLVE_KEY,  n_resolv_cb);
2216   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_T_RESOLVE_KEY,  t_resolv_cb);
2217
2218   /* Set the sensitivity of various widgets as per the settings of other
2219      widgets. */
2220   capture_prep_adjust_sensitivity(NULL, cap_open_w);
2221
2222   /* Catch the "activate" signal on the text
2223      entries, so that if the user types Return there, we act as if the
2224      "OK" button had been selected, as happens if Return is typed if some
2225      widget that *doesn't* handle the Return key has the input focus. */
2226   dlg_set_activate(GTK_COMBO(if_cb)->entry, ok_bt);
2227   dlg_set_activate(filter_te, ok_bt);
2228   dlg_set_activate(file_te, ok_bt);
2229
2230   /* XXX - why does not
2231
2232      gtk_widget_grab_focus(if_cb);
2233
2234     give the initial focus to the "Interface" combo box?
2235
2236     Or should I phrase that as "why does GTK+ continually frustrate
2237     attempts to make GUIs driveable from the keyboard?"  We have to
2238     go catch the activate signal on every single GtkEntry widget
2239     (rather than having widgets whose activate signal is *not*
2240     caught not catch the Return keystroke, so that it passes on,
2241     ultimately, to the window, which can activate the default
2242     widget, i.e. the "OK" button); we have to catch the "key_press_event"
2243     signal and have the handler check for ESC, so that we can have ESC
2244     activate the "Cancel" button; in order to support Alt+<key> mnemonics
2245     for buttons and the like, we may have to construct an accelerator
2246     group by hand and set up the accelerators by hand (if that even
2247     works - I've not tried it yet); we have to do a "gtk_widget_grab_focus()"
2248     to keep some container widget from getting the initial focus, so that
2249     you don't have to tab into the first widget in order to start typing
2250     in it; and it now appears that you simply *can't* make a combo box
2251     get the initial focus, at least not in the obvious fashion. Sigh.... */
2252
2253   g_signal_connect(cap_open_w, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
2254   g_signal_connect(cap_open_w, "destroy", G_CALLBACK(capture_prep_destroy_cb), NULL);
2255
2256   /* Give the initial focus to the "Filter" entry box. */
2257   gtk_widget_grab_focus(filter_te);
2258
2259   gtk_widget_show_all(cap_open_w);
2260   window_present(cap_open_w);
2261 }
2262
2263 /* everythings prepared, now it's really time to start the capture */
2264 void
2265 capture_start_confirmed(void)
2266 {
2267
2268
2269     /* init iface, if never used before */
2270     /* XXX - would better be doing this in main.c */
2271     if(global_capture_opts.iface == NULL) {
2272         gchar *if_device;
2273         const gchar *if_name;
2274
2275         /* did the user ever selected a capture interface before? */
2276         if(prefs.capture_device == NULL) {
2277             simple_dialog(ESD_TYPE_CONFIRMATION,
2278                         ESD_BTN_OK,
2279                         "%sNo capture interface selected!%s\n\n"
2280                         "To select an interface use:\n\n"
2281                         "Capture->Options (until Wireshark is stopped)\n"
2282                         "Edit->Preferences/Capture (permanent, if saved)",
2283                         simple_dialog_primary_start(), simple_dialog_primary_end());
2284             return;
2285         }
2286         if_device = g_strdup(prefs.capture_device);
2287         if_name = get_if_name(if_device);
2288         global_capture_opts.iface = g_strdup(if_name);
2289         global_capture_opts.iface_descr = get_interface_descriptive_name(global_capture_opts.iface);
2290
2291         g_free(if_device);
2292     }
2293
2294     /* XXX - we might need to init other pref data as well... */
2295     menu_auto_scroll_live_changed(auto_scroll_live);
2296
2297     if (capture_start(&global_capture_opts)) {
2298         /* The capture succeeded, which means the capture filter syntax is
2299         valid; add this capture filter to the recent capture filter list. */
2300         cfilter_combo_add_recent(global_capture_opts.cfilter);
2301     }
2302 }
2303
2304 /* user confirmed the "Save capture file..." dialog */
2305 static void
2306 capture_start_answered_cb(gpointer dialog _U_, gint btn, gpointer data)
2307 {
2308     switch(btn) {
2309     case(ESD_BTN_SAVE):
2310         /* save file first */
2311         file_save_as_cmd(after_save_capture_dialog, data);
2312         break;
2313     case(ESD_BTN_DONT_SAVE):
2314         /* XXX - unlink old file? */
2315         /* start the capture */
2316         capture_start_confirmed();
2317         break;
2318     case(ESD_BTN_CANCEL):
2319         break;
2320     default:
2321         g_assert_not_reached();
2322     }
2323 }
2324
2325 /* user pressed the "Start" button (in dialog or toolbar) */
2326 void
2327 capture_start_cb(GtkWidget *w _U_, gpointer d _U_)
2328 {
2329   gpointer  dialog;
2330   gchar *if_name;
2331   gint *linktype_p = NULL;
2332
2333 #ifdef HAVE_AIRPCAP
2334   airpcap_if_active = airpcap_if_selected;
2335   airpcap_set_toolbar_start_capture(airpcap_if_active);
2336 #endif
2337
2338 #ifdef _WIN32
2339   /* Is WPcap loaded? */
2340   if (!has_wpcap) {
2341     char * err_msg = cant_load_winpcap_err("Wireshark");
2342
2343     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, err_msg);
2344     g_free(err_msg);
2345     return;
2346   }
2347 #endif
2348
2349   if(cap_open_w) {
2350     /*
2351      * There's an options dialog; get the values from it and close it.
2352      */
2353     gboolean success;
2354
2355     success = capture_dlg_prep(cap_open_w);
2356     window_destroy(GTK_WIDGET(cap_open_w));
2357     if (!success)
2358       return;   /* error in options dialog */
2359   }
2360
2361   if (global_capture_opts.iface == NULL) {
2362     if (prefs.capture_device == NULL) {
2363       simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
2364         "You didn't specify an interface on which to capture packets.");
2365       return;
2366     }
2367     if_name = g_strdup(get_if_name(prefs.capture_device));
2368   } else {
2369     if_name = g_strdup(global_capture_opts.iface);
2370   }
2371
2372   if (linktype_history != NULL) {
2373     linktype_p = g_hash_table_lookup(linktype_history, if_name);
2374     if (linktype_p == NULL) {
2375       linktype_p = g_malloc(sizeof (int));
2376       g_hash_table_insert(linktype_history, if_name, linktype_p);
2377     } else {
2378       g_free(if_name);
2379     }
2380     *linktype_p = global_capture_opts.linktype;
2381   } else {
2382     global_capture_opts.linktype = capture_dev_user_linktype_find(if_name);
2383     g_free(if_name);
2384   }
2385
2386   if((cfile.state != FILE_CLOSED) && !cfile.user_saved && prefs.gui_ask_unsaved) {
2387     /* user didn't saved his current file, ask him */
2388     dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_SAVE_DONTSAVE_CANCEL,
2389                 "%sSave capture file before starting a new capture?%s\n\n"
2390                 "If you start a new capture without saving, your current capture data will\nbe discarded.",
2391                 simple_dialog_primary_start(), simple_dialog_primary_end());
2392     simple_dialog_set_cb(dialog, capture_start_answered_cb, NULL);
2393   } else {
2394     /* unchanged file, just capture a new one */
2395     capture_start_confirmed();
2396   }
2397 }
2398
2399 static void
2400 capture_cancel_cb(GtkWidget *win, gpointer data)
2401 {
2402 #ifdef HAVE_PCAP_REMOTE
2403   if (g_hash_table_size (remote_host_list) == 0) {
2404     /* Ensure we fall back to local interfaces */
2405     global_capture_opts.src_type = CAPTURE_IFLOCAL;
2406
2407     if (global_capture_opts.iface) {
2408       g_free (global_capture_opts.iface);
2409       global_capture_opts.iface = NULL;
2410     }
2411     if (global_capture_opts.iface_descr) {
2412       g_free (global_capture_opts.iface_descr);
2413       global_capture_opts.iface_descr = NULL;
2414     }
2415   }
2416 #endif
2417
2418   window_cancel_button_cb (win, data);
2419 }
2420
2421 /* user selected a link type, convert to internal value */
2422 static void
2423 select_link_type_cb(GtkWidget *w, gpointer data)
2424 {
2425   int new_linktype = GPOINTER_TO_INT(data);
2426   GtkWidget *linktype_om = g_object_get_data(G_OBJECT(w), E_CAP_LT_OM_KEY);
2427   int old_linktype = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(linktype_om), E_CAP_OM_LT_VALUE_KEY));
2428
2429   /* If the link is changed, update the menu and store the index and the value
2430      to reuse later when the dialog window will be reopened */
2431   if (old_linktype != new_linktype) {
2432     g_object_set_data(G_OBJECT(linktype_om), E_CAP_OM_LT_VALUE_KEY, GINT_TO_POINTER(new_linktype));
2433     global_capture_opts.linktype = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(linktype_om), E_CAP_OM_LT_VALUE_KEY));
2434   }
2435 }
2436
2437 #ifdef HAVE_PCAP_REMOTE
2438 static gboolean
2439 free_remote_host (gpointer key _U_, gpointer value, gpointer user _U_)
2440 {
2441   struct remote_host *rh = value;
2442
2443   g_free (rh->remote_host);
2444   g_free (rh->remote_port);
2445   g_free (rh->auth_username);
2446   g_free (rh->auth_password);
2447
2448   return TRUE;
2449 }
2450
2451 /* user selected an interface type (local/remote), convert to internal value) */
2452 static void
2453 select_if_type_cb(GtkComboBox *iftype_cbx, gpointer data _U_)
2454 {
2455   int new_iftype = gtk_combo_box_get_active(GTK_COMBO_BOX(iftype_cbx));
2456   int old_iftype = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(iftype_cbx),
2457                                                      E_CAP_CBX_IFTYPE_VALUE_KEY));
2458   int no_update = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(iftype_cbx),
2459                                                     E_CAP_CBX_IFTYPE_NOUPDATE_KEY));
2460   gint num_remote = g_hash_table_size (remote_host_list);
2461   
2462   if (new_iftype == CAPTURE_IFREMOTE) {
2463     g_object_set_data(G_OBJECT(iftype_cbx), E_CAP_CBX_PREV_IFTYPE_VALUE_KEY,
2464                       GINT_TO_POINTER(old_iftype));
2465     capture_remote_cb(GTK_WIDGET(iftype_cbx), FALSE);
2466   } else if (new_iftype != old_iftype) {
2467     if (new_iftype > CAPTURE_IFREMOTE) {
2468 #if GTK_CHECK_VERSION(2,6,0)
2469       if (new_iftype == num_remote + 4)
2470 #else
2471       if (new_iftype == num_remote + 2)
2472 #endif
2473       {
2474         /* The user selected the "Clear list" entry */
2475         new_iftype = CAPTURE_IFLOCAL;
2476         gtk_combo_box_set_active(GTK_COMBO_BOX(iftype_cbx), new_iftype);
2477         g_hash_table_foreach_remove (remote_host_list, free_remote_host, NULL);
2478         num_remote += 3;
2479         while (num_remote--)  /* Remove separator lines and "Clear" item */
2480           gtk_combo_box_remove_text (iftype_cbx, 2);
2481       } else {
2482         struct remote_host *rh;
2483         gchar *string;
2484 #if GTK_CHECK_VERSION(2,6,0)
2485         string = gtk_combo_box_get_active_text (GTK_COMBO_BOX(iftype_cbx));
2486 #else
2487         GtkTreeModel *model;
2488         GtkTreeIter iter;
2489
2490         model = gtk_combo_box_get_model(GTK_COMBO_BOX(iftype_cbx));
2491         gtk_combo_box_get_active_iter(GTK_COMBO_BOX(iftype_cbx), &iter);
2492         gtk_tree_model_get(model, &iter, 0, &string, -1);
2493 #endif
2494         rh = g_hash_table_lookup (remote_host_list, string);
2495         g_free (string);
2496         
2497         g_free(global_capture_opts.remote_host);
2498         global_capture_opts.remote_host = g_strdup(rh->remote_host);
2499         g_free(global_capture_opts.remote_port);
2500         global_capture_opts.remote_port = g_strdup(rh->remote_port);
2501         global_capture_opts.auth_type = rh->auth_type;
2502         if (global_capture_opts.auth_type == CAPTURE_AUTH_PWD && strlen(rh->auth_username) == 0) {
2503           /* Empty username, ask for one */
2504           capture_remote_cb(GTK_WIDGET(iftype_cbx), TRUE);
2505           no_update = TRUE;
2506         } else {
2507           /* Already entered username and password */
2508           g_free(global_capture_opts.auth_username);
2509           global_capture_opts.auth_username = g_strdup(rh->auth_username);
2510           g_free(global_capture_opts.auth_password);
2511           global_capture_opts.auth_password = g_strdup(rh->auth_password);
2512         }
2513       }
2514     }
2515     if (!no_update) {
2516       g_object_set_data(G_OBJECT(iftype_cbx), E_CAP_CBX_PREV_IFTYPE_VALUE_KEY,
2517                         GINT_TO_POINTER(old_iftype));
2518       g_object_set_data(G_OBJECT(iftype_cbx), E_CAP_CBX_IFTYPE_VALUE_KEY,
2519                         GINT_TO_POINTER(new_iftype));
2520       update_interface_list();
2521     }
2522   }
2523 }
2524 #endif
2525
2526 /* user pressed "File" button */
2527 static void
2528 capture_prep_file_cb(GtkWidget *file_bt, GtkWidget *file_te)
2529 {
2530     file_selection_browse(file_bt, file_te, "Wireshark: Specify a Capture File", FILE_SELECTION_WRITE_BROWSE);
2531 }
2532
2533
2534 /* convert dialog settings into capture_opts values */
2535 static gboolean
2536 capture_dlg_prep(gpointer parent_w) {
2537   GtkWidget *if_cb, *snap_cb, *snap_sb, *promisc_cb, *pcap_ng_cb, *filter_te, *filter_cm,
2538             *file_te, *multi_files_on_cb, *ringbuffer_nbf_sb, *ringbuffer_nbf_cb,
2539             *linktype_om, *sync_cb, *auto_scroll_cb, *hide_info_cb,
2540             *stop_packets_cb, *stop_packets_sb,
2541             *stop_filesize_cb, *stop_filesize_sb, *stop_filesize_cbx,
2542             *stop_duration_cb, *stop_duration_sb, *stop_duration_cbx,
2543             *ring_filesize_cb, *ring_filesize_sb, *ring_filesize_cbx,
2544             *file_duration_cb, *file_duration_sb, *file_duration_cbx,
2545             *stop_files_cb, *stop_files_sb,
2546             *m_resolv_cb, *n_resolv_cb, *t_resolv_cb;
2547 #ifdef HAVE_PCAP_REMOTE
2548   GtkWidget *iftype_cbx;
2549 #endif
2550 #ifdef _WIN32
2551   GtkWidget *buffer_size_sb;
2552 #endif
2553   gchar *entry_text;
2554   gchar *if_text;
2555   const gchar *if_name;
2556   const gchar *filter_text;
2557   const gchar *g_save_file;
2558   gchar *cf_name;
2559   gchar *dirname;
2560   gint32 tmp;
2561
2562   if_cb      = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_IFACE_KEY);
2563 #ifdef HAVE_PCAP_REMOTE
2564   iftype_cbx = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_IFTYPE_CBX_KEY);
2565 #endif
2566   snap_cb    = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_SNAP_CB_KEY);
2567   snap_sb    = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_SNAP_SB_KEY);
2568   linktype_om  = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_LT_OM_KEY);
2569 #ifdef _WIN32
2570   buffer_size_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_BUFFER_SIZE_SB_KEY);
2571 #endif
2572   promisc_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_PROMISC_KEY);
2573   pcap_ng_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_PCAP_NG_KEY);
2574   filter_cm  = g_object_get_data(G_OBJECT(top_level), E_CFILTER_CM_KEY);
2575   filter_te  = GTK_COMBO(filter_cm)->entry;
2576   file_te    = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_FILE_TE_KEY);
2577   multi_files_on_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_MULTI_FILES_ON_CB_KEY);
2578   ringbuffer_nbf_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_RING_NBF_CB_KEY);
2579   ringbuffer_nbf_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_RING_NBF_SB_KEY);
2580   ring_filesize_cb  = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_RING_FILESIZE_CB_KEY);
2581   ring_filesize_sb  = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_RING_FILESIZE_SB_KEY);
2582   ring_filesize_cbx = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_RING_FILESIZE_CBX_KEY);
2583   file_duration_cb  = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_FILE_DURATION_CB_KEY);
2584   file_duration_sb  = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_FILE_DURATION_SB_KEY);
2585   file_duration_cbx = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_FILE_DURATION_CBX_KEY);
2586   sync_cb   = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_SYNC_KEY);
2587   auto_scroll_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_AUTO_SCROLL_KEY);
2588   hide_info_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_HIDE_INFO_KEY);
2589   stop_packets_cb   = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_PACKETS_CB_KEY);
2590   stop_packets_sb   = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_PACKETS_SB_KEY);
2591   stop_filesize_cb  = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_FILESIZE_CB_KEY);
2592   stop_filesize_sb  = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_FILESIZE_SB_KEY);
2593   stop_filesize_cbx = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_FILESIZE_CBX_KEY);
2594   stop_duration_cb  = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_DURATION_CB_KEY);
2595   stop_duration_sb  = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_DURATION_SB_KEY);
2596   stop_duration_cbx = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_DURATION_CBX_KEY);
2597   stop_files_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_FILES_CB_KEY);
2598   stop_files_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_FILES_SB_KEY);
2599   m_resolv_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_M_RESOLVE_KEY);
2600   n_resolv_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_N_RESOLVE_KEY);
2601   t_resolv_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_T_RESOLVE_KEY);
2602
2603   entry_text =
2604     g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(if_cb)->entry)));
2605   if_text = g_strstrip(entry_text);
2606   if_name = get_if_name(if_text);
2607   if (*if_name == '\0') {
2608     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
2609       "You didn't specify an interface on which to capture packets.");
2610     g_free(entry_text);
2611     return FALSE;
2612   }
2613   g_free(global_capture_opts.iface);
2614   g_free(global_capture_opts.iface_descr);
2615   global_capture_opts.iface = g_strdup(if_name);
2616   global_capture_opts.iface_descr = get_interface_descriptive_name(global_capture_opts.iface);
2617   g_free(entry_text);
2618   /* The Linktype will be stored when the interface will be changed, or if not, not datalink option is used,
2619      the acquisition will be performed on the default datalink for the device */
2620   /*  global_capture_opts.linktype =
2621       GPOINTER_TO_INT(g_object_get_data(G_OBJECT(linktype_om), E_CAP_OM_LT_VALUE_KEY)); */
2622
2623 #ifdef HAVE_PCAP_REMOTE
2624   global_capture_opts.src_type = (capture_source)
2625       GPOINTER_TO_INT(g_object_get_data(G_OBJECT(iftype_cbx), E_CAP_CBX_IFTYPE_VALUE_KEY));
2626   if (global_capture_opts.src_type > CAPTURE_IFREMOTE)
2627     global_capture_opts.src_type = CAPTURE_IFREMOTE;
2628 #endif
2629
2630 #ifdef _WIN32
2631   global_capture_opts.buffer_size =
2632     gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(buffer_size_sb));
2633 #endif
2634
2635   global_capture_opts.has_snaplen =
2636     gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(snap_cb));
2637   if (global_capture_opts.has_snaplen) {
2638     global_capture_opts.snaplen =
2639       gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(snap_sb));
2640     if (global_capture_opts.snaplen < 1)
2641       global_capture_opts.snaplen = WTAP_MAX_PACKET_SIZE;
2642     else if (global_capture_opts.snaplen < MIN_PACKET_SIZE)
2643       global_capture_opts.snaplen = MIN_PACKET_SIZE;
2644   }
2645
2646   global_capture_opts.promisc_mode =
2647     gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(promisc_cb));
2648   global_capture_opts.use_pcapng =
2649     gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(pcap_ng_cb));
2650
2651   /* XXX - don't try to get clever and set "cfile.filter" to NULL if the
2652      filter string is empty, as an indication that we don't have a filter
2653      and thus don't have to set a filter when capturing - the version of
2654      libpcap in Red Hat Linux 6.1, and versions based on later patches
2655      in that series, don't bind the AF_PACKET socket to an interface
2656      until a filter is set, which means they aren't bound at all if
2657      no filter is set, which means no packets arrive as input on that
2658      socket, which means Wireshark never sees any packets. */
2659   filter_text = gtk_entry_get_text(GTK_ENTRY(filter_te));
2660   if (global_capture_opts.cfilter)
2661     g_free(global_capture_opts.cfilter);
2662   g_assert(filter_text != NULL);
2663   global_capture_opts.cfilter = g_strdup(filter_text);
2664
2665   /* Wireshark always saves to a capture file. */
2666   global_capture_opts.saving_to_file = TRUE;
2667   g_save_file = gtk_entry_get_text(GTK_ENTRY(file_te));
2668   if (g_save_file && g_save_file[0]) {
2669     /* User specified a file to which the capture should be written. */
2670     global_capture_opts.save_file = g_strdup(g_save_file);
2671     /* Save the directory name for future file dialogs. */
2672     cf_name = g_strdup(g_save_file);
2673     dirname = get_dirname(cf_name);  /* Overwrites cf_name */
2674     set_last_open_dir(dirname);
2675     g_free(cf_name);
2676   } else {
2677     /* User didn't specify a file; save to a temporary file. */
2678     global_capture_opts.save_file = NULL;
2679   }
2680
2681   global_capture_opts.has_autostop_packets =
2682     gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_packets_cb));
2683   if (global_capture_opts.has_autostop_packets)
2684     global_capture_opts.autostop_packets =
2685       gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(stop_packets_sb));
2686
2687   global_capture_opts.has_autostop_duration =
2688     gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_duration_cb));
2689   if (global_capture_opts.has_autostop_duration) {
2690     global_capture_opts.autostop_duration =
2691       gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(stop_duration_sb));
2692     global_capture_opts.autostop_duration =
2693       time_unit_combo_box_get_value(stop_duration_cbx, global_capture_opts.autostop_duration);
2694   }
2695
2696   global_capture_opts.real_time_mode =
2697     gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(sync_cb));
2698
2699   auto_scroll_live =
2700       gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(auto_scroll_cb));
2701
2702   global_capture_opts.show_info =
2703       !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(hide_info_cb));
2704
2705   if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m_resolv_cb)))
2706     g_resolv_flags |= RESOLV_MAC;
2707   else
2708     g_resolv_flags &= ~RESOLV_MAC;
2709   if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(n_resolv_cb)))
2710     g_resolv_flags |= RESOLV_NETWORK;
2711   else
2712     g_resolv_flags &= ~RESOLV_NETWORK;
2713   if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t_resolv_cb)))
2714     g_resolv_flags |= RESOLV_TRANSPORT;
2715   else
2716     g_resolv_flags &= ~RESOLV_TRANSPORT;
2717
2718   global_capture_opts.has_ring_num_files =
2719     gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ringbuffer_nbf_cb));
2720
2721   global_capture_opts.ring_num_files =
2722     gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(ringbuffer_nbf_sb));
2723   if (global_capture_opts.ring_num_files > RINGBUFFER_MAX_NUM_FILES)
2724     global_capture_opts.ring_num_files = RINGBUFFER_MAX_NUM_FILES;
2725 #if RINGBUFFER_MIN_NUM_FILES > 0
2726   else if (global_capture_opts.ring_num_files < RINGBUFFER_MIN_NUM_FILES)
2727     global_capture_opts.ring_num_files = RINGBUFFER_MIN_NUM_FILES;
2728 #endif
2729
2730   global_capture_opts.multi_files_on =
2731     gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(multi_files_on_cb));
2732
2733   global_capture_opts.has_file_duration =
2734     gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(file_duration_cb));
2735   if (global_capture_opts.has_file_duration) {
2736     global_capture_opts.file_duration =
2737       gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(file_duration_sb));
2738     global_capture_opts.file_duration =
2739       time_unit_combo_box_get_value(file_duration_cbx, global_capture_opts.file_duration);
2740   }
2741
2742   global_capture_opts.has_autostop_files =
2743     gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_files_cb));
2744   if (global_capture_opts.has_autostop_files)
2745     global_capture_opts.autostop_files =
2746       gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(stop_files_sb));
2747
2748   if (global_capture_opts.multi_files_on) {
2749     global_capture_opts.has_autostop_filesize =
2750       gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ring_filesize_cb));
2751     if (global_capture_opts.has_autostop_filesize) {
2752       tmp = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(ring_filesize_sb));
2753       tmp = size_unit_combo_box_convert_value(ring_filesize_cbx, tmp);
2754       if(tmp != 0) {
2755         global_capture_opts.autostop_filesize = tmp;
2756       } else {
2757         simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
2758           "%sMultiple files: Requested filesize too large!%s\n\n"
2759           "The setting \"Next file every x byte(s)\" can't be greater than %u bytes (2GB).", 
2760           simple_dialog_primary_start(), simple_dialog_primary_end(), G_MAXINT);
2761         return FALSE;
2762       }
2763     }
2764
2765     /* test if the settings are ok for a ringbuffer */
2766     if (global_capture_opts.save_file == NULL) {
2767       simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
2768         "%sMultiple files: No capture file name given!%s\n\n"
2769         "You must specify a filename if you want to use multiple files.",
2770         simple_dialog_primary_start(), simple_dialog_primary_end());
2771       return FALSE;
2772     } else if (!global_capture_opts.has_autostop_filesize && !global_capture_opts.has_file_duration) {
2773       simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
2774         "%sMultiple files: No file limit given!%s\n\n"
2775         "You must specify a file size or duration at which is switched to the next capture file\n"
2776         "if you want to use multiple files.",
2777         simple_dialog_primary_start(), simple_dialog_primary_end());
2778       g_free(global_capture_opts.save_file);
2779       global_capture_opts.save_file = NULL;
2780       return FALSE;
2781     }
2782   } else {
2783     global_capture_opts.has_autostop_filesize =
2784       gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_filesize_cb));
2785     if (global_capture_opts.has_autostop_filesize) {
2786       tmp = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(stop_filesize_sb));
2787       tmp = size_unit_combo_box_convert_value(stop_filesize_cbx, tmp);
2788       if(tmp != 0) {
2789         global_capture_opts.autostop_filesize = tmp;
2790       } else {
2791         simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
2792           "%sStop Capture: Requested filesize too large!%s\n\n"
2793           "The setting \"... after x byte(s)\" can't be greater than %u bytes (2GB).", 
2794           simple_dialog_primary_start(), simple_dialog_primary_end(), G_MAXINT);
2795         return FALSE;
2796       }
2797     }
2798   } /* multi_files_on */
2799   return TRUE;
2800 }
2801
2802 /* user requested to destroy the dialog */
2803 static void
2804 capture_prep_destroy_cb(GtkWidget *win, gpointer user_data _U_)
2805 {
2806   GtkWidget *fs;
2807 #ifdef HAVE_PCAP_REMOTE
2808   GList     *if_list;
2809   GtkWidget *remote_w;
2810 #endif
2811
2812   /* Is there a file selection dialog associated with this
2813      Capture Options dialog? */
2814   fs = g_object_get_data(G_OBJECT(win), E_FILE_SEL_DIALOG_PTR_KEY);
2815
2816 #ifdef HAVE_PCAP_REMOTE
2817   if_list = (GList *) g_object_get_data(G_OBJECT(win), E_CAP_IF_LIST_KEY);
2818   if (if_list) {
2819       free_interface_list(if_list);
2820   }
2821 #endif
2822
2823   if (fs != NULL) {
2824     /* Yes.  Destroy it. */
2825     window_destroy(fs);
2826   }
2827
2828   /* Note that we no longer have a "Capture Options" dialog box. */
2829   cap_open_w = NULL;
2830
2831 #ifdef HAVE_AIRPCAP
2832   /* update airpcap toolbar */
2833   airpcap_set_toolbar_stop_capture(airpcap_if_active);
2834 #endif
2835
2836 #ifdef HAVE_PCAP_REMOTE
2837   remote_w = g_object_get_data(G_OBJECT(win), E_CAP_REMOTE_DIALOG_PTR_KEY);
2838   if (remote_w != NULL)
2839       window_destroy(remote_w);
2840 #endif
2841 }
2842
2843 /* user changed the interface entry */
2844 static void
2845 capture_prep_interface_changed_cb(GtkWidget *entry, gpointer argp)
2846 {
2847   GtkWidget *linktype_om = argp;
2848
2849   set_link_type_list(linktype_om, entry);
2850 }
2851
2852 /*
2853  * Adjust the sensitivity of various widgets as per the current setting
2854  * of other widgets.
2855  */
2856 static void
2857 capture_prep_adjust_sensitivity(GtkWidget *tb _U_, gpointer parent_w)
2858 {
2859   GtkWidget *if_cb,
2860             *snap_cb, *snap_sb,
2861             *multi_files_on_cb, *ringbuffer_nbf_cb, *ringbuffer_nbf_sb, *ringbuffer_nbf_lb,
2862             *ring_filesize_cb, *ring_filesize_sb, *ring_filesize_cbx,
2863             *file_duration_cb, *file_duration_sb, *file_duration_cbx,
2864             *sync_cb, *auto_scroll_cb, *hide_info_cb,
2865             *stop_packets_cb, *stop_packets_sb, *stop_packets_lb,
2866             *stop_filesize_cb, *stop_filesize_sb, *stop_filesize_cbx,
2867             *stop_duration_cb, *stop_duration_sb, *stop_duration_cbx,
2868             *stop_files_cb, *stop_files_sb, *stop_files_lb;
2869
2870   if_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_IFACE_KEY);
2871   snap_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_SNAP_CB_KEY);
2872   snap_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_SNAP_SB_KEY);
2873   multi_files_on_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_MULTI_FILES_ON_CB_KEY);
2874   ringbuffer_nbf_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_RING_NBF_CB_KEY);
2875   ringbuffer_nbf_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_RING_NBF_SB_KEY);
2876   ringbuffer_nbf_lb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_RING_NBF_LB_KEY);
2877   ring_filesize_cb  = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_RING_FILESIZE_CB_KEY);
2878   ring_filesize_sb  = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_RING_FILESIZE_SB_KEY);
2879   ring_filesize_cbx = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_RING_FILESIZE_CBX_KEY);
2880   file_duration_cb  = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_FILE_DURATION_CB_KEY);
2881   file_duration_sb  = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_FILE_DURATION_SB_KEY);
2882   file_duration_cbx = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_FILE_DURATION_CBX_KEY);
2883   sync_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_SYNC_KEY);
2884   auto_scroll_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_AUTO_SCROLL_KEY);
2885   hide_info_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_HIDE_INFO_KEY);
2886   stop_packets_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_PACKETS_CB_KEY);
2887   stop_packets_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_PACKETS_SB_KEY);
2888   stop_packets_lb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_PACKETS_LB_KEY);
2889   stop_filesize_cb  = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_FILESIZE_CB_KEY);
2890   stop_filesize_sb  = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_FILESIZE_SB_KEY);
2891   stop_filesize_cbx = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_FILESIZE_CBX_KEY);
2892   stop_duration_cb  = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_DURATION_CB_KEY);
2893   stop_duration_sb  = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_DURATION_SB_KEY);
2894   stop_duration_cbx = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_DURATION_CBX_KEY);
2895   stop_files_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_FILES_CB_KEY);
2896   stop_files_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_FILES_SB_KEY);
2897   stop_files_lb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_FILES_LB_KEY);
2898
2899   /* The snapshot length spinbox is sensitive if the "Limit each packet
2900      to" checkbox is on. */
2901   gtk_widget_set_sensitive(GTK_WIDGET(snap_sb),
2902       gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(snap_cb)));
2903
2904
2905   if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(sync_cb))) {
2906     /* "Update list of packets in real time" captures enabled; we don't
2907        support ring buffer mode for those captures, so turn ring buffer
2908        mode off if it's on, and make its toggle button, and the spin
2909        button for the number of ring buffer files (and the spin button's
2910        label), insensitive. */
2911 /*    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(multi_files_on_cb), FALSE);
2912     gtk_widget_set_sensitive(GTK_WIDGET(multi_files_on_cb), FALSE);*/
2913
2914     /* Auto-scroll mode is meaningful only in "Update list of packets
2915        in real time" captures, so make its toggle button sensitive. */
2916     gtk_widget_set_sensitive(GTK_WIDGET(auto_scroll_cb), TRUE);
2917
2918     /*gtk_widget_set_sensitive(GTK_WIDGET(hide_info_cb), TRUE);*/
2919   } else {
2920     /* "Update list of packets in real time" captures disabled; that
2921        means ring buffer mode is OK, so make its toggle button
2922        sensitive. */
2923 /*    gtk_widget_set_sensitive(GTK_WIDGET(multi_files_on_cb), TRUE);*/
2924
2925     /* Auto-scroll mode is meaningful only in "Update list of packets
2926        in real time" captures, so make its toggle button insensitive. */
2927     gtk_widget_set_sensitive(GTK_WIDGET(auto_scroll_cb), FALSE);
2928
2929     /*gtk_widget_set_sensitive(GTK_WIDGET(hide_info_cb), FALSE);*/
2930   }
2931
2932   if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(multi_files_on_cb))) {
2933     /* Ring buffer mode enabled. */
2934
2935     /* Force at least one of the "file switch" conditions (we need at least one) */
2936     if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ring_filesize_cb)) == FALSE &&
2937         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(file_duration_cb)) == FALSE) {
2938       if (tb == ring_filesize_cb)
2939         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(file_duration_cb), TRUE);
2940       else
2941         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ring_filesize_cb), TRUE);
2942     }
2943
2944     gtk_widget_set_sensitive(GTK_WIDGET(ringbuffer_nbf_cb), TRUE);
2945     gtk_widget_set_sensitive(GTK_WIDGET(ringbuffer_nbf_sb),
2946           gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ringbuffer_nbf_cb)));
2947     gtk_widget_set_sensitive(GTK_WIDGET(ringbuffer_nbf_lb),
2948           gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ringbuffer_nbf_cb)));
2949
2950     /* The ring filesize spinbox is sensitive if the "Next capture file
2951          after N kilobytes" checkbox is on. */
2952     gtk_widget_set_sensitive(GTK_WIDGET(ring_filesize_cb), TRUE);
2953     gtk_widget_set_sensitive(GTK_WIDGET(ring_filesize_sb),
2954           gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ring_filesize_cb)));
2955     gtk_widget_set_sensitive(GTK_WIDGET(ring_filesize_cbx),
2956           gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ring_filesize_cb)));
2957
2958     /* The ring duration spinbox is sensitive if the "Next capture file
2959          after N seconds" checkbox is on. */
2960     gtk_widget_set_sensitive(GTK_WIDGET(file_duration_cb), TRUE);
2961     gtk_widget_set_sensitive(GTK_WIDGET(file_duration_sb),
2962           gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(file_duration_cb)));
2963     gtk_widget_set_sensitive(GTK_WIDGET(file_duration_cbx),
2964           gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(file_duration_cb)));
2965
2966     gtk_widget_set_sensitive(GTK_WIDGET(stop_filesize_cb), FALSE);
2967     gtk_widget_set_sensitive(GTK_WIDGET(stop_filesize_sb), FALSE);
2968     gtk_widget_set_sensitive(GTK_WIDGET(stop_filesize_cbx), FALSE);
2969
2970     gtk_widget_set_sensitive(GTK_WIDGET(stop_files_cb), TRUE);
2971     gtk_widget_set_sensitive(GTK_WIDGET(stop_files_sb),
2972           gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_files_cb)));
2973     gtk_widget_set_sensitive(GTK_WIDGET(stop_files_lb),
2974           gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_files_cb)));
2975   } else {
2976     /* Ring buffer mode disabled. */
2977     gtk_widget_set_sensitive(GTK_WIDGET(ringbuffer_nbf_cb), FALSE);
2978     gtk_widget_set_sensitive(GTK_WIDGET(ringbuffer_nbf_sb), FALSE);
2979     gtk_widget_set_sensitive(GTK_WIDGET(ringbuffer_nbf_lb), FALSE);
2980
2981     gtk_widget_set_sensitive(GTK_WIDGET(ring_filesize_cb), FALSE);
2982     gtk_widget_set_sensitive(GTK_WIDGET(ring_filesize_sb),FALSE);
2983     gtk_widget_set_sensitive(GTK_WIDGET(ring_filesize_cbx),FALSE);
2984
2985     gtk_widget_set_sensitive(GTK_WIDGET(file_duration_cb), FALSE);
2986     gtk_widget_set_sensitive(GTK_WIDGET(file_duration_sb),FALSE);
2987     gtk_widget_set_sensitive(GTK_WIDGET(file_duration_cbx),FALSE);
2988
2989     /* The maximum file size spinbox is sensitive if the "Stop capture
2990          after N kilobytes" checkbox is on. */
2991     gtk_widget_set_sensitive(GTK_WIDGET(stop_filesize_cb), TRUE);
2992     gtk_widget_set_sensitive(GTK_WIDGET(stop_filesize_sb),
2993           gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_filesize_cb)));
2994     gtk_widget_set_sensitive(GTK_WIDGET(stop_filesize_cbx),
2995           gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_filesize_cb)));
2996
2997     gtk_widget_set_sensitive(GTK_WIDGET(stop_files_cb), FALSE);
2998     gtk_widget_set_sensitive(GTK_WIDGET(stop_files_sb), FALSE);
2999     gtk_widget_set_sensitive(GTK_WIDGET(stop_files_lb), FALSE);
3000   }
3001
3002   /* The maximum packet count spinbox is sensitive if the "Stop capture
3003      after N packets" checkbox is on. */
3004   gtk_widget_set_sensitive(GTK_WIDGET(stop_packets_sb),
3005       gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_packets_cb)));
3006   gtk_widget_set_sensitive(GTK_WIDGET(stop_packets_lb),
3007       gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_packets_cb)));
3008
3009   /* The capture duration spinbox is sensitive if the "Stop capture
3010      after N seconds" checkbox is on. */
3011   gtk_widget_set_sensitive(GTK_WIDGET(stop_duration_sb),
3012       gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_duration_cb)));
3013   gtk_widget_set_sensitive(GTK_WIDGET(stop_duration_cbx),
3014       gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_duration_cb)));
3015 }
3016
3017 #endif /* HAVE_LIBPCAP */