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