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