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