66b1d0ed10d2e6ce60e2c5841630d2298f0eba89
[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 gboolean
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_event_box_set_visible_window (GTK_EVENT_BOX(if_ip_eb), FALSE);
1107   gtk_box_pack_start(GTK_BOX(if_ip_hb), if_ip_eb, TRUE, TRUE, 6);
1108   gtk_tooltips_set_tip(tooltips, if_ip_eb, "Lists the IP address(es) "
1109                        "assigned to the selected interface.  If there are "
1110                        "more addresses than will fit in the window, the "
1111                        "first few and the last few will be shown with \"...\" "
1112                        "between them.",
1113                        NULL);
1114
1115   if_ip_lb = gtk_label_new("");
1116   gtk_misc_set_alignment(GTK_MISC(if_ip_lb), 0, 0); /* Left justified */
1117   gtk_container_add(GTK_CONTAINER(if_ip_eb), if_ip_lb);
1118
1119   /* Linktype row */
1120   linktype_hb = gtk_hbox_new(FALSE, 3);
1121   gtk_box_pack_start(GTK_BOX(capture_vb), linktype_hb, FALSE, FALSE, 0);
1122
1123   linktype_lb = gtk_label_new("Link-layer header type:");
1124   gtk_box_pack_start(GTK_BOX(linktype_hb), linktype_lb, FALSE, FALSE, 6);
1125
1126   linktype_om = gtk_option_menu_new();
1127   g_object_set_data(G_OBJECT(linktype_om), E_CAP_LT_OM_LABEL_KEY, linktype_lb);
1128   /* Default to "use the default" */
1129   /* Datalink menu index is not resetted, it will be restored with last used value */
1130   /* g_object_set_data(G_OBJECT(linktype_om), E_CAP_OM_LT_VALUE_KEY, GINT_TO_POINTER(-1)); */
1131   g_object_set_data(G_OBJECT(linktype_om), E_CAP_IFACE_KEY, if_ip_lb);
1132   dl_hdr_menu=NULL;
1133   if (linktype_history == NULL) {
1134     linktype_history = g_hash_table_new(g_str_hash, g_str_equal);
1135   }
1136   set_link_type_list(linktype_om, GTK_COMBO(if_cb)->entry);
1137   /*
1138    * XXX - in some cases, this is "multiple link-layer header types", e.g.
1139    * some 802.11 interfaces on FreeBSD 5.2 and later, where you can request
1140    * fake Ethernet, 802.11, or 802.11-plus-radio-information headers.
1141    *
1142    * In other cases, it's "multiple link-layer types", e.g., with recent
1143    * versions of libpcap, a DAG card on an "HDLC" WAN, where you can
1144    * request Cisco HDLC or PPP depending on what type of traffic is going
1145    * over the WAN, or an Ethernet interface, where you can request Ethernet
1146    * or DOCSIS, the latter being for some Cisco cable modem equipment that
1147    * can be configured to send raw DOCSIS frames over an Ethernet inside
1148    * Ethernet low-level framing, for traffic capture purposes.
1149    *
1150    * We leave it as "multiple link-layer types" for now.
1151    */
1152   gtk_tooltips_set_tip(tooltips, linktype_om,
1153     "The selected interface supports multiple link-layer types; select the desired one.", NULL);
1154   gtk_box_pack_start (GTK_BOX(linktype_hb), linktype_om, FALSE, FALSE, 0);
1155   g_signal_connect(GTK_ENTRY(GTK_COMBO(if_cb)->entry), "changed",
1156                  G_CALLBACK(capture_prep_interface_changed_cb), linktype_om);
1157
1158 #ifdef _WIN32
1159   buffer_size_lb = gtk_label_new("Buffer size:");
1160   gtk_box_pack_start (GTK_BOX(linktype_hb), buffer_size_lb, FALSE, FALSE, 0);
1161
1162   buffer_size_adj = (GtkAdjustment *) gtk_adjustment_new((gfloat) global_capture_opts.buffer_size,
1163     1, 65535, 1.0, 10.0, 0.0);
1164   buffer_size_sb = gtk_spin_button_new (buffer_size_adj, 0, 0);
1165   gtk_spin_button_set_value(GTK_SPIN_BUTTON (buffer_size_sb), (gfloat) global_capture_opts.buffer_size);
1166   gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (buffer_size_sb), TRUE);
1167   gtk_widget_set_size_request(buffer_size_sb, 80, -1);
1168   gtk_tooltips_set_tip(tooltips, buffer_size_sb,
1169     "The memory buffer size used while capturing. If you notice packet drops, you can try to increase this size.", NULL);
1170   gtk_box_pack_start (GTK_BOX(linktype_hb), buffer_size_sb, FALSE, FALSE, 0);
1171
1172   buffer_size_lb = gtk_label_new("megabyte(s)");
1173   gtk_box_pack_start (GTK_BOX(linktype_hb), buffer_size_lb, FALSE, FALSE, 6);
1174 #endif
1175
1176   /* Promiscuous mode row */
1177   promisc_cb = gtk_check_button_new_with_mnemonic(
1178       "Capture packets in _promiscuous mode");
1179   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(promisc_cb),
1180                 global_capture_opts.promisc_mode);
1181   gtk_tooltips_set_tip(tooltips, promisc_cb,
1182     "Usually a network card will only capture the traffic sent to its own network address. "
1183     "If you want to capture all traffic that the network card can \"see\", mark this option. "
1184     "See the FAQ for some more details of capturing packets from a switched network.", NULL);
1185   gtk_container_add(GTK_CONTAINER(capture_vb), promisc_cb);
1186
1187 #ifdef HAVE_PCAP_REMOTE
1188   /* RPCAP-related flags */
1189   nocap_rpcap_cb = gtk_check_button_new_with_mnemonic(
1190       "Do not capture RPCAP own traffic");
1191   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(nocap_rpcap_cb),
1192           global_capture_opts.nocap_rpcap);
1193   gtk_container_add(GTK_CONTAINER(capture_vb), nocap_rpcap_cb);
1194
1195   datatx_udp_cb = gtk_check_button_new_with_mnemonic(
1196       "Use UDP for RPCAP data transfer");
1197   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(datatx_udp_cb),
1198           global_capture_opts.datatx_udp);
1199   gtk_container_add(GTK_CONTAINER(capture_vb), datatx_udp_cb);
1200 #endif
1201
1202   /* Capture length row */
1203   snap_hb = gtk_hbox_new(FALSE, 3);
1204   gtk_container_add(GTK_CONTAINER(capture_vb), snap_hb);
1205
1206   snap_cb = gtk_check_button_new_with_mnemonic("_Limit each packet to");
1207   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(snap_cb),
1208                 global_capture_opts.has_snaplen);
1209   g_signal_connect(snap_cb, "toggled", G_CALLBACK(capture_prep_adjust_sensitivity), cap_open_w);
1210   gtk_tooltips_set_tip(tooltips, snap_cb,
1211     "Limit the maximum number of bytes to be captured from each packet. This size includes the "
1212     "link-layer header and all subsequent headers. ", NULL);
1213   gtk_box_pack_start(GTK_BOX(snap_hb), snap_cb, FALSE, FALSE, 0);
1214
1215   snap_adj = (GtkAdjustment *) gtk_adjustment_new((gfloat) global_capture_opts.snaplen,
1216     MIN_PACKET_SIZE, WTAP_MAX_PACKET_SIZE, 1.0, 10.0, 0.0);
1217   snap_sb = gtk_spin_button_new (snap_adj, 0, 0);
1218   gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (snap_sb), TRUE);
1219   gtk_widget_set_size_request(snap_sb, 80, -1);
1220   gtk_box_pack_start (GTK_BOX(snap_hb), snap_sb, FALSE, FALSE, 0);
1221
1222   snap_lb = gtk_label_new("bytes");
1223   gtk_misc_set_alignment(GTK_MISC(snap_lb), 0, 0.5);
1224   gtk_box_pack_start(GTK_BOX(snap_hb), snap_lb, FALSE, FALSE, 0);
1225
1226   /* Filter row */
1227   filter_hb = gtk_hbox_new(FALSE, 3);
1228   gtk_box_pack_start(GTK_BOX(capture_vb), filter_hb, FALSE, FALSE, 0);
1229
1230   filter_bt = gtk_button_new_from_stock(WIRESHARK_STOCK_CAPTURE_FILTER_ENTRY);
1231   g_signal_connect(filter_bt, "clicked", G_CALLBACK(capture_filter_construct_cb), NULL);
1232   g_signal_connect(filter_bt, "destroy", G_CALLBACK(filter_button_destroy_cb), NULL);
1233   gtk_tooltips_set_tip(tooltips, filter_bt,
1234     "Select a capture filter to reduce the amount of packets to be captured. "
1235     "See \"Capture Filters\" in the online help for further information how to use it.",
1236     NULL);
1237   gtk_box_pack_start(GTK_BOX(filter_hb), filter_bt, FALSE, FALSE, 3);
1238
1239   /* Create the capture filter combo */
1240   filter_cm = gtk_combo_new();
1241
1242   cfilter_list = g_object_get_data(G_OBJECT(top_level), E_CFILTER_FL_KEY);
1243   gtk_combo_disable_activate(GTK_COMBO(filter_cm));
1244   gtk_combo_set_case_sensitive(GTK_COMBO(filter_cm), TRUE);
1245   g_object_set_data(G_OBJECT(top_level), E_CFILTER_FL_KEY, cfilter_list);
1246   g_object_set_data(G_OBJECT(top_level), E_CFILTER_CM_KEY, filter_cm);
1247   filter_te = GTK_COMBO(filter_cm)->entry;
1248
1249   if (cfilter_list != NULL)
1250     gtk_combo_set_popdown_strings(GTK_COMBO(filter_cm), cfilter_list);
1251   if (global_capture_opts.cfilter)
1252     gtk_entry_set_text(GTK_ENTRY(filter_te), global_capture_opts.cfilter);
1253   gtk_tooltips_set_tip(tooltips, filter_te,
1254     "Enter a capture filter to reduce the amount of packets to be captured. "
1255     "See \"Capture Filters\" in the online help for further information how to use it.",
1256     NULL);
1257   gtk_widget_set_size_request(filter_cm, 400, -1);
1258   gtk_box_pack_start(GTK_BOX(filter_hb), filter_cm, FALSE, FALSE, 3);
1259   main_hb = gtk_hbox_new(FALSE, 5);
1260   gtk_container_set_border_width(GTK_CONTAINER(main_hb), 0);
1261   gtk_container_add(GTK_CONTAINER(main_vb), main_hb);
1262
1263   left_vb = gtk_vbox_new(FALSE, 0);
1264   gtk_container_set_border_width(GTK_CONTAINER(left_vb), 0);
1265   gtk_box_pack_start(GTK_BOX(main_hb), left_vb, TRUE, TRUE, 0);
1266
1267   right_vb = gtk_vbox_new(FALSE, 0);
1268   gtk_container_set_border_width(GTK_CONTAINER(right_vb), 0);
1269   gtk_box_pack_start(GTK_BOX(main_hb), right_vb, FALSE, FALSE, 0);
1270
1271   /* let an eventually capture filters dialog know the text entry to fill in */
1272   g_object_set_data(G_OBJECT(filter_bt), E_FILT_TE_PTR_KEY, filter_te);
1273
1274   /* advanced row */
1275 #ifdef HAVE_AIRPCAP
1276   advanced_hb = gtk_hbox_new(FALSE,5);
1277   gtk_box_pack_start(GTK_BOX(capture_vb), advanced_hb, FALSE, FALSE, 0);
1278
1279   advanced_bt = gtk_button_new_with_label("Wireless Settings");
1280
1281   /* set the text */
1282   /* XXX - find a way to set the GtkButton label in GTK 2.x */
1283   gtk_button_set_label(GTK_BUTTON(advanced_bt), "Wireless Settings");
1284
1285   /* Both the callback and the data are global */
1286   g_signal_connect(advanced_bt,"clicked", G_CALLBACK(options_airpcap_advanced_cb),airpcap_tb);
1287   g_object_set_data(G_OBJECT(GTK_ENTRY(GTK_COMBO(if_cb)->entry)),AIRPCAP_OPTIONS_ADVANCED_KEY,advanced_bt);
1288
1289   if(airpcap_if_selected != NULL) {
1290     /* It is an airpcap interface */
1291     gtk_widget_set_sensitive(advanced_bt,TRUE);
1292   } else {
1293     gtk_widget_set_sensitive(advanced_bt,FALSE);
1294   }
1295
1296   gtk_box_pack_start(GTK_BOX(linktype_hb),advanced_bt,FALSE,FALSE,0);
1297   gtk_widget_show(advanced_bt);
1298   gtk_widget_show(advanced_hb);
1299 #endif
1300
1301   /* Capture file-related options frame */
1302   file_fr = gtk_frame_new("Capture File(s)");
1303   gtk_container_add(GTK_CONTAINER(left_vb), file_fr);
1304
1305   file_vb = gtk_vbox_new(FALSE, 3);
1306   gtk_container_set_border_width(GTK_CONTAINER(file_vb), 5);
1307   gtk_container_add(GTK_CONTAINER(file_fr), file_vb);
1308
1309   /* File row */
1310   file_hb = gtk_hbox_new(FALSE, 3);
1311   gtk_box_pack_start(GTK_BOX(file_vb), file_hb, FALSE, FALSE, 0);
1312
1313   file_lb = gtk_label_new("File:");
1314   gtk_box_pack_start(GTK_BOX(file_hb), file_lb, FALSE, FALSE, 3);
1315
1316   file_te = gtk_entry_new();
1317   gtk_tooltips_set_tip(tooltips, file_te,
1318     "Enter the file name to which captured data will be written. "
1319     "If you don't enter something here, a temporary file will be used.",
1320     NULL);
1321   gtk_box_pack_start(GTK_BOX(file_hb), file_te, TRUE, TRUE, 3);
1322
1323   file_bt = gtk_button_new_from_stock(WIRESHARK_STOCK_BROWSE);
1324   gtk_tooltips_set_tip(tooltips, file_bt,
1325     "Select a file to which captured data will be written, "
1326     "instead of entering the file name directly. ",
1327     NULL);
1328   gtk_box_pack_start(GTK_BOX(file_hb), file_bt, FALSE, FALSE, 3);
1329
1330   g_signal_connect(file_bt, "clicked", G_CALLBACK(capture_prep_file_cb), file_te);
1331
1332   /* multiple files table */
1333   multi_tb = gtk_table_new(5, 3, FALSE);
1334   gtk_table_set_row_spacings(GTK_TABLE(multi_tb), 1);
1335   gtk_table_set_col_spacings(GTK_TABLE(multi_tb), 3);
1336   gtk_box_pack_start(GTK_BOX(file_vb), multi_tb, FALSE, FALSE, 0);
1337   row = 0;
1338
1339   /* multiple files row */
1340   multi_files_on_cb = gtk_check_button_new_with_mnemonic("Use _multiple files");
1341   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(multi_files_on_cb),
1342                 global_capture_opts.multi_files_on);
1343   g_signal_connect(multi_files_on_cb, "toggled", G_CALLBACK(capture_prep_adjust_sensitivity),
1344                  cap_open_w);
1345   gtk_tooltips_set_tip(tooltips, multi_files_on_cb,
1346     "Instead of using a single capture file, multiple files will be created. "
1347     "The generated file names will contain an incrementing number and the start time of the capture.", NULL);
1348   gtk_table_attach_defaults(GTK_TABLE(multi_tb), multi_files_on_cb, 0, 1, row, row+1);
1349   row++;
1350
1351   /* Ring buffer filesize row */
1352   ring_filesize_cb = gtk_check_button_new_with_label("Next file every");
1353   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ring_filesize_cb),
1354                 global_capture_opts.has_autostop_filesize || !global_capture_opts.has_file_duration);
1355   g_signal_connect(ring_filesize_cb, "toggled", G_CALLBACK(capture_prep_adjust_sensitivity), cap_open_w);
1356   gtk_tooltips_set_tip(tooltips, ring_filesize_cb,
1357     "If the selected file size is exceeded, capturing switches to the next file.\n"
1358     "PLEASE NOTE: at least one of the \"Next file every\" options MUST be selected.",
1359     NULL);
1360   gtk_table_attach_defaults(GTK_TABLE(multi_tb), ring_filesize_cb, 0, 1, row, row+1);
1361
1362   ring_filesize_adj = (GtkAdjustment *) gtk_adjustment_new(0.0,
1363     1, (gfloat)INT_MAX, 1.0, 10.0, 0.0);
1364   ring_filesize_sb = gtk_spin_button_new (ring_filesize_adj, 0, 0);
1365   gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (ring_filesize_sb), TRUE);
1366   gtk_widget_set_size_request(ring_filesize_sb, 80, -1);
1367   gtk_table_attach_defaults(GTK_TABLE(multi_tb), ring_filesize_sb, 1, 2, row, row+1);
1368
1369   ring_filesize_om = size_unit_option_menu_new(global_capture_opts.autostop_filesize);
1370   gtk_table_attach_defaults(GTK_TABLE(multi_tb), ring_filesize_om, 2, 3, row, row+1);
1371
1372   value = size_unit_option_menu_set_value(global_capture_opts.autostop_filesize);
1373   gtk_adjustment_set_value(ring_filesize_adj, (gfloat) value);
1374
1375   row++;
1376
1377   /* Ring buffer duration row */
1378   file_duration_cb = gtk_check_button_new_with_label("Next file every");
1379   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(file_duration_cb),
1380                               global_capture_opts.has_file_duration);
1381   g_signal_connect(file_duration_cb, "toggled",
1382                  G_CALLBACK(capture_prep_adjust_sensitivity), cap_open_w);
1383   gtk_tooltips_set_tip(tooltips, file_duration_cb,
1384     "If the selected duration is exceeded, capturing switches to the next file.\n"
1385     "PLEASE NOTE: at least one of the \"Next file every\" options MUST be selected.",
1386     NULL);
1387   gtk_table_attach_defaults(GTK_TABLE(multi_tb), file_duration_cb, 0, 1, row, row+1);
1388
1389   file_duration_adj = (GtkAdjustment *)gtk_adjustment_new(0.0,
1390     1, (gfloat)INT_MAX, 1.0, 10.0, 0.0);
1391   file_duration_sb = gtk_spin_button_new (file_duration_adj, 0, 0);
1392   gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (file_duration_sb), TRUE);
1393   gtk_widget_set_size_request(file_duration_sb, 80, -1);
1394   gtk_table_attach_defaults(GTK_TABLE(multi_tb), file_duration_sb, 1, 2, row, row+1);
1395
1396   file_duration_om = time_unit_option_menu_new(global_capture_opts.file_duration);
1397   gtk_table_attach_defaults(GTK_TABLE(multi_tb), file_duration_om, 2, 3, row, row+1);
1398
1399   value = time_unit_option_menu_convert_value(global_capture_opts.file_duration);
1400   gtk_adjustment_set_value(file_duration_adj, (gfloat) value);
1401   row++;
1402
1403   /* Ring buffer files row */
1404   ringbuffer_nbf_cb = gtk_check_button_new_with_label("Ring buffer with");
1405   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ringbuffer_nbf_cb),
1406                 global_capture_opts.has_ring_num_files);
1407   g_signal_connect(ringbuffer_nbf_cb, "toggled", G_CALLBACK(capture_prep_adjust_sensitivity), cap_open_w);
1408   gtk_tooltips_set_tip(tooltips, ringbuffer_nbf_cb,
1409     "After capturing has switched to the next file and the given number of files has exceeded, "
1410     "the oldest file will be removed.",
1411     NULL);
1412   gtk_table_attach_defaults(GTK_TABLE(multi_tb), ringbuffer_nbf_cb, 0, 1, row, row+1);
1413
1414   ringbuffer_nbf_adj = (GtkAdjustment *) gtk_adjustment_new((gfloat) global_capture_opts.ring_num_files,
1415     2/*RINGBUFFER_MIN_NUM_FILES*/, RINGBUFFER_MAX_NUM_FILES, 1.0, 10.0, 0.0);
1416   ringbuffer_nbf_sb = gtk_spin_button_new (ringbuffer_nbf_adj, 0, 0);
1417   gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (ringbuffer_nbf_sb), TRUE);
1418   gtk_widget_set_size_request(ringbuffer_nbf_sb, 80, -1);
1419   g_signal_connect(ringbuffer_nbf_sb, "changed", G_CALLBACK(capture_prep_adjust_sensitivity), cap_open_w);
1420   gtk_table_attach_defaults(GTK_TABLE(multi_tb), ringbuffer_nbf_sb, 1, 2, row, row+1);
1421
1422   ringbuffer_nbf_lb = gtk_label_new("files");
1423   gtk_misc_set_alignment(GTK_MISC(ringbuffer_nbf_lb), 0, 0.5);
1424   gtk_table_attach_defaults(GTK_TABLE(multi_tb), ringbuffer_nbf_lb, 2, 3, row, row+1);
1425   row++;
1426
1427   /* Files row */
1428   stop_files_cb = gtk_check_button_new_with_label("Stop capture after");
1429   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(stop_files_cb),
1430                 global_capture_opts.has_autostop_files);
1431   g_signal_connect(stop_files_cb, "toggled", G_CALLBACK(capture_prep_adjust_sensitivity), cap_open_w);
1432   gtk_tooltips_set_tip(tooltips, stop_files_cb,
1433     "Stop capturing after the given number of \"file switches\" have been done.", NULL);
1434   gtk_table_attach_defaults(GTK_TABLE(multi_tb), stop_files_cb, 0, 1, row, row+1);
1435
1436   stop_files_adj = (GtkAdjustment *) gtk_adjustment_new((gfloat)global_capture_opts.autostop_files,
1437     1, (gfloat)INT_MAX, 1.0, 10.0, 0.0);
1438   stop_files_sb = gtk_spin_button_new (stop_files_adj, 0, 0);
1439   gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (stop_files_sb), TRUE);
1440   gtk_widget_set_size_request(stop_files_sb, 80, -1);
1441   gtk_table_attach_defaults(GTK_TABLE(multi_tb), stop_files_sb, 1, 2, row, row+1);
1442
1443   stop_files_lb = gtk_label_new("file(s)");
1444   gtk_misc_set_alignment(GTK_MISC(stop_files_lb), 0, 0.5);
1445   gtk_table_attach_defaults(GTK_TABLE(multi_tb), stop_files_lb, 2, 3, row, row+1);
1446   row++;
1447
1448   /* Capture limits frame */
1449   limit_fr = gtk_frame_new("Stop Capture ...");
1450   gtk_container_add(GTK_CONTAINER(left_vb), limit_fr);
1451
1452   limit_vb = gtk_vbox_new(FALSE, 3);
1453   gtk_container_set_border_width(GTK_CONTAINER(limit_vb), 5);
1454   gtk_container_add(GTK_CONTAINER(limit_fr), limit_vb);
1455
1456   /* limits table */
1457   limit_tb = gtk_table_new(3, 3, FALSE);
1458   gtk_table_set_row_spacings(GTK_TABLE(limit_tb), 1);
1459   gtk_table_set_col_spacings(GTK_TABLE(limit_tb), 3);
1460   gtk_box_pack_start(GTK_BOX(limit_vb), limit_tb, FALSE, FALSE, 0);
1461   row = 0;
1462
1463   /* Packet count row */
1464   stop_packets_cb = gtk_check_button_new_with_label("... after");
1465   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(stop_packets_cb),
1466                 global_capture_opts.has_autostop_packets);
1467   g_signal_connect(stop_packets_cb, "toggled", G_CALLBACK(capture_prep_adjust_sensitivity), cap_open_w);
1468   gtk_tooltips_set_tip(tooltips, stop_packets_cb,
1469     "Stop capturing after the given number of packets have been captured.", NULL);
1470   gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_packets_cb, 0, 1, row, row+1);
1471
1472   stop_packets_adj = (GtkAdjustment *) gtk_adjustment_new((gfloat)global_capture_opts.autostop_packets,
1473     1, (gfloat)INT_MAX, 1.0, 10.0, 0.0);
1474   stop_packets_sb = gtk_spin_button_new (stop_packets_adj, 0, 0);
1475   gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (stop_packets_sb), TRUE);
1476   gtk_widget_set_size_request(stop_packets_sb, 80, -1);
1477   gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_packets_sb, 1, 2, row, row+1);
1478
1479   stop_packets_lb = gtk_label_new("packet(s)");
1480   gtk_misc_set_alignment(GTK_MISC(stop_packets_lb), 0, 0.5);
1481   gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_packets_lb, 2, 3, row, row+1);
1482   row++;
1483
1484   /* Filesize row */
1485   stop_filesize_cb = gtk_check_button_new_with_label("... after");
1486   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(stop_filesize_cb),
1487                 global_capture_opts.has_autostop_filesize);
1488   g_signal_connect(stop_filesize_cb, "toggled", G_CALLBACK(capture_prep_adjust_sensitivity), cap_open_w);
1489   gtk_tooltips_set_tip(tooltips, stop_filesize_cb,
1490     "Stop capturing after the given amount of capture data has been captured.", NULL);
1491   gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_filesize_cb, 0, 1, row, row+1);
1492
1493   stop_filesize_adj = (GtkAdjustment *) gtk_adjustment_new(0.0,
1494     1, (gfloat)INT_MAX, 1.0, 10.0, 0.0);
1495   stop_filesize_sb = gtk_spin_button_new (stop_filesize_adj, 0, 0);
1496   gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (stop_filesize_sb), TRUE);
1497   gtk_widget_set_size_request(stop_filesize_sb, 80, -1);
1498   gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_filesize_sb, 1, 2, row, row+1);
1499
1500   stop_filesize_om = size_unit_option_menu_new(global_capture_opts.autostop_filesize);
1501   gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_filesize_om, 2, 3, row, row+1);
1502
1503   value = size_unit_option_menu_set_value(global_capture_opts.autostop_filesize);
1504   gtk_adjustment_set_value(stop_filesize_adj, (gfloat) value);
1505
1506   row++;
1507
1508   /* Duration row */
1509   stop_duration_cb = gtk_check_button_new_with_label("... after");
1510   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(stop_duration_cb),
1511                 global_capture_opts.has_autostop_duration);
1512   g_signal_connect(stop_duration_cb, "toggled", G_CALLBACK(capture_prep_adjust_sensitivity), cap_open_w);
1513   gtk_tooltips_set_tip(tooltips, stop_duration_cb,
1514     "Stop capturing after the given time is exceeded.", NULL);
1515   gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_duration_cb, 0, 1, row, row+1);
1516
1517   stop_duration_adj = (GtkAdjustment *) gtk_adjustment_new(0.0,
1518     1, (gfloat)INT_MAX, 1.0, 10.0, 0.0);
1519   stop_duration_sb = gtk_spin_button_new (stop_duration_adj, 0, 0);
1520   gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (stop_duration_sb), TRUE);
1521   gtk_widget_set_size_request(stop_duration_sb, 80, -1);
1522   gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_duration_sb, 1, 2, row, row+1);
1523
1524   stop_duration_om = time_unit_option_menu_new(global_capture_opts.autostop_duration);
1525   gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_duration_om, 2, 3, row, row+1);
1526
1527   value = time_unit_option_menu_convert_value(global_capture_opts.autostop_duration);
1528   gtk_adjustment_set_value(stop_duration_adj, (gfloat) value);
1529   row++;
1530
1531 #ifdef HAVE_PCAP_SETSAMPLING
1532   /* Sampling options */
1533   sampling_fr = gtk_frame_new("Sampling Options");
1534   gtk_container_add(GTK_CONTAINER(right_vb), sampling_fr);
1535
1536   sampling_vb = gtk_vbox_new(FALSE, 0);
1537   gtk_container_set_border_width(GTK_CONTAINER(sampling_vb), 5);
1538   gtk_container_add(GTK_CONTAINER(sampling_fr), sampling_vb);
1539
1540   sampling_tb = gtk_table_new(3, 3, FALSE);
1541   gtk_table_set_row_spacings(GTK_TABLE(sampling_tb), 1);
1542   gtk_table_set_col_spacings(GTK_TABLE(sampling_tb), 3);
1543   gtk_box_pack_start(GTK_BOX(sampling_vb), sampling_tb, FALSE, FALSE, 0);
1544
1545   /* "No sampling" row */
1546   samp_none_rb = gtk_radio_button_new_with_label(NULL, "None");
1547   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(samp_none_rb),
1548                      (global_capture_opts.sampling_method == CAPTURE_SAMP_NONE));
1549   g_signal_connect(samp_none_rb, "toggled",
1550                  G_CALLBACK(capture_prep_adjust_sensitivity), cap_open_w);
1551   gtk_table_attach_defaults(GTK_TABLE(sampling_tb), samp_none_rb, 0, 1, 0, 1);
1552
1553   /* "Sampling by counter" row */
1554   samp_group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(samp_none_rb));
1555   samp_count_rb = gtk_radio_button_new_with_label(samp_group, "1 of");
1556   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(samp_none_rb),
1557                      (global_capture_opts.sampling_method == CAPTURE_SAMP_BY_COUNT));
1558   g_signal_connect(samp_count_rb, "toggled",
1559                  G_CALLBACK(capture_prep_adjust_sensitivity), cap_open_w);
1560   gtk_table_attach_defaults(GTK_TABLE(sampling_tb), samp_count_rb, 0, 1, 1, 2);
1561
1562   samp_count_adj = (GtkAdjustment *) gtk_adjustment_new(
1563                         (gfloat)global_capture_opts.sampling_param,
1564                         1, (gfloat)INT_MAX, 1.0, 10.0, 0.0);
1565   samp_count_sb = gtk_spin_button_new(samp_count_adj, 0, 0);
1566   gtk_spin_button_set_wrap(GTK_SPIN_BUTTON(samp_count_sb), TRUE);
1567   gtk_table_attach_defaults(GTK_TABLE(sampling_tb), samp_count_sb, 1, 2, 1, 2);
1568
1569   sampling_lb = gtk_label_new("packets");
1570   gtk_misc_set_alignment(GTK_MISC(sampling_lb), 0, 0.5);
1571   gtk_table_attach_defaults(GTK_TABLE(sampling_tb), sampling_lb, 2, 3, 1, 2);
1572
1573   /* "Sampling by timer" row */
1574   samp_group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(samp_count_rb));
1575   samp_timer_rb = gtk_radio_button_new_with_label(samp_group, "1 every");
1576   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(samp_none_rb),
1577                      (global_capture_opts.sampling_method == CAPTURE_SAMP_BY_TIMER));
1578   g_signal_connect(samp_timer_rb, "toggled",
1579                  G_CALLBACK(capture_prep_adjust_sensitivity), cap_open_w);
1580   gtk_table_attach_defaults(GTK_TABLE(sampling_tb), samp_timer_rb, 0, 1, 2, 3);
1581
1582   samp_timer_adj = (GtkAdjustment *) gtk_adjustment_new(
1583                         (gfloat)global_capture_opts.sampling_param,
1584                         1, (gfloat)INT_MAX, 1.0, 10.0, 0.0);
1585   samp_timer_sb = gtk_spin_button_new(samp_timer_adj, 0, 0);
1586   gtk_spin_button_set_wrap(GTK_SPIN_BUTTON(samp_timer_sb), TRUE);
1587   gtk_table_attach_defaults(GTK_TABLE(sampling_tb), samp_timer_sb, 1, 2, 2, 3);
1588
1589   sampling_lb = gtk_label_new("milliseconds");
1590   gtk_misc_set_alignment(GTK_MISC(sampling_lb), 0, 0.5);
1591   gtk_table_attach_defaults(GTK_TABLE(sampling_tb), sampling_lb, 2, 3, 2, 3);
1592 #endif
1593
1594   /* Display-related options frame */
1595   display_fr = gtk_frame_new("Display Options");
1596   gtk_container_add(GTK_CONTAINER(right_vb), display_fr);
1597
1598   display_vb = gtk_vbox_new(FALSE, 0);
1599   gtk_container_set_border_width(GTK_CONTAINER(display_vb), 5);
1600   gtk_container_add(GTK_CONTAINER(display_fr), display_vb);
1601
1602   /* "Update display in real time" row */
1603   sync_cb = gtk_check_button_new_with_mnemonic(
1604       "_Update list of packets in real time");
1605   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(sync_cb),
1606                 global_capture_opts.real_time_mode);
1607   g_signal_connect(sync_cb, "toggled", G_CALLBACK(capture_prep_adjust_sensitivity), cap_open_w);
1608   gtk_tooltips_set_tip(tooltips, sync_cb,
1609     "Using this option will show the captured packets immediately on the main screen. "
1610     "Please note: this will slow down capturing, so increased packet drops might appear.", NULL);
1611   gtk_container_add(GTK_CONTAINER(display_vb), sync_cb);
1612
1613   /* "Auto-scroll live update" row */
1614   auto_scroll_cb = gtk_check_button_new_with_mnemonic(
1615                 "_Automatic scrolling in live capture");
1616   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(auto_scroll_cb), auto_scroll_live);
1617   gtk_tooltips_set_tip(tooltips, auto_scroll_cb,
1618     "This will scroll the \"Packet List\" automatically to the latest captured packet, "
1619     "when the \"Update List of packets in real time\" option is used.", NULL);
1620   gtk_container_add(GTK_CONTAINER(display_vb), auto_scroll_cb);
1621
1622   /* "Hide capture info" row */
1623   hide_info_cb = gtk_check_button_new_with_mnemonic(
1624                 "_Hide capture info dialog");
1625   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(hide_info_cb), !global_capture_opts.show_info);
1626   gtk_tooltips_set_tip(tooltips, hide_info_cb,
1627     "Hide the capture info dialog while capturing.", NULL);
1628   gtk_container_add(GTK_CONTAINER(display_vb), hide_info_cb);
1629
1630   /* Name Resolution frame */
1631   resolv_fr = gtk_frame_new("Name Resolution");
1632   gtk_container_add(GTK_CONTAINER(right_vb), resolv_fr);
1633
1634   resolv_vb = gtk_vbox_new(FALSE, 0);
1635   gtk_container_set_border_width(GTK_CONTAINER(resolv_vb), 5);
1636   gtk_container_add(GTK_CONTAINER(resolv_fr), resolv_vb);
1637
1638   m_resolv_cb = gtk_check_button_new_with_mnemonic(
1639                 "Enable _MAC name resolution");
1640   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_resolv_cb),
1641                 g_resolv_flags & RESOLV_MAC);
1642   gtk_tooltips_set_tip(tooltips, m_resolv_cb,
1643     "Perform MAC layer name resolution while capturing.", NULL);
1644   gtk_container_add(GTK_CONTAINER(resolv_vb), m_resolv_cb);
1645
1646   n_resolv_cb = gtk_check_button_new_with_mnemonic(
1647                 "Enable _network name resolution");
1648   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(n_resolv_cb),
1649                 g_resolv_flags & RESOLV_NETWORK);
1650   gtk_tooltips_set_tip(tooltips, n_resolv_cb,
1651     "Perform network layer name resolution while capturing.", NULL);
1652   gtk_container_add(GTK_CONTAINER(resolv_vb), n_resolv_cb);
1653
1654   t_resolv_cb = gtk_check_button_new_with_mnemonic(
1655                 "Enable _transport name resolution");
1656   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(t_resolv_cb),
1657                 g_resolv_flags & RESOLV_TRANSPORT);
1658   gtk_tooltips_set_tip(tooltips, t_resolv_cb,
1659     "Perform transport layer name resolution while capturing.", NULL);
1660   gtk_container_add(GTK_CONTAINER(resolv_vb), t_resolv_cb);
1661
1662   /* Button row: "Start", "Cancel" and "Help" buttons */
1663   bbox = dlg_button_row_new(WIRESHARK_STOCK_CAPTURE_START, GTK_STOCK_CANCEL, GTK_STOCK_HELP, NULL);
1664   gtk_box_pack_start(GTK_BOX(main_vb), bbox, FALSE, FALSE, 5);
1665
1666   ok_bt = g_object_get_data(G_OBJECT(bbox), WIRESHARK_STOCK_CAPTURE_START);
1667   g_signal_connect(ok_bt, "clicked", G_CALLBACK(capture_start_cb), cap_open_w);
1668   gtk_tooltips_set_tip(tooltips, ok_bt,
1669     "Start the capture process.", NULL);
1670
1671   cancel_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CANCEL);
1672   gtk_tooltips_set_tip(tooltips, cancel_bt,
1673     "Cancel and exit dialog.", NULL);
1674   window_set_cancel_button(cap_open_w, cancel_bt, window_cancel_button_cb);
1675
1676   help_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_HELP);
1677   gtk_tooltips_set_tip(tooltips, help_bt,
1678     "Show help about capturing.", NULL);
1679   g_signal_connect(help_bt, "clicked", G_CALLBACK(topic_cb), (gpointer)HELP_CAPTURE_OPTIONS_DIALOG);
1680
1681   gtk_widget_grab_default(ok_bt);
1682
1683   /* Attach pointers to needed widgets to the capture prefs window/object */
1684   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_IFACE_KEY, if_cb);
1685 #ifdef HAVE_PCAP_REMOTE
1686   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_IFTYPE_OM_KEY, iftype_om);
1687   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_REMOTE_DIALOG_PTR_KEY, NULL);
1688   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_NOCAP_RPCAP_CB_KEY, nocap_rpcap_cb);
1689   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_DATATX_UDP_CB_KEY, datatx_udp_cb);
1690 #endif
1691   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_SNAP_CB_KEY, snap_cb);
1692   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_SNAP_SB_KEY, snap_sb);
1693   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_LT_OM_KEY, linktype_om);
1694 #ifdef _WIN32
1695   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_BUFFER_SIZE_SB_KEY, buffer_size_sb);
1696 #endif
1697   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_PROMISC_KEY, promisc_cb);
1698   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_FILT_KEY,  filter_te);
1699   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_FILE_TE_KEY,  file_te);
1700   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_MULTI_FILES_ON_CB_KEY,  multi_files_on_cb);
1701   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_RING_NBF_CB_KEY,  ringbuffer_nbf_cb);
1702   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_RING_NBF_SB_KEY,  ringbuffer_nbf_sb);
1703   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_RING_NBF_LB_KEY,  ringbuffer_nbf_lb);
1704   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_RING_FILESIZE_CB_KEY,  ring_filesize_cb);
1705   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_RING_FILESIZE_SB_KEY,  ring_filesize_sb);
1706   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_RING_FILESIZE_OM_KEY,  ring_filesize_om);
1707   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_FILE_DURATION_CB_KEY,  file_duration_cb);
1708   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_FILE_DURATION_SB_KEY,  file_duration_sb);
1709   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_FILE_DURATION_OM_KEY,  file_duration_om);
1710   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_SYNC_KEY,  sync_cb);
1711   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_AUTO_SCROLL_KEY, auto_scroll_cb);
1712   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_HIDE_INFO_KEY, hide_info_cb);
1713   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_STOP_PACKETS_CB_KEY, stop_packets_cb);
1714   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_STOP_PACKETS_SB_KEY, stop_packets_sb);
1715   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_STOP_PACKETS_LB_KEY, stop_packets_lb);
1716   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_STOP_FILESIZE_CB_KEY, stop_filesize_cb);
1717   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_STOP_FILESIZE_SB_KEY, stop_filesize_sb);
1718   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_STOP_FILESIZE_OM_KEY, stop_filesize_om);
1719   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_STOP_DURATION_CB_KEY,  stop_duration_cb);
1720   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_STOP_DURATION_SB_KEY,  stop_duration_sb);
1721   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_STOP_DURATION_OM_KEY,  stop_duration_om);
1722   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_STOP_FILES_CB_KEY, stop_files_cb);
1723   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_STOP_FILES_SB_KEY, stop_files_sb);
1724   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_STOP_FILES_LB_KEY, stop_files_lb);
1725   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_M_RESOLVE_KEY,  m_resolv_cb);
1726   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_N_RESOLVE_KEY,  n_resolv_cb);
1727   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_T_RESOLVE_KEY,  t_resolv_cb);
1728 #ifdef HAVE_PCAP_SETSAMPLING
1729   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_SAMP_NONE_RB_KEY, samp_none_rb);
1730   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_SAMP_COUNT_RB_KEY, samp_count_rb);
1731   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_SAMP_COUNT_SB_KEY, samp_count_sb);
1732   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_SAMP_TIMER_RB_KEY, samp_timer_rb);
1733   g_object_set_data(G_OBJECT(cap_open_w), E_CAP_SAMP_TIMER_SB_KEY, samp_timer_sb);
1734 #endif
1735
1736   /* Set the sensitivity of various widgets as per the settings of other
1737      widgets. */
1738   capture_prep_adjust_sensitivity(NULL, cap_open_w);
1739
1740   /* Catch the "activate" signal on the text
1741      entries, so that if the user types Return there, we act as if the
1742      "OK" button had been selected, as happens if Return is typed if some
1743      widget that *doesn't* handle the Return key has the input focus. */
1744   dlg_set_activate(GTK_COMBO(if_cb)->entry, ok_bt);
1745   dlg_set_activate(filter_te, ok_bt);
1746   dlg_set_activate(file_te, ok_bt);
1747
1748   /* XXX - why does not
1749
1750      gtk_widget_grab_focus(if_cb);
1751
1752     give the initial focus to the "Interface" combo box?
1753
1754     Or should I phrase that as "why does GTK+ continually frustrate
1755     attempts to make GUIs driveable from the keyboard?"  We have to
1756     go catch the activate signal on every single GtkEntry widget
1757     (rather than having widgets whose activate signal is *not*
1758     caught not catch the Return keystroke, so that it passes on,
1759     ultimately, to the window, which can activate the default
1760     widget, i.e. the "OK" button); we have to catch the "key_press_event"
1761     signal and have the handler check for ESC, so that we can have ESC
1762     activate the "Cancel" button; in order to support Alt+<key> mnemonics
1763     for buttons and the like, we may have to construct an accelerator
1764     group by hand and set up the accelerators by hand (if that even
1765     works - I've not tried it yet); we have to do a "gtk_widget_grab_focus()"
1766     to keep some container widget from getting the initial focus, so that
1767     you don't have to tab into the first widget in order to start typing
1768     in it; and it now appears that you simply *can't* make a combo box
1769     get the initial focus, at least not in the obvious fashion. Sigh.... */
1770
1771   g_signal_connect(cap_open_w, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
1772   g_signal_connect(cap_open_w, "destroy", G_CALLBACK(capture_prep_destroy_cb), NULL);
1773
1774   /* Give the initial focus to the "Filter" entry box. */
1775   gtk_widget_grab_focus(filter_te);
1776
1777   gtk_widget_show_all(cap_open_w);
1778   window_present(cap_open_w);
1779 }
1780
1781 /* everythings prepared, now it's really time to start the capture */
1782 void
1783 capture_start_confirmed(void)
1784 {
1785
1786
1787     /* init iface, if never used before */
1788     /* XXX - would better be doing this in main.c */
1789     if(global_capture_opts.iface == NULL) {
1790         gchar *if_device;
1791         const gchar *if_name;
1792
1793         /* did the user ever selected a capture interface before? */
1794         if(prefs.capture_device == NULL) {
1795             simple_dialog(ESD_TYPE_CONFIRMATION,
1796                         ESD_BTN_OK,
1797                         "%sNo capture interface selected!%s\n\n"
1798                         "To select an interface use:\n\n"
1799                         "Capture->Options (until Wireshark is stopped)\n"
1800                         "Edit->Preferences/Capture (permanent, if saved)",
1801                         simple_dialog_primary_start(), simple_dialog_primary_end());
1802             return;
1803         }
1804         if_device = g_strdup(prefs.capture_device);
1805         if_name = get_if_name(if_device);
1806         global_capture_opts.iface = g_strdup(if_name);
1807         global_capture_opts.iface_descr = get_interface_descriptive_name(global_capture_opts.iface);
1808
1809         g_free(if_device);
1810     }
1811
1812     /* XXX - we might need to init other pref data as well... */
1813     menu_auto_scroll_live_changed(auto_scroll_live);
1814
1815     if (capture_start(&global_capture_opts)) {
1816         /* The capture succeeded, which means the capture filter syntax is
1817         valid; add this capture filter to the recent capture filter list. */
1818         cfilter_combo_add_recent(global_capture_opts.cfilter);
1819     }
1820 }
1821
1822 /* user confirmed the "Save capture file..." dialog */
1823 static void
1824 capture_start_answered_cb(gpointer dialog _U_, gint btn, gpointer data)
1825 {
1826     switch(btn) {
1827     case(ESD_BTN_SAVE):
1828         /* save file first */
1829         file_save_as_cmd(after_save_capture_dialog, data);
1830         break;
1831     case(ESD_BTN_DONT_SAVE):
1832         /* XXX - unlink old file? */
1833         /* start the capture */
1834         capture_start_confirmed();
1835         break;
1836     case(ESD_BTN_CANCEL):
1837         break;
1838     default:
1839         g_assert_not_reached();
1840     }
1841 }
1842
1843 /* user pressed the "Start" button (in dialog or toolbar) */
1844 void
1845 capture_start_cb(GtkWidget *w _U_, gpointer d _U_)
1846 {
1847   gpointer  dialog;
1848   gchar *if_name;
1849   gint *linktype_p = NULL;
1850
1851 #ifdef HAVE_AIRPCAP
1852   airpcap_if_active = airpcap_if_selected;
1853   airpcap_set_toolbar_start_capture(airpcap_if_active);
1854 #endif
1855
1856 #ifdef _WIN32
1857   /* Is WPcap loaded? */
1858   if (!has_wpcap) {
1859     char * err_msg = cant_load_winpcap_err("Wireshark");
1860
1861     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, err_msg);
1862     g_free(err_msg);
1863     return;
1864   }
1865 #endif
1866
1867   if(cap_open_w) {
1868     /*
1869      * There's an options dialog; get the values from it and close it.
1870      */
1871     gboolean success;
1872
1873     success = capture_dlg_prep(cap_open_w);
1874     window_destroy(GTK_WIDGET(cap_open_w));
1875     if (!success)
1876       return;   /* error in options dialog */
1877   }
1878
1879   if (global_capture_opts.iface == NULL) {
1880     if (prefs.capture_device == NULL) {
1881       simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
1882         "You didn't specify an interface on which to capture packets.");
1883       return;
1884     }
1885     if_name = g_strdup(get_if_name(prefs.capture_device));
1886   } else {
1887     if_name = g_strdup(global_capture_opts.iface);
1888   }
1889
1890   if (linktype_history != NULL) {
1891     linktype_p = g_hash_table_lookup(linktype_history, if_name);
1892     if (linktype_p == NULL) {
1893       linktype_p = g_malloc(sizeof (int));
1894       g_hash_table_insert(linktype_history, if_name, linktype_p);
1895     } else {
1896       g_free(if_name);
1897     }
1898     *linktype_p = global_capture_opts.linktype;
1899   } else {
1900     global_capture_opts.linktype = capture_dev_user_linktype_find(if_name);
1901     g_free(if_name);
1902   }
1903
1904   if((cfile.state != FILE_CLOSED) && !cfile.user_saved && prefs.gui_ask_unsaved) {
1905     /* user didn't saved his current file, ask him */
1906     dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_SAVE_DONTSAVE_CANCEL,
1907                 "%sSave capture file before starting a new capture?%s\n\n"
1908                 "If you start a new capture without saving, your current capture data will\nbe discarded.",
1909                 simple_dialog_primary_start(), simple_dialog_primary_end());
1910     simple_dialog_set_cb(dialog, capture_start_answered_cb, NULL);
1911   } else {
1912     /* unchanged file, just capture a new one */
1913     capture_start_confirmed();
1914   }
1915 }
1916
1917 /* user selected a link type, convert to internal value */
1918 static void
1919 select_link_type_cb(GtkWidget *w, gpointer data)
1920 {
1921   int new_linktype = GPOINTER_TO_INT(data);
1922   GtkWidget *linktype_om = g_object_get_data(G_OBJECT(w), E_CAP_LT_OM_KEY);
1923   int old_linktype = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(linktype_om), E_CAP_OM_LT_VALUE_KEY));
1924
1925   /* If the link is changed, update the menu and store the index and the value
1926      to reuse later when the dialog window will be reopened */
1927   if (old_linktype != new_linktype) {
1928     g_object_set_data(G_OBJECT(linktype_om), E_CAP_OM_LT_VALUE_KEY, GINT_TO_POINTER(new_linktype));
1929     global_capture_opts.linktype = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(linktype_om), E_CAP_OM_LT_VALUE_KEY));
1930   }
1931 }
1932
1933 #ifdef HAVE_PCAP_REMOTE
1934 /* user selected an interface type (local/remote), convert to internal value) */
1935 static void
1936 select_if_type_cb(GtkWidget *w, gpointer data)
1937 {
1938     int new_iftype = GPOINTER_TO_INT(data);
1939     GtkWidget *iftype_om = g_object_get_data(G_OBJECT(w), E_CAP_IFTYPE_OM_KEY);
1940     int old_iftype = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(iftype_om),
1941                                             E_CAP_OM_IFTYPE_VALUE_KEY));
1942
1943     if (old_iftype != new_iftype)
1944     {
1945         g_object_set_data(G_OBJECT(iftype_om), E_CAP_OM_IFTYPE_VALUE_KEY,
1946                         GINT_TO_POINTER(new_iftype));
1947     }
1948     if (new_iftype == CAPTURE_IFREMOTE)
1949     {
1950         capture_remote_cb(iftype_om, NULL);
1951     }
1952     else if (new_iftype != old_iftype)
1953     {
1954         global_capture_opts.src_type = CAPTURE_IFLOCAL;
1955         update_interface_list();
1956     }
1957 }
1958 #endif
1959
1960 /* user pressed "File" button */
1961 static void
1962 capture_prep_file_cb(GtkWidget *file_bt, GtkWidget *file_te)
1963 {
1964     file_selection_browse(file_bt, file_te, "Wireshark: Specify a Capture File", FILE_SELECTION_WRITE_BROWSE);
1965 }
1966
1967
1968 /* convert dialog settings into capture_opts values */
1969 static gboolean
1970 capture_dlg_prep(gpointer parent_w) {
1971   GtkWidget *if_cb, *snap_cb, *snap_sb, *promisc_cb, *filter_te, *filter_cm,
1972             *file_te, *multi_files_on_cb, *ringbuffer_nbf_sb, *ringbuffer_nbf_cb,
1973             *linktype_om, *sync_cb, *auto_scroll_cb, *hide_info_cb,
1974             *stop_packets_cb, *stop_packets_sb,
1975             *stop_filesize_cb, *stop_filesize_sb, *stop_filesize_om,
1976             *stop_duration_cb, *stop_duration_sb, *stop_duration_om,
1977             *ring_filesize_cb, *ring_filesize_sb, *ring_filesize_om,
1978             *file_duration_cb, *file_duration_sb, *file_duration_om,
1979             *stop_files_cb, *stop_files_sb,
1980             *m_resolv_cb, *n_resolv_cb, *t_resolv_cb;
1981 #ifdef HAVE_PCAP_REMOTE
1982   GtkWidget *iftype_om, *datatx_udp_cb, *nocap_rpcap_cb;
1983 #endif
1984 #ifdef HAVE_PCAP_SETSAMPLING
1985   GtkWidget *samp_none_rb, *samp_count_rb, *samp_timer_rb,
1986             *samp_count_sb, *samp_timer_sb;
1987 #endif
1988 #ifdef _WIN32
1989   GtkWidget *buffer_size_sb;
1990 #endif
1991   gchar *entry_text;
1992   gchar *if_text;
1993   const gchar *if_name;
1994   const gchar *filter_text;
1995   const gchar *g_save_file;
1996   gchar *cf_name;
1997   gchar *dirname;
1998   gint32 tmp;
1999
2000   if_cb     = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_IFACE_KEY);
2001 #ifdef HAVE_PCAP_REMOTE
2002   iftype_om = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_IFTYPE_OM_KEY);
2003   datatx_udp_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_DATATX_UDP_CB_KEY);
2004   nocap_rpcap_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_NOCAP_RPCAP_CB_KEY);
2005 #endif
2006   snap_cb   = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_SNAP_CB_KEY);
2007   snap_sb   = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_SNAP_SB_KEY);
2008   linktype_om = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_LT_OM_KEY);
2009 #ifdef _WIN32
2010   buffer_size_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_BUFFER_SIZE_SB_KEY);
2011 #endif
2012   promisc_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_PROMISC_KEY);
2013   filter_cm = g_object_get_data(G_OBJECT(top_level), E_CFILTER_CM_KEY);
2014   filter_te = GTK_COMBO(filter_cm)->entry;
2015   file_te   = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_FILE_TE_KEY);
2016   multi_files_on_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_MULTI_FILES_ON_CB_KEY);
2017   ringbuffer_nbf_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_RING_NBF_CB_KEY);
2018   ringbuffer_nbf_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_RING_NBF_SB_KEY);
2019   ring_filesize_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_RING_FILESIZE_CB_KEY);
2020   ring_filesize_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_RING_FILESIZE_SB_KEY);
2021   ring_filesize_om = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_RING_FILESIZE_OM_KEY);
2022   file_duration_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_FILE_DURATION_CB_KEY);
2023   file_duration_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_FILE_DURATION_SB_KEY);
2024   file_duration_om = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_FILE_DURATION_OM_KEY);
2025   sync_cb   = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_SYNC_KEY);
2026   auto_scroll_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_AUTO_SCROLL_KEY);
2027   hide_info_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_HIDE_INFO_KEY);
2028   stop_packets_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_PACKETS_CB_KEY);
2029   stop_packets_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_PACKETS_SB_KEY);
2030   stop_filesize_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_FILESIZE_CB_KEY);
2031   stop_filesize_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_FILESIZE_SB_KEY);
2032   stop_filesize_om = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_FILESIZE_OM_KEY);
2033   stop_duration_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_DURATION_CB_KEY);
2034   stop_duration_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_DURATION_SB_KEY);
2035   stop_duration_om = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_DURATION_OM_KEY);
2036   stop_files_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_FILES_CB_KEY);
2037   stop_files_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_FILES_SB_KEY);
2038   m_resolv_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_M_RESOLVE_KEY);
2039   n_resolv_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_N_RESOLVE_KEY);
2040   t_resolv_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_T_RESOLVE_KEY);
2041 #ifdef HAVE_PCAP_SETSAMPLING
2042   samp_none_rb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_SAMP_NONE_RB_KEY);
2043   samp_count_rb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_SAMP_COUNT_RB_KEY);
2044   samp_timer_rb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_SAMP_TIMER_RB_KEY);
2045   samp_count_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_SAMP_COUNT_SB_KEY);
2046   samp_timer_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_SAMP_TIMER_SB_KEY);
2047 #endif
2048
2049   entry_text =
2050     g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(if_cb)->entry)));
2051   if_text = g_strstrip(entry_text);
2052   if_name = get_if_name(if_text);
2053   if (*if_name == '\0') {
2054     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
2055       "You didn't specify an interface on which to capture packets.");
2056     g_free(entry_text);
2057     return FALSE;
2058   }
2059   if (global_capture_opts.iface)
2060     g_free(global_capture_opts.iface);
2061   if (global_capture_opts.iface_descr)
2062     g_free(global_capture_opts.iface_descr);
2063   global_capture_opts.iface = g_strdup(if_name);
2064   global_capture_opts.iface_descr = get_interface_descriptive_name(global_capture_opts.iface);
2065   g_free(entry_text);
2066   /* The Linktype will be stored when the interface will be changed, or if not, not datalink option is used,
2067      the acquisition will be performed on the default datalink for the device */
2068   /*  global_capture_opts.linktype =
2069       GPOINTER_TO_INT(g_object_get_data(G_OBJECT(linktype_om), E_CAP_OM_LT_VALUE_KEY)); */
2070
2071 #ifdef HAVE_PCAP_REMOTE
2072   global_capture_opts.src_type = (capture_source)
2073       GPOINTER_TO_INT(g_object_get_data(G_OBJECT(iftype_om), E_CAP_OM_IFTYPE_VALUE_KEY));
2074   global_capture_opts.datatx_udp =
2075       gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(datatx_udp_cb));
2076   global_capture_opts.nocap_rpcap =
2077       gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(nocap_rpcap_cb));
2078 #endif
2079 #ifdef HAVE_PCAP_SETSAMPLING
2080    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(samp_none_rb)))
2081        global_capture_opts.sampling_method = CAPTURE_SAMP_NONE;
2082    else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(samp_count_rb)))
2083    {
2084        global_capture_opts.sampling_method = CAPTURE_SAMP_BY_COUNT;
2085        global_capture_opts.sampling_param = gtk_spin_button_get_value_as_int(
2086                                         GTK_SPIN_BUTTON(samp_count_sb));
2087    }
2088    else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(samp_timer_rb)))
2089    {
2090        global_capture_opts.sampling_method = CAPTURE_SAMP_BY_TIMER;
2091        global_capture_opts.sampling_param = gtk_spin_button_get_value_as_int(
2092                                         GTK_SPIN_BUTTON(samp_timer_sb));
2093    }
2094 #endif
2095
2096 #ifdef _WIN32
2097   global_capture_opts.buffer_size =
2098     gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(buffer_size_sb));
2099 #endif
2100
2101   global_capture_opts.has_snaplen =
2102     gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(snap_cb));
2103   if (global_capture_opts.has_snaplen) {
2104     global_capture_opts.snaplen =
2105       gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(snap_sb));
2106     if (global_capture_opts.snaplen < 1)
2107       global_capture_opts.snaplen = WTAP_MAX_PACKET_SIZE;
2108     else if (global_capture_opts.snaplen < MIN_PACKET_SIZE)
2109       global_capture_opts.snaplen = MIN_PACKET_SIZE;
2110   }
2111
2112   global_capture_opts.promisc_mode =
2113     gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(promisc_cb));
2114
2115   /* XXX - don't try to get clever and set "cfile.filter" to NULL if the
2116      filter string is empty, as an indication that we don't have a filter
2117      and thus don't have to set a filter when capturing - the version of
2118      libpcap in Red Hat Linux 6.1, and versions based on later patches
2119      in that series, don't bind the AF_PACKET socket to an interface
2120      until a filter is set, which means they aren't bound at all if
2121      no filter is set, which means no packets arrive as input on that
2122      socket, which means Wireshark never sees any packets. */
2123   filter_text = gtk_entry_get_text(GTK_ENTRY(filter_te));
2124   if (global_capture_opts.cfilter)
2125     g_free(global_capture_opts.cfilter);
2126   g_assert(filter_text != NULL);
2127   global_capture_opts.cfilter = g_strdup(filter_text);
2128
2129   /* Wireshark always saves to a capture file. */
2130   global_capture_opts.saving_to_file = TRUE;
2131   g_save_file = gtk_entry_get_text(GTK_ENTRY(file_te));
2132   if (g_save_file && g_save_file[0]) {
2133     /* User specified a file to which the capture should be written. */
2134     global_capture_opts.save_file = g_strdup(g_save_file);
2135     /* Save the directory name for future file dialogs. */
2136     cf_name = g_strdup(g_save_file);
2137     dirname = get_dirname(cf_name);  /* Overwrites cf_name */
2138     set_last_open_dir(dirname);
2139     g_free(cf_name);
2140   } else {
2141     /* User didn't specify a file; save to a temporary file. */
2142     global_capture_opts.save_file = NULL;
2143   }
2144
2145   global_capture_opts.has_autostop_packets =
2146     gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_packets_cb));
2147   if (global_capture_opts.has_autostop_packets)
2148     global_capture_opts.autostop_packets =
2149       gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(stop_packets_sb));
2150
2151   global_capture_opts.has_autostop_duration =
2152     gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_duration_cb));
2153   if (global_capture_opts.has_autostop_duration) {
2154     global_capture_opts.autostop_duration =
2155       gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(stop_duration_sb));
2156     global_capture_opts.autostop_duration =
2157       time_unit_option_menu_get_value(stop_duration_om, global_capture_opts.autostop_duration);
2158   }
2159
2160   global_capture_opts.real_time_mode =
2161     gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(sync_cb));
2162
2163   auto_scroll_live =
2164       gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(auto_scroll_cb));
2165
2166   global_capture_opts.show_info =
2167       !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(hide_info_cb));
2168
2169   if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m_resolv_cb)))
2170     g_resolv_flags |= RESOLV_MAC;
2171   else
2172     g_resolv_flags &= ~RESOLV_MAC;
2173   if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(n_resolv_cb)))
2174     g_resolv_flags |= RESOLV_NETWORK;
2175   else
2176     g_resolv_flags &= ~RESOLV_NETWORK;
2177   if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t_resolv_cb)))
2178     g_resolv_flags |= RESOLV_TRANSPORT;
2179   else
2180     g_resolv_flags &= ~RESOLV_TRANSPORT;
2181
2182   global_capture_opts.has_ring_num_files =
2183     gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ringbuffer_nbf_cb));
2184
2185   global_capture_opts.ring_num_files =
2186     gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(ringbuffer_nbf_sb));
2187   if (global_capture_opts.ring_num_files > RINGBUFFER_MAX_NUM_FILES)
2188     global_capture_opts.ring_num_files = RINGBUFFER_MAX_NUM_FILES;
2189 #if RINGBUFFER_MIN_NUM_FILES > 0
2190   else if (global_capture_opts.ring_num_files < RINGBUFFER_MIN_NUM_FILES)
2191     global_capture_opts.ring_num_files = RINGBUFFER_MIN_NUM_FILES;
2192 #endif
2193
2194   global_capture_opts.multi_files_on =
2195     gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(multi_files_on_cb));
2196
2197   global_capture_opts.has_file_duration =
2198     gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(file_duration_cb));
2199   if (global_capture_opts.has_file_duration) {
2200     global_capture_opts.file_duration =
2201       gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(file_duration_sb));
2202     global_capture_opts.file_duration =
2203       time_unit_option_menu_get_value(file_duration_om, global_capture_opts.file_duration);
2204   }
2205
2206   global_capture_opts.has_autostop_files =
2207     gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_files_cb));
2208   if (global_capture_opts.has_autostop_files)
2209     global_capture_opts.autostop_files =
2210       gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(stop_files_sb));
2211
2212   if (global_capture_opts.multi_files_on) {
2213     global_capture_opts.has_autostop_filesize =
2214       gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ring_filesize_cb));
2215     if (global_capture_opts.has_autostop_filesize) {
2216       tmp = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(ring_filesize_sb));
2217       tmp = size_unit_option_menu_convert_value(ring_filesize_om, tmp);
2218       if(tmp != 0) {
2219         global_capture_opts.autostop_filesize = tmp;
2220       } else {
2221         simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
2222           "%sMultiple files: Requested filesize too large!%s\n\n"
2223           "The setting \"Next file every x byte(s)\" can't be greater than %u bytes (2GB).", 
2224           simple_dialog_primary_start(), simple_dialog_primary_end(), G_MAXINT);
2225         return FALSE;
2226       }
2227     }
2228
2229     /* test if the settings are ok for a ringbuffer */
2230     if (global_capture_opts.save_file == NULL) {
2231       simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
2232         "%sMultiple files: No capture file name given!%s\n\n"
2233         "You must specify a filename if you want to use multiple files.",
2234         simple_dialog_primary_start(), simple_dialog_primary_end());
2235       return FALSE;
2236     } else if (!global_capture_opts.has_autostop_filesize && !global_capture_opts.has_file_duration) {
2237       simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
2238         "%sMultiple files: No file limit given!%s\n\n"
2239         "You must specify a file size or duration at which is switched to the next capture file\n"
2240         "if you want to use multiple files.",
2241         simple_dialog_primary_start(), simple_dialog_primary_end());
2242       g_free(global_capture_opts.save_file);
2243       global_capture_opts.save_file = NULL;
2244       return FALSE;
2245     }
2246   } else {
2247     global_capture_opts.has_autostop_filesize =
2248       gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_filesize_cb));
2249     if (global_capture_opts.has_autostop_filesize) {
2250       tmp = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(stop_filesize_sb));
2251       tmp = size_unit_option_menu_convert_value(stop_filesize_om, tmp);
2252       if(tmp != 0) {
2253         global_capture_opts.autostop_filesize = tmp;
2254       } else {
2255         simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
2256           "%sStop Capture: Requested filesize too large!%s\n\n"
2257           "The setting \"... after x byte(s)\" can't be greater than %u bytes (2GB).", 
2258           simple_dialog_primary_start(), simple_dialog_primary_end(), G_MAXINT);
2259         return FALSE;
2260       }
2261     }
2262   } /* multi_files_on */
2263   return TRUE;
2264 }
2265
2266 /* user requested to destroy the dialog */
2267 static void
2268 capture_prep_destroy_cb(GtkWidget *win, gpointer user_data _U_)
2269 {
2270   GtkWidget *fs;
2271 #ifdef HAVE_PCAP_REMOTE
2272   GtkWidget *remote_w;
2273 #endif
2274
2275   /* Is there a file selection dialog associated with this
2276      Capture Options dialog? */
2277   fs = g_object_get_data(G_OBJECT(win), E_FILE_SEL_DIALOG_PTR_KEY);
2278
2279   if (fs != NULL) {
2280     /* Yes.  Destroy it. */
2281     window_destroy(fs);
2282   }
2283
2284   /* Note that we no longer have a "Capture Options" dialog box. */
2285   cap_open_w = NULL;
2286
2287 #ifdef HAVE_AIRPCAP
2288   /* update airpcap toolbar */
2289   airpcap_set_toolbar_stop_capture(airpcap_if_active);
2290 #endif
2291
2292 #ifdef HAVE_PCAP_REMOTE
2293   remote_w = g_object_get_data(G_OBJECT(win), E_CAP_REMOTE_DIALOG_PTR_KEY);
2294   if (remote_w != NULL)
2295       window_destroy(remote_w);
2296 #endif
2297 }
2298
2299 /* user changed the interface entry */
2300 static void
2301 capture_prep_interface_changed_cb(GtkWidget *entry, gpointer argp)
2302 {
2303   GtkWidget *linktype_om = argp;
2304
2305   set_link_type_list(linktype_om, entry);
2306 }
2307
2308 /*
2309  * Adjust the sensitivity of various widgets as per the current setting
2310  * of other widgets.
2311  */
2312 static void
2313 capture_prep_adjust_sensitivity(GtkWidget *tb _U_, gpointer parent_w)
2314 {
2315   GtkWidget *if_cb,
2316             *snap_cb, *snap_sb,
2317             *multi_files_on_cb, *ringbuffer_nbf_cb, *ringbuffer_nbf_sb, *ringbuffer_nbf_lb,
2318             *ring_filesize_cb, *ring_filesize_sb, *ring_filesize_om,
2319             *file_duration_cb, *file_duration_sb, *file_duration_om,
2320             *sync_cb, *auto_scroll_cb, *hide_info_cb,
2321             *stop_packets_cb, *stop_packets_sb, *stop_packets_lb,
2322             *stop_filesize_cb, *stop_filesize_sb, *stop_filesize_om,
2323             *stop_duration_cb, *stop_duration_sb, *stop_duration_om,
2324             *stop_files_cb, *stop_files_sb, *stop_files_lb;
2325 #ifdef HAVE_PCAP_SETSAMPLING
2326   GtkWidget *samp_count_rb, *samp_timer_rb,
2327             *samp_count_sb, *samp_timer_sb;
2328 #endif
2329
2330
2331   if_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_IFACE_KEY);
2332   snap_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_SNAP_CB_KEY);
2333   snap_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_SNAP_SB_KEY);
2334   multi_files_on_cb  = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_MULTI_FILES_ON_CB_KEY);
2335   ringbuffer_nbf_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_RING_NBF_CB_KEY);
2336   ringbuffer_nbf_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_RING_NBF_SB_KEY);
2337   ringbuffer_nbf_lb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_RING_NBF_LB_KEY);
2338   ring_filesize_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_RING_FILESIZE_CB_KEY);
2339   ring_filesize_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_RING_FILESIZE_SB_KEY);
2340   ring_filesize_om = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_RING_FILESIZE_OM_KEY);
2341   file_duration_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_FILE_DURATION_CB_KEY);
2342   file_duration_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_FILE_DURATION_SB_KEY);
2343   file_duration_om = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_FILE_DURATION_OM_KEY);
2344   sync_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_SYNC_KEY);
2345   auto_scroll_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_AUTO_SCROLL_KEY);
2346   hide_info_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_HIDE_INFO_KEY);
2347   stop_packets_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_PACKETS_CB_KEY);
2348   stop_packets_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_PACKETS_SB_KEY);
2349   stop_packets_lb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_PACKETS_LB_KEY);
2350   stop_filesize_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_FILESIZE_CB_KEY);
2351   stop_filesize_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_FILESIZE_SB_KEY);
2352   stop_filesize_om = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_FILESIZE_OM_KEY);
2353   stop_duration_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_DURATION_CB_KEY);
2354   stop_duration_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_DURATION_SB_KEY);
2355   stop_duration_om = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_DURATION_OM_KEY);
2356   stop_files_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_FILES_CB_KEY);
2357   stop_files_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_FILES_SB_KEY);
2358   stop_files_lb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_FILES_LB_KEY);
2359 #ifdef HAVE_PCAP_SETSAMPLING
2360   samp_count_rb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_SAMP_COUNT_RB_KEY);
2361   samp_timer_rb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_SAMP_TIMER_RB_KEY);
2362   samp_count_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_SAMP_COUNT_SB_KEY);
2363   samp_timer_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_SAMP_TIMER_SB_KEY);
2364 #endif
2365
2366   /* The snapshot length spinbox is sensitive if the "Limit each packet
2367      to" checkbox is on. */
2368   gtk_widget_set_sensitive(GTK_WIDGET(snap_sb),
2369       gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(snap_cb)));
2370
2371
2372   if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(sync_cb))) {
2373     /* "Update list of packets in real time" captures enabled; we don't
2374        support ring buffer mode for those captures, so turn ring buffer
2375        mode off if it's on, and make its toggle button, and the spin
2376        button for the number of ring buffer files (and the spin button's
2377        label), insensitive. */
2378 /*    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(multi_files_on_cb), FALSE);
2379     gtk_widget_set_sensitive(GTK_WIDGET(multi_files_on_cb), FALSE);*/
2380
2381     /* Auto-scroll mode is meaningful only in "Update list of packets
2382        in real time" captures, so make its toggle button sensitive. */
2383     gtk_widget_set_sensitive(GTK_WIDGET(auto_scroll_cb), TRUE);
2384
2385     /*gtk_widget_set_sensitive(GTK_WIDGET(hide_info_cb), TRUE);*/
2386   } else {
2387     /* "Update list of packets in real time" captures disabled; that
2388        means ring buffer mode is OK, so make its toggle button
2389        sensitive. */
2390 /*    gtk_widget_set_sensitive(GTK_WIDGET(multi_files_on_cb), TRUE);*/
2391
2392     /* Auto-scroll mode is meaningful only in "Update list of packets
2393        in real time" captures, so make its toggle button insensitive. */
2394     gtk_widget_set_sensitive(GTK_WIDGET(auto_scroll_cb), FALSE);
2395
2396     /*gtk_widget_set_sensitive(GTK_WIDGET(hide_info_cb), FALSE);*/
2397   }
2398
2399   if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(multi_files_on_cb))) {
2400     /* Ring buffer mode enabled. */
2401
2402     /* Force at least one of the "file switch" conditions (we need at least one) */
2403     if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ring_filesize_cb)) == FALSE &&
2404         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(file_duration_cb)) == FALSE) {
2405       if (tb == ring_filesize_cb)
2406         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(file_duration_cb), TRUE);
2407       else
2408         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ring_filesize_cb), TRUE);
2409     }
2410
2411     gtk_widget_set_sensitive(GTK_WIDGET(ringbuffer_nbf_cb), TRUE);
2412     gtk_widget_set_sensitive(GTK_WIDGET(ringbuffer_nbf_sb),
2413           gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ringbuffer_nbf_cb)));
2414     gtk_widget_set_sensitive(GTK_WIDGET(ringbuffer_nbf_lb),
2415           gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ringbuffer_nbf_cb)));
2416
2417     /* The ring filesize spinbox is sensitive if the "Next capture file
2418          after N kilobytes" checkbox is on. */
2419     gtk_widget_set_sensitive(GTK_WIDGET(ring_filesize_cb), TRUE);
2420     gtk_widget_set_sensitive(GTK_WIDGET(ring_filesize_sb),
2421           gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ring_filesize_cb)));
2422     gtk_widget_set_sensitive(GTK_WIDGET(ring_filesize_om),
2423           gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ring_filesize_cb)));
2424
2425     /* The ring duration spinbox is sensitive if the "Next capture file
2426          after N seconds" checkbox is on. */
2427     gtk_widget_set_sensitive(GTK_WIDGET(file_duration_cb), TRUE);
2428     gtk_widget_set_sensitive(GTK_WIDGET(file_duration_sb),
2429           gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(file_duration_cb)));
2430     gtk_widget_set_sensitive(GTK_WIDGET(file_duration_om),
2431           gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(file_duration_cb)));
2432
2433     gtk_widget_set_sensitive(GTK_WIDGET(stop_filesize_cb), FALSE);
2434     gtk_widget_set_sensitive(GTK_WIDGET(stop_filesize_sb), FALSE);
2435     gtk_widget_set_sensitive(GTK_WIDGET(stop_filesize_om), FALSE);
2436
2437     gtk_widget_set_sensitive(GTK_WIDGET(stop_files_cb), TRUE);
2438     gtk_widget_set_sensitive(GTK_WIDGET(stop_files_sb),
2439           gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_files_cb)));
2440     gtk_widget_set_sensitive(GTK_WIDGET(stop_files_lb),
2441           gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_files_cb)));
2442   } else {
2443     /* Ring buffer mode disabled. */
2444     gtk_widget_set_sensitive(GTK_WIDGET(ringbuffer_nbf_cb), FALSE);
2445     gtk_widget_set_sensitive(GTK_WIDGET(ringbuffer_nbf_sb), FALSE);
2446     gtk_widget_set_sensitive(GTK_WIDGET(ringbuffer_nbf_lb), FALSE);
2447
2448     gtk_widget_set_sensitive(GTK_WIDGET(ring_filesize_cb), FALSE);
2449     gtk_widget_set_sensitive(GTK_WIDGET(ring_filesize_sb),FALSE);
2450     gtk_widget_set_sensitive(GTK_WIDGET(ring_filesize_om),FALSE);
2451
2452     gtk_widget_set_sensitive(GTK_WIDGET(file_duration_cb), FALSE);
2453     gtk_widget_set_sensitive(GTK_WIDGET(file_duration_sb),FALSE);
2454     gtk_widget_set_sensitive(GTK_WIDGET(file_duration_om),FALSE);
2455
2456     /* The maximum file size spinbox is sensitive if the "Stop capture
2457          after N kilobytes" checkbox is on. */
2458     gtk_widget_set_sensitive(GTK_WIDGET(stop_filesize_cb), TRUE);
2459     gtk_widget_set_sensitive(GTK_WIDGET(stop_filesize_sb),
2460           gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_filesize_cb)));
2461     gtk_widget_set_sensitive(GTK_WIDGET(stop_filesize_om),
2462           gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_filesize_cb)));
2463
2464     gtk_widget_set_sensitive(GTK_WIDGET(stop_files_cb), FALSE);
2465     gtk_widget_set_sensitive(GTK_WIDGET(stop_files_sb), FALSE);
2466     gtk_widget_set_sensitive(GTK_WIDGET(stop_files_lb), FALSE);
2467   }
2468
2469   /* The maximum packet count spinbox is sensitive if the "Stop capture
2470      after N packets" checkbox is on. */
2471   gtk_widget_set_sensitive(GTK_WIDGET(stop_packets_sb),
2472       gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_packets_cb)));
2473   gtk_widget_set_sensitive(GTK_WIDGET(stop_packets_lb),
2474       gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_packets_cb)));
2475
2476   /* The capture duration spinbox is sensitive if the "Stop capture
2477      after N seconds" checkbox is on. */
2478   gtk_widget_set_sensitive(GTK_WIDGET(stop_duration_sb),
2479       gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_duration_cb)));
2480   gtk_widget_set_sensitive(GTK_WIDGET(stop_duration_om),
2481       gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_duration_cb)));
2482
2483 #ifdef HAVE_PCAP_SETSAMPLING
2484    gtk_widget_set_sensitive(GTK_WIDGET(samp_count_sb),
2485       gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(samp_count_rb)));
2486    gtk_widget_set_sensitive(GTK_WIDGET(samp_timer_sb),
2487       gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(samp_timer_rb)));
2488 #endif
2489 }
2490
2491 #endif /* HAVE_LIBPCAP */