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