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