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