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