some more : try to make read/write not break the build if the return value is not...
[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 #include <string.h>
32 #include <gtk/gtk.h>
33 #include <stdio.h>        /* menu.h needs FILE */
34 #include <gtk/menu.h>
35
36 #include <epan/packet.h>
37 #include "capture.h"
38 #include "globals.h"
39 #include <epan/addr_resolv.h>
40 #include "main.h"
41 #include "gui_utils.h"
42 #include "capture_dlg.h"
43 #include "capture_errs.h"
44 #include "filter_dlg.h"
45 #include "simple_dialog.h"
46 #include "dlg_utils.h"
47 #include "file_dlg.h"
48 #include "capture-pcap-util.h"
49 #include "capture_ui_utils.h"
50 #include <epan/prefs.h>
51 #include "ringbuffer.h"
52 #include <epan/filesystem.h>
53 #include "compat_macros.h"
54 #include "capture_file_dlg.h"
55 #include "help_dlg.h"
56 #include "gtkglobals.h"
57 #include "cfilter_combo_utils.h"
58
59 #ifdef _WIN32
60 #include "capture-wpcap.h"
61 #endif
62
63 #include "keys.h"
64
65 #ifdef HAVE_AIRPCAP
66 #include <airpcap.h>
67 #include "airpcap_loader.h"
68 #include "airpcap_gui_utils.h"
69 #include "airpcap_dlg.h"
70 #endif
71
72 /* Capture callback data keys */
73 #define E_CAP_IFACE_KEY             "cap_iface"
74 #define E_CAP_IFACE_IP_KEY          "cap_iface_ip"
75 #define E_CAP_SNAP_CB_KEY           "cap_snap_cb"
76 #define E_CAP_LT_OM_KEY             "cap_lt_om"
77 #define E_CAP_LT_OM_LABEL_KEY       "cap_lt_om_label"
78 #ifdef _WIN32
79 #define E_CAP_BUFFER_SIZE_SB_KEY    "cap_buffer_size_sb"
80 #endif
81 #define E_CAP_SNAP_SB_KEY           "cap_snap_sb"
82 #define E_CAP_PROMISC_KEY           "cap_promisc"
83 #define E_CAP_FILT_KEY              "cap_filter_te"
84 #define E_CAP_FILE_TE_KEY           "cap_file_te"
85 #define E_CAP_MULTI_FILES_ON_CB_KEY "cap_multi_files_on_cb"
86 #define E_CAP_RING_FILESIZE_CB_KEY  "cap_ring_filesize_cb"
87 #define E_CAP_RING_FILESIZE_SB_KEY  "cap_ring_filesize_sb"
88 #define E_CAP_RING_FILESIZE_OM_KEY  "cap_ring_filesize_om"
89 #define E_CAP_FILE_DURATION_CB_KEY  "cap_file_duration_cb"
90 #define E_CAP_FILE_DURATION_SB_KEY  "cap_file_duration_sb"
91 #define E_CAP_FILE_DURATION_OM_KEY  "cap_file_duration_om"
92 #define E_CAP_RING_NBF_CB_KEY       "cap_ring_nbf_cb"
93 #define E_CAP_RING_NBF_SB_KEY       "cap_ring_nbf_sb"
94 #define E_CAP_RING_NBF_LB_KEY       "cap_ring_nbf_lb"
95 #define E_CAP_STOP_FILES_CB_KEY     "cap_stop_files_cb"
96 #define E_CAP_STOP_FILES_SB_KEY     "cap_stop_files_sb"
97 #define E_CAP_STOP_FILES_LB_KEY     "cap_stop_files_lb"
98 #define E_CAP_SYNC_KEY              "cap_sync"
99 #define E_CAP_AUTO_SCROLL_KEY       "cap_auto_scroll"
100 #define E_CAP_HIDE_INFO_KEY         "cap_hide_info"
101 #define E_CAP_STOP_PACKETS_CB_KEY   "cap_stop_packets_cb"
102 #define E_CAP_STOP_PACKETS_SB_KEY   "cap_stop_packets_sb"
103 #define E_CAP_STOP_PACKETS_LB_KEY   "cap_stop_packets_lb"
104 #define E_CAP_STOP_FILESIZE_CB_KEY  "cap_stop_filesize_cb"
105 #define E_CAP_STOP_FILESIZE_SB_KEY  "cap_stop_filesize_sb"
106 #define E_CAP_STOP_FILESIZE_OM_KEY  "cap_stop_filesize_om"
107 #define E_CAP_STOP_DURATION_CB_KEY  "cap_stop_duration_cb"
108 #define E_CAP_STOP_DURATION_SB_KEY  "cap_stop_duration_sb"
109 #define E_CAP_STOP_DURATION_OM_KEY  "cap_stop_duration_om"
110 #define E_CAP_M_RESOLVE_KEY         "cap_m_resolve"
111 #define E_CAP_N_RESOLVE_KEY         "cap_n_resolve"
112 #define E_CAP_T_RESOLVE_KEY         "cap_t_resolve"
113
114 #define E_CAP_OM_LT_VALUE_KEY       "cap_om_lt_value"
115
116
117 /*
118  * Keep a static pointer to the current "Capture Options" window, if
119  * any, so that if somebody tries to do "Capture:Start" while there's
120  * already a "Capture Options" window up, we just pop up the existing
121  * one, rather than creating a new one.
122  */
123 static GtkWidget *cap_open_w;
124 static GtkWidget * dl_hdr_menu=NULL;
125 static guint linktype_history=0;
126
127 static void
128 capture_prep_file_cb(GtkWidget *file_bt, GtkWidget *file_te);
129
130 static void
131 select_link_type_cb(GtkWidget *w, gpointer data);
132
133 static void
134 capture_prep_adjust_sensitivity(GtkWidget *tb, gpointer parent_w);
135
136 static void
137 capture_prep_destroy_cb(GtkWidget *win, gpointer user_data);
138
139 static void
140 capture_prep_interface_changed_cb(GtkWidget *entry, gpointer parent_w);
141
142 static void
143 capture_dlg_prep(gpointer parent_w);
144
145
146 /* stop the currently running capture */
147 void
148 capture_stop_cb(GtkWidget *w _U_, gpointer d _U_)
149 {
150 #ifdef HAVE_AIRPCAP
151         airpcap_set_toolbar_stop_capture(airpcap_if_active);
152 #endif
153
154     capture_stop(capture_opts);
155 }
156
157 /* restart (stop - delete old file - start) running capture */
158 void
159 capture_restart_cb(GtkWidget *w _U_, gpointer d _U_)
160 {
161 #ifdef HAVE_AIRPCAP
162         airpcap_set_toolbar_start_capture(airpcap_if_active);
163 #endif
164
165     capture_restart(capture_opts);
166 }
167
168 /* init the link type list */
169 /* (often this list has only one entry and will therefore be disabled) */
170 static void
171 set_link_type_list(GtkWidget *linktype_om, GtkWidget *entry)
172 {
173   gchar *entry_text;
174   gchar *if_text;
175   gchar *if_name;
176   GList *if_list;
177   GList *if_entry;
178   if_info_t *if_info;
179   GList *lt_list;
180   int err;
181   GtkWidget *lt_menu, *lt_menu_item;
182   GList *lt_entry;
183   data_link_info_t *data_link_info;
184   gchar *linktype_menu_label;
185   guint num_supported_link_types;
186   GtkWidget *linktype_lb = OBJECT_GET_DATA(linktype_om, E_CAP_LT_OM_LABEL_KEY);
187   GtkWidget *if_ip_lb;
188   GString *ip_str = g_string_new("IP address: ");
189   int ips = 0;
190   GSList *curr_ip;
191   if_addr_t *ip_addr;
192 #ifdef HAVE_AIRPCAP
193   GtkWidget *advanced_bt;
194 #endif
195
196   /* Deallocate the existing menu for Datalink header type */
197   if (dl_hdr_menu != NULL)
198     gtk_widget_destroy(dl_hdr_menu);
199
200   lt_menu = gtk_menu_new();
201   dl_hdr_menu= lt_menu;
202   entry_text = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry)));
203   if_text = g_strstrip(entry_text);
204   if_name = g_strdup(get_if_name(if_text));
205
206 #ifdef HAVE_AIRPCAP
207   /* is it an airpcap interface??? */
208   /* retrieve the advanced button pointer */
209   advanced_bt = OBJECT_GET_DATA(entry,AIRPCAP_OPTIONS_ADVANCED_KEY);
210   airpcap_if_selected = get_airpcap_if_by_name(airpcap_if_list,if_name);
211   airpcap_enable_toolbar_widgets(airpcap_tb,FALSE);
212   if( airpcap_if_selected != NULL)
213         {
214         gtk_widget_set_sensitive(advanced_bt,TRUE);
215         }
216   else
217         {
218         gtk_widget_set_sensitive(advanced_bt,FALSE);
219         }
220 #endif
221
222   /*
223    * If the interface name is in the list of known interfaces, get
224    * its list of link-layer types and set the option menu to display it.
225    *
226    * If it's not, don't bother - the user might be in the middle of
227    * editing the list, or it might be a remote device in which case
228    * getting the list could take an arbitrarily-long period of time.
229    * The list currently won't contain any remote devices (as
230    * "pcap_findalldevs()" doesn't know about remote devices, and neither
231    * does the code we use if "pcap_findalldevs()" isn't available), but
232    * should contain all the local devices on which you can capture.
233    */
234   lt_list = NULL;
235   if (*if_name != '\0') {
236     /*
237      * Try to get the list of known interfaces.
238      */
239     if_list = get_interface_list(&err, NULL);
240     if (if_list != NULL) {
241       /*
242        * We have the list - check it.
243        */
244       for (if_entry = if_list; if_entry != NULL;
245            if_entry = g_list_next(if_entry)) {
246         if_info = if_entry->data;
247         if (strcmp(if_info->name, if_name) == 0) {
248           /*
249            * It's in the list.
250            * Get the list of link-layer types for it.
251            */
252           lt_list = get_pcap_linktype_list(if_name, NULL);
253
254           /* create string of list of IP addresses of this interface */
255           for (; (curr_ip = g_slist_nth(if_info->ip_addr, ips)) != NULL; ips++) {
256             if (ips != 0)
257               g_string_append(ip_str, ", ");
258
259             ip_addr = (if_addr_t *)curr_ip->data;
260             switch (ip_addr->type) {
261
262             case AT_IPv4:
263               g_string_append(ip_str,
264                 ip_to_str((guint8 *)&ip_addr->ip_addr.ip4_addr));
265               break;
266
267             case AT_IPv6:
268               g_string_append(ip_str,
269                   ip6_to_str((struct e_in6_addr *)&ip_addr->ip_addr.ip6_addr));
270               break;
271
272             default:
273               g_assert_not_reached();
274             }
275           }
276
277           if (if_info->loopback)
278             g_string_append(ip_str, " (loopback)");
279         }
280       }
281       free_interface_list(if_list);
282     }
283   }
284   g_free(entry_text);
285   g_free(if_name);
286   num_supported_link_types = 0;
287   for (lt_entry = lt_list; lt_entry != NULL; lt_entry = g_list_next(lt_entry)) {
288     data_link_info = lt_entry->data;
289     if (data_link_info->description != NULL) {
290       lt_menu_item = gtk_menu_item_new_with_label(data_link_info->description);
291       OBJECT_SET_DATA(lt_menu_item, E_CAP_LT_OM_KEY, linktype_om);
292       SIGNAL_CONNECT(lt_menu_item, "activate", select_link_type_cb,
293                      GINT_TO_POINTER(data_link_info->dlt));
294       num_supported_link_types++;
295     } else {
296       /* Not supported - tell them about it but don't let them select it. */
297       linktype_menu_label = g_strdup_printf("%s (not supported)",
298                                             data_link_info->name);
299       lt_menu_item = gtk_menu_item_new_with_label(linktype_menu_label);
300       g_free(linktype_menu_label);
301       gtk_widget_set_sensitive(lt_menu_item, FALSE);
302     }
303     gtk_menu_append(GTK_MENU(lt_menu), lt_menu_item);
304     gtk_widget_show(lt_menu_item);
305   }
306   if (lt_list != NULL)
307     free_pcap_linktype_list(lt_list);
308   gtk_option_menu_set_menu(GTK_OPTION_MENU(linktype_om), lt_menu);
309   gtk_widget_set_sensitive(linktype_lb, num_supported_link_types >= 2);
310   gtk_widget_set_sensitive(linktype_om, num_supported_link_types >= 2);
311   /* Restore the menu to the last index used */
312   gtk_option_menu_set_history(GTK_OPTION_MENU(linktype_om),linktype_history);
313   if_ip_lb = OBJECT_GET_DATA(linktype_om, E_CAP_IFACE_KEY);
314   if(ips == 0) {
315     g_string_append(ip_str, "unknown");
316   }
317   gtk_label_set_text(GTK_LABEL(if_ip_lb), ip_str->str);
318 #if GTK_CHECK_VERSION(2,6,0)
319   gtk_label_set_ellipsize(GTK_LABEL(if_ip_lb), PANGO_ELLIPSIZE_MIDDLE);
320 #endif
321   g_string_free(ip_str, TRUE);
322 }
323
324
325 #define TIME_UNIT_SECOND    0
326 #define TIME_UNIT_MINUTE    1
327 #define TIME_UNIT_HOUR      2
328 #define TIME_UNIT_DAY       3
329 #define MAX_TIME_UNITS 4
330 static const char *time_unit_name[MAX_TIME_UNITS] = {
331         "second(s)",
332         "minute(s)",
333         "hour(s)",
334         "day(s)",
335 };
336
337 /* create one of the duration options */
338 /* (and select the matching unit depending on the given value) */
339 static GtkWidget *time_unit_option_menu_new(guint32 value) {
340     GtkWidget *unit_om, *menu, *menu_item;
341     int i;
342
343         unit_om=gtk_option_menu_new();
344         menu=gtk_menu_new();
345         for(i=0;i<MAX_TIME_UNITS;i++){
346                 menu_item=gtk_menu_item_new_with_label(time_unit_name[i]);
347                 OBJECT_SET_DATA(menu_item, "time_unit", GINT_TO_POINTER(i));
348                 gtk_menu_append(GTK_MENU(menu), menu_item);
349         }
350
351     /* the selected menu item can't be changed, once the option_menu
352        is created, so set the matching menu item now */
353     /* days */
354     if(value >= 60 * 60 * 24) {
355             gtk_menu_set_active(GTK_MENU(menu), TIME_UNIT_DAY);
356     } else {
357         /* hours */
358         if(value >= 60 * 60) {
359                 gtk_menu_set_active(GTK_MENU(menu), TIME_UNIT_HOUR);
360         } else {
361             /* minutes */
362             if(value >= 60) {
363                     gtk_menu_set_active(GTK_MENU(menu), TIME_UNIT_MINUTE);
364             } else {
365                 /* seconds */
366                     gtk_menu_set_active(GTK_MENU(menu), TIME_UNIT_SECOND);
367             }
368         }
369     }
370
371         gtk_option_menu_set_menu(GTK_OPTION_MENU(unit_om), menu);
372
373     return unit_om;
374 }
375
376 /* convert time value from raw to displayed (e.g. 60s -> 1min) */
377 static guint32 time_unit_option_menu_convert_value(
378 guint32 value)
379 {
380     /* days */
381     if(value >= 60 * 60 * 24) {
382         return value / (60 * 60 * 24);
383     }
384
385     /* hours */
386     if(value >= 60 * 60) {
387         return value / (60 * 60);
388     }
389
390     /* minutes */
391     if(value >= 60) {
392         return value / 60;
393     }
394
395     /* seconds */
396     return value;
397 }
398
399 /* get raw value from unit and value fields */
400 static guint32 time_unit_option_menu_get_value(
401 GtkWidget *unit_om,
402 guint32 value)
403 {
404         GtkWidget *menu, *menu_item;
405     int unit;
406
407     menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(unit_om));
408     menu_item = gtk_menu_get_active(GTK_MENU(menu));
409     unit = GPOINTER_TO_INT(OBJECT_GET_DATA(menu_item, "time_unit"));
410
411
412     switch(unit) {
413     case(TIME_UNIT_SECOND):
414         return value;
415         break;
416     case(TIME_UNIT_MINUTE):
417         return value * 60;
418         break;
419     case(TIME_UNIT_HOUR):
420         return value * 60 * 60;
421         break;
422     case(TIME_UNIT_DAY):
423         return value * 60 * 60 * 24;
424         break;
425     default:
426         g_assert_not_reached();
427         return 0;
428     }
429 }
430
431
432 #define SIZE_UNIT_KILOBYTES 0
433 #define SIZE_UNIT_MEGABYTES 1
434 #define SIZE_UNIT_GIGABYTES 2
435 #define MAX_SIZE_UNITS 3
436 static const char *size_unit_name[MAX_SIZE_UNITS] = {
437         "kilobyte(s)",
438         "megabyte(s)",
439         "gigabyte(s)",
440 };
441
442 /* create one of the size options */
443 /* (and select the matching unit depending on the given value) */
444 static GtkWidget *size_unit_option_menu_new(guint32 value) {
445     GtkWidget *unit_om, *menu, *menu_item;
446     int i;
447
448         unit_om=gtk_option_menu_new();
449         menu=gtk_menu_new();
450         for(i=0;i<MAX_SIZE_UNITS;i++){
451                 menu_item=gtk_menu_item_new_with_label(size_unit_name[i]);
452                 OBJECT_SET_DATA(menu_item, "size_unit", GINT_TO_POINTER(i));
453                 gtk_menu_append(GTK_MENU(menu), menu_item);
454         }
455
456     /* the selected menu item can't be changed, once the option_menu
457        is created, so set the matching menu item now */
458     /* gigabytes */
459     if(value >= 1024 * 1024) {
460             gtk_menu_set_active(GTK_MENU(menu), SIZE_UNIT_GIGABYTES);
461     } else {
462         /* megabytes */
463         if(value >= 1024) {
464                 gtk_menu_set_active(GTK_MENU(menu), SIZE_UNIT_MEGABYTES);
465         } else {
466             /* kilobytes */
467             gtk_menu_set_active(GTK_MENU(menu), SIZE_UNIT_KILOBYTES);
468         }
469     }
470
471         gtk_option_menu_set_menu(GTK_OPTION_MENU(unit_om), menu);
472
473     return unit_om;
474 }
475
476 /* convert size value from raw to displayed (e.g. 1024 Bytes -> 1 KB) */
477 static guint32 size_unit_option_menu_set_value(
478 guint32 value)
479 {
480     /* gigabytes */
481     if(value >= 1024 * 1024) {
482         return value / (1024 * 1024);
483     }
484
485     /* megabytes */
486     if(value >= 1024) {
487         return value / (1024);
488     }
489
490     /* kilobytes */
491     return value;
492 }
493
494 /* get raw value from unit and value fields */
495 static guint32 size_unit_option_menu_convert_value(
496 GtkWidget *unit_om,
497 guint32 value)
498 {
499         GtkWidget *menu, *menu_item;
500     int unit;
501
502     menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(unit_om));
503     menu_item = gtk_menu_get_active(GTK_MENU(menu));
504     unit = GPOINTER_TO_INT(OBJECT_GET_DATA(menu_item, "size_unit"));
505
506
507     switch(unit) {
508     case(SIZE_UNIT_KILOBYTES):
509         return value;
510         break;
511     case(SIZE_UNIT_MEGABYTES):
512         if(value > G_MAXINT / 1024) {
513             return 0;
514         } else {
515             return value * 1024;
516         }
517         break;
518     case(SIZE_UNIT_GIGABYTES):
519         if(value > G_MAXINT / (1024 * 1024)) {
520             return 0;
521         } else {
522             return value * 1024 * 1024;
523         }
524         break;
525     default:
526         g_assert_not_reached();
527         return 0;
528     }
529 }
530
531 #ifdef HAVE_AIRPCAP
532 /*
533  * Sets the toolbar before calling the advanced dialog with for the right interface
534  */
535 void
536 options_airpcap_advanced_cb(GtkWidget *w _U_, gpointer d _U_)
537 {
538 int *from_widget;
539
540 from_widget = (gint*)g_malloc(sizeof(gint));
541 *from_widget = AIRPCAP_ADVANCED_FROM_OPTIONS;
542 OBJECT_SET_DATA(airpcap_tb,AIRPCAP_ADVANCED_FROM_KEY,from_widget);
543
544 airpcap_if_active = airpcap_if_selected;
545 airpcap_enable_toolbar_widgets(airpcap_tb,FALSE);
546 display_airpcap_advanced_cb(w,d);
547 }
548 #endif
549
550 /* show capture prepare (options) dialog */
551 void
552 capture_prep_cb(GtkWidget *w _U_, gpointer d _U_)
553 {
554   GtkWidget     *main_vb,
555                 *main_hb, *left_vb, *right_vb,
556
557                 *capture_fr, *capture_vb,
558                 *if_hb, *if_cb, *if_lb,
559                 *if_ip_hb, *if_ip_lb, *if_ip_eb,
560                 *linktype_hb, *linktype_lb, *linktype_om,
561                 *snap_hb, *snap_cb, *snap_sb, *snap_lb,
562                 *promisc_cb,
563                 *filter_hb, *filter_bt, *filter_te, *filter_cm,
564
565                 *file_fr, *file_vb,
566                 *file_hb, *file_bt, *file_lb, *file_te,
567                 *multi_tb, *multi_files_on_cb,
568                 *ring_filesize_cb, *ring_filesize_sb, *ring_filesize_om,
569                 *file_duration_cb, *file_duration_sb, *file_duration_om,
570                 *ringbuffer_nbf_cb, *ringbuffer_nbf_sb, *ringbuffer_nbf_lb,
571                 *stop_files_cb, *stop_files_sb, *stop_files_lb,
572
573                 *limit_fr, *limit_vb, *limit_tb,
574                 *stop_packets_cb, *stop_packets_sb, *stop_packets_lb,
575                 *stop_filesize_cb, *stop_filesize_sb, *stop_filesize_om,
576                 *stop_duration_cb, *stop_duration_sb, *stop_duration_om,
577
578                 *display_fr, *display_vb,
579                 *sync_cb, *auto_scroll_cb, *hide_info_cb,
580
581                 *resolv_fr, *resolv_vb,
582                 *m_resolv_cb, *n_resolv_cb, *t_resolv_cb,
583                 *bbox, *ok_bt, *cancel_bt,
584                 *help_bt;
585 #ifdef HAVE_AIRPCAP
586   GtkWidget     *advanced_hb, *advanced_bt;
587 #endif
588 #if GTK_MAJOR_VERSION < 2
589   GtkAccelGroup *accel_group;
590 #endif
591   GtkTooltips   *tooltips;
592   GtkAdjustment *snap_adj, *ringbuffer_nbf_adj,
593                 *stop_packets_adj, *stop_filesize_adj, *stop_duration_adj, *stop_files_adj, *ring_filesize_adj, *file_duration_adj;
594   GList         *if_list, *combo_list, *cfilter_list;
595   int           row;
596   int           err;
597   gchar         *err_str;
598 #ifdef _WIN32
599   GtkAdjustment *buffer_size_adj;
600   GtkWidget     *buffer_size_lb, *buffer_size_sb;
601 #endif
602   guint32       value;
603   gchar         *cap_title;
604   gchar         *if_device;
605
606 #ifdef HAVE_AIRPCAP
607   GtkWidget             *decryption_cm;
608 #endif
609
610   if (cap_open_w != NULL) {
611     /* There's already a "Capture Options" dialog box; reactivate it. */
612     reactivate_window(cap_open_w);
613     return;
614   }
615
616 #ifdef _WIN32
617   /* Is WPcap loaded? */
618   if (!has_wpcap) {
619     char *detailed_err;
620
621     detailed_err = cant_load_winpcap_err("Wireshark");
622     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", detailed_err);
623     g_free(detailed_err);
624     return;
625   }
626 #endif
627
628   if_list = get_interface_list(&err, &err_str);
629   if (if_list == NULL && err == CANT_GET_INTERFACE_LIST) {
630     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_str);
631     g_free(err_str);
632   }
633
634 #ifdef HAVE_AIRPCAP
635   /* update airpcap interface list */
636
637   /* load the airpcap interfaces */
638   airpcap_if_list = get_airpcap_interface_list(&err, &err_str);
639
640   decryption_cm = OBJECT_GET_DATA(airpcap_tb,AIRPCAP_TOOLBAR_DECRYPTION_KEY);
641   update_decryption_mode_list(decryption_cm);
642
643   if (airpcap_if_list == NULL && err == CANT_GET_AIRPCAP_INTERFACE_LIST) {
644     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_str);
645     g_free(err_str);
646   }
647
648         /* select the first ad default (THIS SHOULD BE CHANGED) */
649         airpcap_if_active = airpcap_get_default_if(airpcap_if_list);
650 #endif
651
652   /* use user-defined title if preference is set */
653   cap_title = create_user_window_title("Wireshark: Capture Options");
654
655   cap_open_w = dlg_window_new(cap_title);
656   g_free(cap_title);
657
658   tooltips = gtk_tooltips_new();
659
660 #if GTK_MAJOR_VERSION < 2
661   /* Accelerator group for the accelerators (or, as they're called in
662      Windows and, I think, in Motif, "mnemonics"; Alt+<key> is a mnemonic,
663      Ctrl+<key> is an accelerator). */
664   accel_group = gtk_accel_group_new();
665   gtk_window_add_accel_group(GTK_WINDOW(cap_open_w), accel_group);
666 #endif
667
668   main_vb = gtk_vbox_new(FALSE, 0);
669   gtk_container_border_width(GTK_CONTAINER(main_vb), 5);
670   gtk_container_add(GTK_CONTAINER(cap_open_w), main_vb);
671
672   /* Capture-related options frame */
673   capture_fr = gtk_frame_new("Capture");
674   gtk_container_add(GTK_CONTAINER(main_vb), capture_fr);
675
676   capture_vb = gtk_vbox_new(FALSE, 3);
677   gtk_container_border_width(GTK_CONTAINER(capture_vb), 5);
678   gtk_container_add(GTK_CONTAINER(capture_fr), capture_vb);
679
680   /* Interface row */
681   if_hb = gtk_hbox_new(FALSE, 3);
682   gtk_container_add(GTK_CONTAINER(capture_vb), if_hb);
683
684   if_lb = gtk_label_new("Interface:");
685   gtk_box_pack_start(GTK_BOX(if_hb), if_lb, FALSE, FALSE, 6);
686
687   if_cb = gtk_combo_new();
688   combo_list = build_capture_combo_list(if_list, TRUE);
689   if (combo_list != NULL)
690     gtk_combo_set_popdown_strings(GTK_COMBO(if_cb), combo_list);
691   if (capture_opts->iface == NULL && prefs.capture_device != NULL) {
692     /* No interface was specified on the command line or in a previous
693        capture, but there is one specified in the preferences file;
694        make the one from the preferences file the default */
695     if_device = g_strdup(prefs.capture_device);
696     capture_opts->iface = g_strdup(get_if_name(if_device));
697     g_free(if_device);
698   }
699
700 #ifdef HAVE_AIRPCAP
701         /* get the airpcap interface (if it IS an airpcap interface, and update the
702           toolbar... and of course enable the advanced button...)*/
703           airpcap_if_selected = get_airpcap_if_by_name(airpcap_if_list,capture_opts->iface);
704 #endif
705
706   if (capture_opts->iface != NULL) {
707     if_device = build_capture_combo_name(if_list, capture_opts->iface);
708     gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(if_cb)->entry), if_device);
709     g_free(if_device);
710   } else if (combo_list != NULL) {
711     gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(if_cb)->entry),
712                        (char *)combo_list->data);
713   }
714   free_capture_combo_list(combo_list);
715   free_interface_list(if_list);
716   gtk_tooltips_set_tip(tooltips, GTK_COMBO(if_cb)->entry,
717     "Choose which interface (network card) will be used to capture packets from. "
718     "Be sure to select the correct one, as it's a common mistake to select the wrong interface.", NULL);
719   gtk_box_pack_start(GTK_BOX(if_hb), if_cb, TRUE, TRUE, 6);
720
721   if_ip_hb = gtk_hbox_new(FALSE, 3);
722   gtk_box_pack_start(GTK_BOX(capture_vb), if_ip_hb, FALSE, FALSE, 0);
723
724   if_ip_eb = gtk_event_box_new();
725   gtk_box_pack_start(GTK_BOX(if_ip_hb), if_ip_eb, TRUE, TRUE, 6);
726   gtk_tooltips_set_tip(tooltips, if_ip_eb, "Lists the IP address(es) "
727                        "assigned to the selected interface.  If there are "
728                        "more addresses than will fit in the window, the "
729                        "first few and the last few will be shown with \"...\" "
730                        "between them.",
731                        NULL);
732
733   if_ip_lb = gtk_label_new("");
734   gtk_misc_set_alignment(GTK_MISC(if_ip_lb), 0, 0); /* Left justified */
735   gtk_container_add(GTK_CONTAINER(if_ip_eb), if_ip_lb);
736
737   /* Linktype row */
738   linktype_hb = gtk_hbox_new(FALSE, 3);
739   gtk_box_pack_start(GTK_BOX(capture_vb), linktype_hb, FALSE, FALSE, 0);
740
741   linktype_lb = gtk_label_new("Link-layer header type:");
742   gtk_box_pack_start(GTK_BOX(linktype_hb), linktype_lb, FALSE, FALSE, 6);
743
744   linktype_om = gtk_option_menu_new();
745   OBJECT_SET_DATA(linktype_om, E_CAP_LT_OM_LABEL_KEY, linktype_lb);
746   /* Default to "use the default" */
747   /* Datalink menu index is not resetted, it will be restored with last used value */
748   /* OBJECT_SET_DATA(linktype_om, E_CAP_OM_LT_VALUE_KEY, GINT_TO_POINTER(-1)); */
749   OBJECT_SET_DATA(linktype_om, E_CAP_IFACE_KEY, if_ip_lb);
750   dl_hdr_menu=NULL;
751   set_link_type_list(linktype_om, GTK_COMBO(if_cb)->entry);
752   /*
753    * XXX - in some cases, this is "multiple link-layer header types", e.g.
754    * some 802.11 interfaces on FreeBSD 5.2 and later, where you can request
755    * fake Ethernet, 802.11, or 802.11-plus-radio-information headers.
756    *
757    * In other cases, it's "multiple link-layer types", e.g., with recent
758    * versions of libpcap, a DAG card on an "HDLC" WAN, where you can
759    * request Cisco HDLC or PPP depending on what type of traffic is going
760    * over the WAN, or an Ethernet interface, where you can request Ethernet
761    * or DOCSIS, the latter being for some Cisco cable modem equipment that
762    * can be configured to send raw DOCSIS frames over an Ethernet inside
763    * Ethernet low-level framing, for traffic capture purposes.
764    *
765    * We leave it as "multiple link-layer types" for now.
766    */
767   gtk_tooltips_set_tip(tooltips, linktype_om,
768     "The selected interface supports multiple link-layer types; select the desired one.", NULL);
769   gtk_box_pack_start (GTK_BOX(linktype_hb), linktype_om, FALSE, FALSE, 0);
770   SIGNAL_CONNECT(GTK_ENTRY(GTK_COMBO(if_cb)->entry), "changed",
771                  capture_prep_interface_changed_cb, linktype_om);
772
773 #ifdef _WIN32
774   buffer_size_lb = gtk_label_new("Buffer size:");
775   gtk_box_pack_start (GTK_BOX(linktype_hb), buffer_size_lb, FALSE, FALSE, 0);
776
777   buffer_size_adj = (GtkAdjustment *) gtk_adjustment_new((gfloat) capture_opts->buffer_size,
778     1, 65535, 1.0, 10.0, 0.0);
779   buffer_size_sb = gtk_spin_button_new (buffer_size_adj, 0, 0);
780   gtk_spin_button_set_value(GTK_SPIN_BUTTON (buffer_size_sb), (gfloat) capture_opts->buffer_size);
781   gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (buffer_size_sb), TRUE);
782   WIDGET_SET_SIZE(buffer_size_sb, 80, -1);
783   gtk_tooltips_set_tip(tooltips, buffer_size_sb,
784     "The memory buffer size used while capturing. If you notice packet drops, you can try to increase this size.", NULL);
785   gtk_box_pack_start (GTK_BOX(linktype_hb), buffer_size_sb, FALSE, FALSE, 0);
786
787   buffer_size_lb = gtk_label_new("megabyte(s)");
788   gtk_box_pack_start (GTK_BOX(linktype_hb), buffer_size_lb, FALSE, FALSE, 6);
789 #endif
790
791   /* Promiscuous mode row */
792   promisc_cb = CHECK_BUTTON_NEW_WITH_MNEMONIC(
793       "Capture packets in _promiscuous mode", accel_group);
794   gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(promisc_cb),
795                 capture_opts->promisc_mode);
796   gtk_tooltips_set_tip(tooltips, promisc_cb,
797     "Usually a network card will only capture the traffic sent to its own network address. "
798     "If you want to capture all traffic that the network card can \"see\", mark this option. "
799     "See the FAQ for some more details of capturing packets from a switched network.", NULL);
800   gtk_container_add(GTK_CONTAINER(capture_vb), promisc_cb);
801
802   /* Capture length row */
803   snap_hb = gtk_hbox_new(FALSE, 3);
804   gtk_container_add(GTK_CONTAINER(capture_vb), snap_hb);
805
806   snap_cb = CHECK_BUTTON_NEW_WITH_MNEMONIC("_Limit each packet to", accel_group);
807   gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(snap_cb),
808                 capture_opts->has_snaplen);
809   SIGNAL_CONNECT(snap_cb, "toggled", capture_prep_adjust_sensitivity, cap_open_w);
810   gtk_tooltips_set_tip(tooltips, snap_cb,
811     "Limit the maximum number of bytes to be captured from each packet. This size includes the "
812     "link-layer header and all subsequent headers. ", NULL);
813   gtk_box_pack_start(GTK_BOX(snap_hb), snap_cb, FALSE, FALSE, 0);
814
815   snap_adj = (GtkAdjustment *) gtk_adjustment_new((gfloat) capture_opts->snaplen,
816     MIN_PACKET_SIZE, WTAP_MAX_PACKET_SIZE, 1.0, 10.0, 0.0);
817   snap_sb = gtk_spin_button_new (snap_adj, 0, 0);
818   gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (snap_sb), TRUE);
819   WIDGET_SET_SIZE(snap_sb, 80, -1);
820   gtk_box_pack_start (GTK_BOX(snap_hb), snap_sb, FALSE, FALSE, 0);
821
822   snap_lb = gtk_label_new("bytes");
823   gtk_misc_set_alignment(GTK_MISC(snap_lb), 0, 0.5);
824   gtk_box_pack_start(GTK_BOX(snap_hb), snap_lb, FALSE, FALSE, 0);
825
826   /* Filter row */
827   filter_hb = gtk_hbox_new(FALSE, 3);
828   gtk_box_pack_start(GTK_BOX(capture_vb), filter_hb, FALSE, FALSE, 0);
829
830   filter_bt = BUTTON_NEW_FROM_STOCK(WIRESHARK_STOCK_CAPTURE_FILTER_ENTRY);
831   SIGNAL_CONNECT(filter_bt, "clicked", capture_filter_construct_cb, NULL);
832   SIGNAL_CONNECT(filter_bt, "destroy", filter_button_destroy_cb, NULL);
833   gtk_tooltips_set_tip(tooltips, filter_bt,
834     "Select a capture filter to reduce the amount of packets to be captured. "
835     "See \"Capture Filters\" in the online help for further information how to use it.",
836     NULL);
837   gtk_box_pack_start(GTK_BOX(filter_hb), filter_bt, FALSE, FALSE, 3);
838
839   /* Create the capture filter combo */
840   filter_cm = gtk_combo_new();
841
842   cfilter_list = OBJECT_GET_DATA(top_level, E_CFILTER_FL_KEY);
843   gtk_combo_disable_activate(GTK_COMBO(filter_cm));
844   gtk_combo_set_case_sensitive(GTK_COMBO(filter_cm), TRUE);
845   OBJECT_SET_DATA(top_level, E_CFILTER_FL_KEY, cfilter_list);
846   OBJECT_SET_DATA(top_level, E_CFILTER_CM_KEY, filter_cm);
847   filter_te = GTK_COMBO(filter_cm)->entry;
848
849   if (cfilter_list != NULL)
850     gtk_combo_set_popdown_strings(GTK_COMBO(filter_cm), cfilter_list);
851   if (capture_opts->cfilter)
852     gtk_entry_set_text(GTK_ENTRY(filter_te), capture_opts->cfilter);
853   gtk_tooltips_set_tip(tooltips, filter_te,
854     "Enter a capture filter to reduce the amount of packets to be captured. "
855     "See \"Capture Filters\" in the online help for further information how to use it.",
856     NULL);
857   WIDGET_SET_SIZE(filter_cm, 400, -1);
858   gtk_box_pack_start(GTK_BOX(filter_hb), filter_cm, FALSE, FALSE, 3);
859   main_hb = gtk_hbox_new(FALSE, 5);
860   gtk_container_border_width(GTK_CONTAINER(main_hb), 0);
861   gtk_container_add(GTK_CONTAINER(main_vb), main_hb);
862
863   left_vb = gtk_vbox_new(FALSE, 0);
864   gtk_container_border_width(GTK_CONTAINER(left_vb), 0);
865   gtk_box_pack_start(GTK_BOX(main_hb), left_vb, TRUE, TRUE, 0);
866
867   right_vb = gtk_vbox_new(FALSE, 0);
868   gtk_container_border_width(GTK_CONTAINER(right_vb), 0);
869   gtk_box_pack_start(GTK_BOX(main_hb), right_vb, FALSE, FALSE, 0);
870
871   /* let an eventually capture filters dialog know the text entry to fill in */
872   OBJECT_SET_DATA(filter_bt, E_FILT_TE_PTR_KEY, filter_te);
873
874   /* advanced row */
875 #ifdef HAVE_AIRPCAP
876   advanced_hb = gtk_hbox_new(FALSE,5);
877   gtk_box_pack_start(GTK_BOX(capture_vb), advanced_hb, FALSE, FALSE, 0);
878
879   advanced_bt = gtk_button_new_with_label("Wireless Settings");
880
881   /* set the text */
882   #if GTK_MAJOR_VERSION >= 2
883   /* XXX - find a way to set the GtkButton label in GTK 2.x */
884   gtk_button_set_label(GTK_BUTTON(advanced_bt), "Wireless Settings");
885   #else
886   /* Set the GtkButton label in GTK 1.x */
887   gtk_label_set_text(GTK_LABEL(GTK_BIN(advanced_bt)->child), "Wireless Settings");
888   #endif
889
890   /* Both the callback and the data are global */
891   SIGNAL_CONNECT(advanced_bt,"clicked",options_airpcap_advanced_cb,airpcap_tb);
892   OBJECT_SET_DATA(GTK_ENTRY(GTK_COMBO(if_cb)->entry),AIRPCAP_OPTIONS_ADVANCED_KEY,advanced_bt);
893
894   if(airpcap_if_selected != NULL)
895         {
896         /* It is an airpcap interface */
897         gtk_widget_set_sensitive(advanced_bt,TRUE);
898         }
899   else
900         {
901         gtk_widget_set_sensitive(advanced_bt,FALSE);
902         }
903
904   gtk_box_pack_start(GTK_BOX(linktype_hb),advanced_bt,FALSE,FALSE,0);
905   gtk_widget_show(advanced_bt);
906   gtk_widget_show(advanced_hb);
907 #endif
908
909   /* Capture file-related options frame */
910   file_fr = gtk_frame_new("Capture File(s)");
911   gtk_container_add(GTK_CONTAINER(left_vb), file_fr);
912
913   file_vb = gtk_vbox_new(FALSE, 3);
914   gtk_container_border_width(GTK_CONTAINER(file_vb), 5);
915   gtk_container_add(GTK_CONTAINER(file_fr), file_vb);
916
917   /* File row */
918   file_hb = gtk_hbox_new(FALSE, 3);
919   gtk_box_pack_start(GTK_BOX(file_vb), file_hb, FALSE, FALSE, 0);
920
921   file_lb = gtk_label_new("File:");
922   gtk_box_pack_start(GTK_BOX(file_hb), file_lb, FALSE, FALSE, 3);
923
924   file_te = gtk_entry_new();
925   gtk_tooltips_set_tip(tooltips, file_te,
926     "Enter the file name to which captured data will be written. "
927     "If you don't enter something here, a temporary file will be used.",
928     NULL);
929   gtk_box_pack_start(GTK_BOX(file_hb), file_te, TRUE, TRUE, 3);
930
931   file_bt = BUTTON_NEW_FROM_STOCK(WIRESHARK_STOCK_BROWSE);
932   gtk_tooltips_set_tip(tooltips, file_bt,
933     "Select a file to which captured data will be written, "
934     "instead of entering the file name directly. ",
935     NULL);
936   gtk_box_pack_start(GTK_BOX(file_hb), file_bt, FALSE, FALSE, 3);
937
938   SIGNAL_CONNECT(file_bt, "clicked", capture_prep_file_cb, file_te);
939
940   /* multiple files table */
941   multi_tb = gtk_table_new(5, 3, FALSE);
942   gtk_table_set_row_spacings(GTK_TABLE(multi_tb), 1);
943   gtk_table_set_col_spacings(GTK_TABLE(multi_tb), 3);
944   gtk_box_pack_start(GTK_BOX(file_vb), multi_tb, FALSE, FALSE, 0);
945   row = 0;
946
947   /* multiple files row */
948   multi_files_on_cb = CHECK_BUTTON_NEW_WITH_MNEMONIC("Use _multiple files", accel_group);
949   gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(multi_files_on_cb),
950                 capture_opts->multi_files_on);
951   SIGNAL_CONNECT(multi_files_on_cb, "toggled", capture_prep_adjust_sensitivity,
952                  cap_open_w);
953   gtk_tooltips_set_tip(tooltips, multi_files_on_cb,
954     "Instead of using a single capture file, multiple files will be created. "
955     "The generated file names will contain an incrementing number and the start time of the capture.", NULL);
956   gtk_table_attach_defaults(GTK_TABLE(multi_tb), multi_files_on_cb, 0, 1, row, row+1);
957   row++;
958
959   /* Ring buffer filesize row */
960   ring_filesize_cb = gtk_check_button_new_with_label("Next file every");
961   gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(ring_filesize_cb),
962                 capture_opts->has_autostop_filesize);
963   SIGNAL_CONNECT(ring_filesize_cb, "toggled", capture_prep_adjust_sensitivity, cap_open_w);
964   gtk_tooltips_set_tip(tooltips, ring_filesize_cb,
965     "If the selected file size is exceeded, capturing switches to the next file.\n"
966     "PLEASE NOTE: at least one of the \"Next file every\" options MUST be selected.",
967     NULL);
968   gtk_table_attach_defaults(GTK_TABLE(multi_tb), ring_filesize_cb, 0, 1, row, row+1);
969
970   ring_filesize_adj = (GtkAdjustment *) gtk_adjustment_new(0.0,
971     1, (gfloat)INT_MAX, 1.0, 10.0, 0.0);
972   ring_filesize_sb = gtk_spin_button_new (ring_filesize_adj, 0, 0);
973   gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (ring_filesize_sb), TRUE);
974   WIDGET_SET_SIZE(ring_filesize_sb, 80, -1);
975   gtk_table_attach_defaults(GTK_TABLE(multi_tb), ring_filesize_sb, 1, 2, row, row+1);
976
977   ring_filesize_om = size_unit_option_menu_new(capture_opts->autostop_filesize);
978   gtk_table_attach_defaults(GTK_TABLE(multi_tb), ring_filesize_om, 2, 3, row, row+1);
979
980   value = size_unit_option_menu_set_value(capture_opts->autostop_filesize);
981   gtk_adjustment_set_value(ring_filesize_adj, (gfloat) value);
982
983   row++;
984
985   /* Ring buffer duration row */
986   file_duration_cb = gtk_check_button_new_with_label("Next file every");
987   gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(file_duration_cb),
988                               capture_opts->has_file_duration);
989   SIGNAL_CONNECT(file_duration_cb, "toggled",
990                  capture_prep_adjust_sensitivity, cap_open_w);
991   gtk_tooltips_set_tip(tooltips, file_duration_cb,
992     "If the selected duration is exceeded, capturing switches to the next file.\n"
993     "PLEASE NOTE: at least one of the \"Next file every\" options MUST be selected.",
994     NULL);
995   gtk_table_attach_defaults(GTK_TABLE(multi_tb), file_duration_cb, 0, 1, row, row+1);
996
997   file_duration_adj = (GtkAdjustment *)gtk_adjustment_new(0.0,
998     1, (gfloat)INT_MAX, 1.0, 10.0, 0.0);
999   file_duration_sb = gtk_spin_button_new (file_duration_adj, 0, 0);
1000   gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (file_duration_sb), TRUE);
1001   WIDGET_SET_SIZE(file_duration_sb, 80, -1);
1002   gtk_table_attach_defaults(GTK_TABLE(multi_tb), file_duration_sb, 1, 2, row, row+1);
1003
1004   file_duration_om = time_unit_option_menu_new(capture_opts->file_duration);
1005   gtk_table_attach_defaults(GTK_TABLE(multi_tb), file_duration_om, 2, 3, row, row+1);
1006
1007   value = time_unit_option_menu_convert_value(capture_opts->file_duration);
1008   gtk_adjustment_set_value(file_duration_adj, (gfloat) value);
1009   row++;
1010
1011   /* Ring buffer files row */
1012   ringbuffer_nbf_cb = gtk_check_button_new_with_label("Ring buffer with");
1013   gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(ringbuffer_nbf_cb),
1014                 capture_opts->has_ring_num_files);
1015   SIGNAL_CONNECT(ringbuffer_nbf_cb, "toggled", capture_prep_adjust_sensitivity, cap_open_w);
1016   gtk_tooltips_set_tip(tooltips, ringbuffer_nbf_cb,
1017     "After capturing has switched to the next file and the given number of files has exceeded, "
1018     "the oldest file will be removed.",
1019     NULL);
1020   gtk_table_attach_defaults(GTK_TABLE(multi_tb), ringbuffer_nbf_cb, 0, 1, row, row+1);
1021
1022   ringbuffer_nbf_adj = (GtkAdjustment *) gtk_adjustment_new((gfloat) capture_opts->ring_num_files,
1023     2/*RINGBUFFER_MIN_NUM_FILES*/, RINGBUFFER_MAX_NUM_FILES, 1.0, 10.0, 0.0);
1024   ringbuffer_nbf_sb = gtk_spin_button_new (ringbuffer_nbf_adj, 0, 0);
1025   gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (ringbuffer_nbf_sb), TRUE);
1026   WIDGET_SET_SIZE(ringbuffer_nbf_sb, 80, -1);
1027   SIGNAL_CONNECT(ringbuffer_nbf_sb, "changed", capture_prep_adjust_sensitivity, cap_open_w);
1028   gtk_table_attach_defaults(GTK_TABLE(multi_tb), ringbuffer_nbf_sb, 1, 2, row, row+1);
1029
1030   ringbuffer_nbf_lb = gtk_label_new("files");
1031   gtk_misc_set_alignment(GTK_MISC(ringbuffer_nbf_lb), 0, 0.5);
1032   gtk_table_attach_defaults(GTK_TABLE(multi_tb), ringbuffer_nbf_lb, 2, 3, row, row+1);
1033   row++;
1034
1035   /* Files row */
1036   stop_files_cb = gtk_check_button_new_with_label("Stop capture after");
1037   gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(stop_files_cb),
1038                 capture_opts->has_autostop_files);
1039   SIGNAL_CONNECT(stop_files_cb, "toggled", capture_prep_adjust_sensitivity, cap_open_w);
1040   gtk_tooltips_set_tip(tooltips, stop_files_cb,
1041     "Stop capturing after the given number of \"file switches\" have been done.", NULL);
1042   gtk_table_attach_defaults(GTK_TABLE(multi_tb), stop_files_cb, 0, 1, row, row+1);
1043
1044   stop_files_adj = (GtkAdjustment *) gtk_adjustment_new((gfloat)capture_opts->autostop_files,
1045     1, (gfloat)INT_MAX, 1.0, 10.0, 0.0);
1046   stop_files_sb = gtk_spin_button_new (stop_files_adj, 0, 0);
1047   gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (stop_files_sb), TRUE);
1048   WIDGET_SET_SIZE(stop_files_sb, 80, -1);
1049   gtk_table_attach_defaults(GTK_TABLE(multi_tb), stop_files_sb, 1, 2, row, row+1);
1050
1051   stop_files_lb = gtk_label_new("file(s)");
1052   gtk_misc_set_alignment(GTK_MISC(stop_files_lb), 0, 0.5);
1053   gtk_table_attach_defaults(GTK_TABLE(multi_tb), stop_files_lb, 2, 3, row, row+1);
1054   row++;
1055
1056   /* Capture limits frame */
1057   limit_fr = gtk_frame_new("Stop Capture ...");
1058   gtk_container_add(GTK_CONTAINER(left_vb), limit_fr);
1059
1060   limit_vb = gtk_vbox_new(FALSE, 3);
1061   gtk_container_border_width(GTK_CONTAINER(limit_vb), 5);
1062   gtk_container_add(GTK_CONTAINER(limit_fr), limit_vb);
1063
1064   /* limits table */
1065   limit_tb = gtk_table_new(3, 3, FALSE);
1066   gtk_table_set_row_spacings(GTK_TABLE(limit_tb), 1);
1067   gtk_table_set_col_spacings(GTK_TABLE(limit_tb), 3);
1068   gtk_box_pack_start(GTK_BOX(limit_vb), limit_tb, FALSE, FALSE, 0);
1069   row = 0;
1070
1071   /* Packet count row */
1072   stop_packets_cb = gtk_check_button_new_with_label("... after");
1073   gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(stop_packets_cb),
1074                 capture_opts->has_autostop_packets);
1075   SIGNAL_CONNECT(stop_packets_cb, "toggled", capture_prep_adjust_sensitivity, cap_open_w);
1076   gtk_tooltips_set_tip(tooltips, stop_packets_cb,
1077     "Stop capturing after the given number of packets have been captured.", NULL);
1078   gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_packets_cb, 0, 1, row, row+1);
1079
1080   stop_packets_adj = (GtkAdjustment *) gtk_adjustment_new((gfloat)capture_opts->autostop_packets,
1081     1, (gfloat)INT_MAX, 1.0, 10.0, 0.0);
1082   stop_packets_sb = gtk_spin_button_new (stop_packets_adj, 0, 0);
1083   gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (stop_packets_sb), TRUE);
1084   WIDGET_SET_SIZE(stop_packets_sb, 80, -1);
1085   gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_packets_sb, 1, 2, row, row+1);
1086
1087   stop_packets_lb = gtk_label_new("packet(s)");
1088   gtk_misc_set_alignment(GTK_MISC(stop_packets_lb), 0, 0.5);
1089   gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_packets_lb, 2, 3, row, row+1);
1090   row++;
1091
1092   /* Filesize row */
1093   stop_filesize_cb = gtk_check_button_new_with_label("... after");
1094   gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(stop_filesize_cb),
1095                 capture_opts->has_autostop_filesize);
1096   SIGNAL_CONNECT(stop_filesize_cb, "toggled", capture_prep_adjust_sensitivity, cap_open_w);
1097   gtk_tooltips_set_tip(tooltips, stop_filesize_cb,
1098     "Stop capturing after the given amount of capture data has been captured.", NULL);
1099   gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_filesize_cb, 0, 1, row, row+1);
1100
1101   stop_filesize_adj = (GtkAdjustment *) gtk_adjustment_new(0.0,
1102     1, (gfloat)INT_MAX, 1.0, 10.0, 0.0);
1103   stop_filesize_sb = gtk_spin_button_new (stop_filesize_adj, 0, 0);
1104   gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (stop_filesize_sb), TRUE);
1105   WIDGET_SET_SIZE(stop_filesize_sb, 80, -1);
1106   gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_filesize_sb, 1, 2, row, row+1);
1107
1108   stop_filesize_om = size_unit_option_menu_new(capture_opts->autostop_filesize);
1109   gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_filesize_om, 2, 3, row, row+1);
1110
1111   value = size_unit_option_menu_set_value(capture_opts->autostop_filesize);
1112   gtk_adjustment_set_value(stop_filesize_adj, (gfloat) value);
1113
1114   row++;
1115
1116   /* Duration row */
1117   stop_duration_cb = gtk_check_button_new_with_label("... after");
1118   gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(stop_duration_cb),
1119                 capture_opts->has_autostop_duration);
1120   SIGNAL_CONNECT(stop_duration_cb, "toggled", capture_prep_adjust_sensitivity, cap_open_w);
1121   gtk_tooltips_set_tip(tooltips, stop_duration_cb,
1122     "Stop capturing after the given time is exceeded.", NULL);
1123   gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_duration_cb, 0, 1, row, row+1);
1124
1125   stop_duration_adj = (GtkAdjustment *) gtk_adjustment_new(0.0,
1126     1, (gfloat)INT_MAX, 1.0, 10.0, 0.0);
1127   stop_duration_sb = gtk_spin_button_new (stop_duration_adj, 0, 0);
1128   gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (stop_duration_sb), TRUE);
1129   WIDGET_SET_SIZE(stop_duration_sb, 80, -1);
1130   gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_duration_sb, 1, 2, row, row+1);
1131
1132   stop_duration_om = time_unit_option_menu_new(capture_opts->autostop_duration);
1133   gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_duration_om, 2, 3, row, row+1);
1134
1135   value = time_unit_option_menu_convert_value(capture_opts->autostop_duration);
1136   gtk_adjustment_set_value(stop_duration_adj, (gfloat) value);
1137   row++;
1138
1139   /* Display-related options frame */
1140   display_fr = gtk_frame_new("Display Options");
1141   gtk_container_add(GTK_CONTAINER(right_vb), display_fr);
1142
1143   display_vb = gtk_vbox_new(FALSE, 0);
1144   gtk_container_border_width(GTK_CONTAINER(display_vb), 5);
1145   gtk_container_add(GTK_CONTAINER(display_fr), display_vb);
1146
1147   /* "Update display in real time" row */
1148   sync_cb = CHECK_BUTTON_NEW_WITH_MNEMONIC(
1149       "_Update list of packets in real time", accel_group);
1150   gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(sync_cb),
1151                 capture_opts->real_time_mode);
1152   SIGNAL_CONNECT(sync_cb, "toggled", capture_prep_adjust_sensitivity, cap_open_w);
1153   gtk_tooltips_set_tip(tooltips, sync_cb,
1154     "Using this option will show the captured packets immediately on the main screen. "
1155     "Please note: this will slow down capturing, so increased packet drops might appear.", NULL);
1156   gtk_container_add(GTK_CONTAINER(display_vb), sync_cb);
1157
1158   /* "Auto-scroll live update" row */
1159   auto_scroll_cb = CHECK_BUTTON_NEW_WITH_MNEMONIC(
1160                 "_Automatic scrolling in live capture", accel_group);
1161   gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(auto_scroll_cb), auto_scroll_live);
1162   gtk_tooltips_set_tip(tooltips, auto_scroll_cb,
1163     "This will scroll the \"Packet List\" automatically to the latest captured packet, "
1164     "when the \"Update List of packets in real time\" option is used.", NULL);
1165   gtk_container_add(GTK_CONTAINER(display_vb), auto_scroll_cb);
1166
1167   /* "Hide capture info" row */
1168   hide_info_cb = CHECK_BUTTON_NEW_WITH_MNEMONIC(
1169                 "_Hide capture info dialog", accel_group);
1170   gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(hide_info_cb), !capture_opts->show_info);
1171   gtk_tooltips_set_tip(tooltips, hide_info_cb,
1172     "Hide the capture info dialog while capturing.", NULL);
1173   gtk_container_add(GTK_CONTAINER(display_vb), hide_info_cb);
1174
1175   /* Name Resolution frame */
1176   resolv_fr = gtk_frame_new("Name Resolution");
1177   gtk_container_add(GTK_CONTAINER(right_vb), resolv_fr);
1178
1179   resolv_vb = gtk_vbox_new(FALSE, 0);
1180   gtk_container_border_width(GTK_CONTAINER(resolv_vb), 5);
1181   gtk_container_add(GTK_CONTAINER(resolv_fr), resolv_vb);
1182
1183   m_resolv_cb = CHECK_BUTTON_NEW_WITH_MNEMONIC(
1184                 "Enable _MAC name resolution", accel_group);
1185   gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(m_resolv_cb),
1186                 g_resolv_flags & RESOLV_MAC);
1187   gtk_tooltips_set_tip(tooltips, m_resolv_cb,
1188     "Perform MAC layer name resolution while capturing.", NULL);
1189   gtk_container_add(GTK_CONTAINER(resolv_vb), m_resolv_cb);
1190
1191   n_resolv_cb = CHECK_BUTTON_NEW_WITH_MNEMONIC(
1192                 "Enable _network name resolution", accel_group);
1193   gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(n_resolv_cb),
1194                 g_resolv_flags & RESOLV_NETWORK);
1195   gtk_tooltips_set_tip(tooltips, n_resolv_cb,
1196     "Perform network layer name resolution while capturing.", NULL);
1197   gtk_container_add(GTK_CONTAINER(resolv_vb), n_resolv_cb);
1198
1199   t_resolv_cb = CHECK_BUTTON_NEW_WITH_MNEMONIC(
1200                 "Enable _transport name resolution", accel_group);
1201   gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(t_resolv_cb),
1202                 g_resolv_flags & RESOLV_TRANSPORT);
1203   gtk_tooltips_set_tip(tooltips, t_resolv_cb,
1204     "Perform transport layer name resolution while capturing.", NULL);
1205   gtk_container_add(GTK_CONTAINER(resolv_vb), t_resolv_cb);
1206
1207   /* Button row: "Start" and "Cancel" buttons */
1208   bbox = dlg_button_row_new(WIRESHARK_STOCK_CAPTURE_START, GTK_STOCK_CANCEL, GTK_STOCK_HELP, NULL);
1209   gtk_box_pack_start(GTK_BOX(main_vb), bbox, FALSE, FALSE, 5);
1210
1211   ok_bt = OBJECT_GET_DATA(bbox, WIRESHARK_STOCK_CAPTURE_START);
1212   SIGNAL_CONNECT(ok_bt, "clicked", capture_start_cb, cap_open_w);
1213   gtk_tooltips_set_tip(tooltips, ok_bt,
1214     "Start the capture process.", NULL);
1215
1216   cancel_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_CANCEL);
1217   gtk_tooltips_set_tip(tooltips, cancel_bt,
1218     "Cancel and exit dialog.", NULL);
1219   window_set_cancel_button(cap_open_w, cancel_bt, window_cancel_button_cb);
1220
1221   help_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_HELP);
1222   gtk_tooltips_set_tip(tooltips, help_bt,
1223     "Show help about capturing.", NULL);
1224   SIGNAL_CONNECT(help_bt, "clicked", topic_cb, HELP_CAPTURE_OPTIONS_DIALOG);
1225
1226   gtk_widget_grab_default(ok_bt);
1227
1228   /* Attach pointers to needed widgets to the capture prefs window/object */
1229   OBJECT_SET_DATA(cap_open_w, E_CAP_IFACE_KEY, if_cb);
1230   OBJECT_SET_DATA(cap_open_w, E_CAP_SNAP_CB_KEY, snap_cb);
1231   OBJECT_SET_DATA(cap_open_w, E_CAP_SNAP_SB_KEY, snap_sb);
1232   OBJECT_SET_DATA(cap_open_w, E_CAP_LT_OM_KEY, linktype_om);
1233 #ifdef _WIN32
1234   OBJECT_SET_DATA(cap_open_w, E_CAP_BUFFER_SIZE_SB_KEY, buffer_size_sb);
1235 #endif
1236   OBJECT_SET_DATA(cap_open_w, E_CAP_PROMISC_KEY, promisc_cb);
1237   OBJECT_SET_DATA(cap_open_w, E_CAP_FILT_KEY,  filter_te);
1238   OBJECT_SET_DATA(cap_open_w, E_CAP_FILE_TE_KEY,  file_te);
1239   OBJECT_SET_DATA(cap_open_w, E_CAP_MULTI_FILES_ON_CB_KEY,  multi_files_on_cb);
1240   OBJECT_SET_DATA(cap_open_w, E_CAP_RING_NBF_CB_KEY,  ringbuffer_nbf_cb);
1241   OBJECT_SET_DATA(cap_open_w, E_CAP_RING_NBF_SB_KEY,  ringbuffer_nbf_sb);
1242   OBJECT_SET_DATA(cap_open_w, E_CAP_RING_NBF_LB_KEY,  ringbuffer_nbf_lb);
1243   OBJECT_SET_DATA(cap_open_w, E_CAP_RING_FILESIZE_CB_KEY,  ring_filesize_cb);
1244   OBJECT_SET_DATA(cap_open_w, E_CAP_RING_FILESIZE_SB_KEY,  ring_filesize_sb);
1245   OBJECT_SET_DATA(cap_open_w, E_CAP_RING_FILESIZE_OM_KEY,  ring_filesize_om);
1246   OBJECT_SET_DATA(cap_open_w, E_CAP_FILE_DURATION_CB_KEY,  file_duration_cb);
1247   OBJECT_SET_DATA(cap_open_w, E_CAP_FILE_DURATION_SB_KEY,  file_duration_sb);
1248   OBJECT_SET_DATA(cap_open_w, E_CAP_FILE_DURATION_OM_KEY,  file_duration_om);
1249   OBJECT_SET_DATA(cap_open_w, E_CAP_SYNC_KEY,  sync_cb);
1250   OBJECT_SET_DATA(cap_open_w, E_CAP_AUTO_SCROLL_KEY, auto_scroll_cb);
1251   OBJECT_SET_DATA(cap_open_w, E_CAP_HIDE_INFO_KEY, hide_info_cb);
1252   OBJECT_SET_DATA(cap_open_w, E_CAP_STOP_PACKETS_CB_KEY, stop_packets_cb);
1253   OBJECT_SET_DATA(cap_open_w, E_CAP_STOP_PACKETS_SB_KEY, stop_packets_sb);
1254   OBJECT_SET_DATA(cap_open_w, E_CAP_STOP_PACKETS_LB_KEY, stop_packets_lb);
1255   OBJECT_SET_DATA(cap_open_w, E_CAP_STOP_FILESIZE_CB_KEY, stop_filesize_cb);
1256   OBJECT_SET_DATA(cap_open_w, E_CAP_STOP_FILESIZE_SB_KEY, stop_filesize_sb);
1257   OBJECT_SET_DATA(cap_open_w, E_CAP_STOP_FILESIZE_OM_KEY, stop_filesize_om);
1258   OBJECT_SET_DATA(cap_open_w, E_CAP_STOP_DURATION_CB_KEY,  stop_duration_cb);
1259   OBJECT_SET_DATA(cap_open_w, E_CAP_STOP_DURATION_SB_KEY,  stop_duration_sb);
1260   OBJECT_SET_DATA(cap_open_w, E_CAP_STOP_DURATION_OM_KEY,  stop_duration_om);
1261   OBJECT_SET_DATA(cap_open_w, E_CAP_STOP_FILES_CB_KEY, stop_files_cb);
1262   OBJECT_SET_DATA(cap_open_w, E_CAP_STOP_FILES_SB_KEY, stop_files_sb);
1263   OBJECT_SET_DATA(cap_open_w, E_CAP_STOP_FILES_LB_KEY, stop_files_lb);
1264   OBJECT_SET_DATA(cap_open_w, E_CAP_M_RESOLVE_KEY,  m_resolv_cb);
1265   OBJECT_SET_DATA(cap_open_w, E_CAP_N_RESOLVE_KEY,  n_resolv_cb);
1266   OBJECT_SET_DATA(cap_open_w, E_CAP_T_RESOLVE_KEY,  t_resolv_cb);
1267
1268   /* Set the sensitivity of various widgets as per the settings of other
1269      widgets. */
1270   capture_prep_adjust_sensitivity(NULL, cap_open_w);
1271
1272   /* Catch the "activate" signal on the text
1273      entries, so that if the user types Return there, we act as if the
1274      "OK" button had been selected, as happens if Return is typed if some
1275      widget that *doesn't* handle the Return key has the input focus. */
1276   dlg_set_activate(GTK_COMBO(if_cb)->entry, ok_bt);
1277   dlg_set_activate(filter_te, ok_bt);
1278   dlg_set_activate(file_te, ok_bt);
1279
1280   /* XXX - why does not
1281
1282      gtk_widget_grab_focus(if_cb);
1283
1284     give the initial focus to the "Interface" combo box?
1285
1286     Or should I phrase that as "why does GTK+ continually frustrate
1287     attempts to make GUIs driveable from the keyboard?"  We have to
1288     go catch the activate signal on every single GtkEntry widget
1289     (rather than having widgets whose activate signal is *not*
1290     caught not catch the Return keystroke, so that it passes on,
1291     ultimately, to the window, which can activate the default
1292     widget, i.e. the "OK" button); we have to catch the "key_press_event"
1293     signal and have the handler check for ESC, so that we can have ESC
1294     activate the "Cancel" button; in order to support Alt+<key> mnemonics
1295     for buttons and the like, we may have to construct an accelerator
1296     group by hand and set up the accelerators by hand (if that even
1297     works - I've not tried it yet); we have to do a "gtk_widget_grab_focus()"
1298     to keep some container widget from getting the initial focus, so that
1299     you don't have to tab into the first widget in order to start typing
1300     in it; and it now appears that you simply *can't* make a combo box
1301     get the initial focus, at least not in the obvious fashion. Sigh.... */
1302
1303   SIGNAL_CONNECT(cap_open_w, "delete_event", window_delete_event_cb, NULL);
1304   SIGNAL_CONNECT(cap_open_w, "destroy", capture_prep_destroy_cb, NULL);
1305
1306   /* Give the initial focus to the "Filter" entry box. */
1307   gtk_widget_grab_focus(filter_te);
1308
1309   gtk_widget_show_all(cap_open_w);
1310   window_present(cap_open_w);
1311 }
1312
1313 /* everythings prepared, now it's really time to start the capture */
1314 void
1315 capture_start_confirmed(void) {
1316
1317
1318     /* init iface, if never used before */
1319     /* XXX - would better be doing this in main.c */
1320     if(capture_opts->iface == NULL) {
1321         gchar *if_device;
1322         const gchar *if_name;
1323
1324         /* did the user ever selected a capture interface before? */
1325         if(prefs.capture_device == NULL) {
1326             simple_dialog(ESD_TYPE_CONFIRMATION,
1327                         ESD_BTN_OK,
1328                         PRIMARY_TEXT_START "No capture interface selected!" PRIMARY_TEXT_END "\n\n"
1329                         "To select an interface use:\n\n"
1330                         "Capture->Options (until Wireshark is stopped)\n"
1331                         "Edit->Preferences/Capture (permanent, if saved)");
1332             return;
1333         }
1334         if_device = g_strdup(prefs.capture_device);
1335         if_name = get_if_name(if_device);
1336         capture_opts->iface = g_strdup(if_name);
1337
1338         g_free(if_device);
1339     }
1340
1341     /* XXX - we might need to init other pref data as well... */
1342     menu_auto_scroll_live_changed(auto_scroll_live);
1343
1344     if (capture_start(capture_opts)) {
1345         /* The capture succeeded, which means the capture filter syntax is
1346         valid; add this capture filter to the recent capture filter list. */
1347         cfilter_combo_add_recent(capture_opts->cfilter);
1348     }
1349 }
1350
1351 /* user confirmed the "Save capture file..." dialog */
1352 static void
1353 capture_start_answered_cb(gpointer dialog _U_, gint btn, gpointer data)
1354 {
1355     switch(btn) {
1356     case(ESD_BTN_SAVE):
1357         /* save file first */
1358         file_save_as_cmd(after_save_capture_dialog, data);
1359         break;
1360     case(ESD_BTN_DONT_SAVE):
1361         /* XXX - unlink old file? */
1362         /* start the capture */
1363         capture_start_confirmed();
1364         break;
1365     case(ESD_BTN_CANCEL):
1366         break;
1367     default:
1368         g_assert_not_reached();
1369     }
1370 }
1371
1372 /* user pressed the "Start" button (in dialog or toolbar) */
1373 void
1374 capture_start_cb(GtkWidget *w _U_, gpointer d _U_)
1375 {
1376   gpointer  dialog;
1377
1378 #ifdef HAVE_AIRPCAP
1379   airpcap_if_active = airpcap_if_selected;
1380   airpcap_set_toolbar_start_capture(airpcap_if_active);
1381 #endif
1382
1383 #ifdef _WIN32
1384   /* Is WPcap loaded? */
1385   if (!has_wpcap) {
1386       char * err_msg = cant_load_winpcap_err("Wireshark");
1387
1388           simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
1389           err_msg);
1390       g_free(err_msg);
1391           return;
1392   }
1393 #endif
1394
1395   /* get the values and close the options dialog */
1396   if(cap_open_w) {
1397     capture_dlg_prep(cap_open_w);
1398     window_destroy(GTK_WIDGET(cap_open_w));
1399   }
1400
1401   if((cfile.state != FILE_CLOSED) && !cfile.user_saved && prefs.gui_ask_unsaved) {
1402     /* user didn't saved his current file, ask him */
1403     dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_SAVE_DONTSAVE_CANCEL,
1404                 PRIMARY_TEXT_START "Save capture file before starting a new capture?" PRIMARY_TEXT_END "\n\n"
1405                 "If you start a new capture without saving, your current capture data will\nbe discarded.");
1406     simple_dialog_set_cb(dialog, capture_start_answered_cb, NULL);
1407   } else {
1408     /* unchanged file, just capture a new one */
1409     capture_start_confirmed();
1410   }
1411 }
1412
1413 /* user selected a link type, convert to internal value */
1414 static void
1415 select_link_type_cb(GtkWidget *w, gpointer data)
1416 {
1417   int new_linktype = GPOINTER_TO_INT(data);
1418   GtkWidget *linktype_om = OBJECT_GET_DATA(w, E_CAP_LT_OM_KEY);
1419   int old_linktype = GPOINTER_TO_INT(OBJECT_GET_DATA(linktype_om, E_CAP_OM_LT_VALUE_KEY));
1420
1421   /* If the link is changed, update the menu and store the index and the value
1422      to reuse later when the dialog window will be reopened */
1423   if (old_linktype != new_linktype) {
1424     OBJECT_SET_DATA(linktype_om, E_CAP_OM_LT_VALUE_KEY, GINT_TO_POINTER(new_linktype));
1425     capture_opts->linktype = GPOINTER_TO_INT(OBJECT_GET_DATA(linktype_om, E_CAP_OM_LT_VALUE_KEY));
1426 #if GTK_MAJOR_VERSION >= 2
1427     linktype_history=MAX(gtk_option_menu_get_history(GTK_OPTION_MENU(linktype_om)), 0);
1428 #endif
1429
1430   }
1431  }
1432
1433 /* user pressed "File" button */
1434 static void
1435 capture_prep_file_cb(GtkWidget *file_bt, GtkWidget *file_te)
1436 {
1437     file_selection_browse(file_bt, file_te, "Wireshark: Specify a Capture File", FILE_SELECTION_WRITE_BROWSE);
1438 }
1439
1440
1441 /* convert dialog settings into capture_opts values */
1442 static void
1443 capture_dlg_prep(gpointer parent_w) {
1444   GtkWidget *if_cb, *snap_cb, *snap_sb, *promisc_cb, *filter_te, *filter_cm,
1445             *file_te, *multi_files_on_cb, *ringbuffer_nbf_sb, *ringbuffer_nbf_cb,
1446             *linktype_om, *sync_cb, *auto_scroll_cb, *hide_info_cb,
1447             *stop_packets_cb, *stop_packets_sb,
1448             *stop_filesize_cb, *stop_filesize_sb, *stop_filesize_om,
1449             *stop_duration_cb, *stop_duration_sb, *stop_duration_om,
1450             *ring_filesize_cb, *ring_filesize_sb, *ring_filesize_om,
1451             *file_duration_cb, *file_duration_sb, *file_duration_om,
1452             *stop_files_cb, *stop_files_sb,
1453             *m_resolv_cb, *n_resolv_cb, *t_resolv_cb;
1454 #ifdef _WIN32
1455   GtkWidget *buffer_size_sb;
1456 #endif
1457   gchar *entry_text;
1458   gchar *if_text;
1459   const gchar *if_name;
1460   const gchar *filter_text;
1461   const gchar *g_save_file;
1462   gchar *cf_name;
1463   gchar *dirname;
1464   gint32 tmp;
1465
1466   if_cb     = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_IFACE_KEY);
1467   snap_cb   = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_SNAP_CB_KEY);
1468   snap_sb   = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_SNAP_SB_KEY);
1469   linktype_om = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_LT_OM_KEY);
1470 #ifdef _WIN32
1471   buffer_size_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_BUFFER_SIZE_SB_KEY);
1472 #endif
1473   promisc_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_PROMISC_KEY);
1474   filter_cm = OBJECT_GET_DATA(top_level, E_CFILTER_CM_KEY);
1475   filter_te = GTK_COMBO(filter_cm)->entry;
1476   file_te   = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_FILE_TE_KEY);
1477   multi_files_on_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_MULTI_FILES_ON_CB_KEY);
1478   ringbuffer_nbf_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_RING_NBF_CB_KEY);
1479   ringbuffer_nbf_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_RING_NBF_SB_KEY);
1480   ring_filesize_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_RING_FILESIZE_CB_KEY);
1481   ring_filesize_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_RING_FILESIZE_SB_KEY);
1482   ring_filesize_om = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_RING_FILESIZE_OM_KEY);
1483   file_duration_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_FILE_DURATION_CB_KEY);
1484   file_duration_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_FILE_DURATION_SB_KEY);
1485   file_duration_om = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_FILE_DURATION_OM_KEY);
1486   sync_cb   = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_SYNC_KEY);
1487   auto_scroll_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_AUTO_SCROLL_KEY);
1488   hide_info_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_HIDE_INFO_KEY);
1489   stop_packets_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_PACKETS_CB_KEY);
1490   stop_packets_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_PACKETS_SB_KEY);
1491   stop_filesize_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_FILESIZE_CB_KEY);
1492   stop_filesize_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_FILESIZE_SB_KEY);
1493   stop_filesize_om = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_FILESIZE_OM_KEY);
1494   stop_duration_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_DURATION_CB_KEY);
1495   stop_duration_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_DURATION_SB_KEY);
1496   stop_duration_om = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_DURATION_OM_KEY);
1497   stop_files_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_FILES_CB_KEY);
1498   stop_files_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_FILES_SB_KEY);
1499   m_resolv_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_M_RESOLVE_KEY);
1500   n_resolv_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_N_RESOLVE_KEY);
1501   t_resolv_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_T_RESOLVE_KEY);
1502
1503   entry_text =
1504     g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(if_cb)->entry)));
1505   if_text = g_strstrip(entry_text);
1506   if_name = get_if_name(if_text);
1507   if (*if_name == '\0') {
1508     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
1509       "You didn't specify an interface on which to capture packets.");
1510     g_free(entry_text);
1511     return;
1512   }
1513   if (capture_opts->iface)
1514     g_free(capture_opts->iface);
1515   capture_opts->iface = g_strdup(if_name);
1516   g_free(entry_text);
1517   /* The Linktype will be stored when the interface will be changed, or if not, not datalink option is used,
1518      the acquisition will be performed on the default datalink for the device */
1519   /*  capture_opts->linktype =
1520       GPOINTER_TO_INT(OBJECT_GET_DATA(linktype_om, E_CAP_OM_LT_VALUE_KEY)); */
1521
1522 #ifdef _WIN32
1523   capture_opts->buffer_size =
1524     gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(buffer_size_sb));
1525 #endif
1526
1527   capture_opts->has_snaplen =
1528     gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(snap_cb));
1529   if (capture_opts->has_snaplen) {
1530     capture_opts->snaplen =
1531       gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(snap_sb));
1532     if (capture_opts->snaplen < 1)
1533       capture_opts->snaplen = WTAP_MAX_PACKET_SIZE;
1534     else if (capture_opts->snaplen < MIN_PACKET_SIZE)
1535       capture_opts->snaplen = MIN_PACKET_SIZE;
1536   }
1537
1538   capture_opts->promisc_mode =
1539     gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(promisc_cb));
1540
1541   /* XXX - don't try to get clever and set "cfile.filter" to NULL if the
1542      filter string is empty, as an indication that we don't have a filter
1543      and thus don't have to set a filter when capturing - the version of
1544      libpcap in Red Hat Linux 6.1, and versions based on later patches
1545      in that series, don't bind the AF_PACKET socket to an interface
1546      until a filter is set, which means they aren't bound at all if
1547      no filter is set, which means no packets arrive as input on that
1548      socket, which means Wireshark never sees any packets. */
1549   filter_text = gtk_entry_get_text(GTK_ENTRY(filter_te));
1550   if (capture_opts->cfilter)
1551     g_free(capture_opts->cfilter);
1552   g_assert(filter_text != NULL);
1553   capture_opts->cfilter = g_strdup(filter_text);
1554
1555   /* Wireshark always saves to a capture file. */
1556   capture_opts->saving_to_file = TRUE;
1557   g_save_file = gtk_entry_get_text(GTK_ENTRY(file_te));
1558   if (g_save_file && g_save_file[0]) {
1559     /* User specified a file to which the capture should be written. */
1560     capture_opts->save_file = g_strdup(g_save_file);
1561     /* Save the directory name for future file dialogs. */
1562     cf_name = g_strdup(g_save_file);
1563     dirname = get_dirname(cf_name);  /* Overwrites cf_name */
1564     set_last_open_dir(dirname);
1565     g_free(cf_name);
1566   } else {
1567     /* User didn't specify a file; save to a temporary file. */
1568     capture_opts->save_file = NULL;
1569   }
1570
1571   capture_opts->has_autostop_packets =
1572     gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_packets_cb));
1573   if (capture_opts->has_autostop_packets)
1574     capture_opts->autostop_packets =
1575       gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(stop_packets_sb));
1576
1577   capture_opts->has_autostop_duration =
1578     gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_duration_cb));
1579   if (capture_opts->has_autostop_duration) {
1580     capture_opts->autostop_duration =
1581       gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(stop_duration_sb));
1582     capture_opts->autostop_duration =
1583       time_unit_option_menu_get_value(stop_duration_om, capture_opts->autostop_duration);
1584   }
1585
1586   capture_opts->real_time_mode =
1587     gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(sync_cb));
1588
1589   auto_scroll_live =
1590       gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(auto_scroll_cb));
1591
1592   capture_opts->show_info =
1593       !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(hide_info_cb));
1594
1595   if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m_resolv_cb)))
1596     g_resolv_flags |= RESOLV_MAC;
1597   else
1598     g_resolv_flags &= ~RESOLV_MAC;
1599   if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(n_resolv_cb)))
1600     g_resolv_flags |= RESOLV_NETWORK;
1601   else
1602     g_resolv_flags &= ~RESOLV_NETWORK;
1603   if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t_resolv_cb)))
1604     g_resolv_flags |= RESOLV_TRANSPORT;
1605   else
1606     g_resolv_flags &= ~RESOLV_TRANSPORT;
1607
1608   capture_opts->has_ring_num_files =
1609     gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ringbuffer_nbf_cb));
1610
1611   capture_opts->ring_num_files =
1612     gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(ringbuffer_nbf_sb));
1613   if (capture_opts->ring_num_files > RINGBUFFER_MAX_NUM_FILES)
1614     capture_opts->ring_num_files = RINGBUFFER_MAX_NUM_FILES;
1615 #if RINGBUFFER_MIN_NUM_FILES > 0
1616   else if (capture_opts->ring_num_files < RINGBUFFER_MIN_NUM_FILES)
1617     capture_opts->ring_num_files = RINGBUFFER_MIN_NUM_FILES;
1618 #endif
1619
1620   capture_opts->multi_files_on =
1621     gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(multi_files_on_cb));
1622
1623   capture_opts->has_file_duration =
1624     gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(file_duration_cb));
1625   if (capture_opts->has_file_duration) {
1626     capture_opts->file_duration =
1627       gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(file_duration_sb));
1628     capture_opts->file_duration =
1629       time_unit_option_menu_get_value(file_duration_om, capture_opts->file_duration);
1630   }
1631
1632   capture_opts->has_autostop_files =
1633     gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_files_cb));
1634   if (capture_opts->has_autostop_files)
1635     capture_opts->autostop_files =
1636       gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(stop_files_sb));
1637
1638   if (capture_opts->multi_files_on) {
1639     capture_opts->has_autostop_filesize =
1640       gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ring_filesize_cb));
1641     if (capture_opts->has_autostop_filesize) {
1642       tmp = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(ring_filesize_sb));
1643       tmp = size_unit_option_menu_convert_value(ring_filesize_om, tmp);
1644       if(tmp != 0) {
1645         capture_opts->autostop_filesize = tmp;
1646       } else {
1647         simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
1648           PRIMARY_TEXT_START "Multiple files: Requested filesize too large!\n\n" PRIMARY_TEXT_END
1649           "The setting \"Next file every x byte(s)\" can't be greater than %u bytes (2GB).", G_MAXINT);
1650         return;
1651       }
1652     }
1653
1654     /* test if the settings are ok for a ringbuffer */
1655     if (capture_opts->save_file == NULL) {
1656       simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
1657         PRIMARY_TEXT_START "Multiple files: No capture file name given!\n\n" PRIMARY_TEXT_END
1658         "You must specify a filename if you want to use multiple files.");
1659       return;
1660     } else if (!capture_opts->has_autostop_filesize && !capture_opts->has_file_duration) {
1661       simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
1662         PRIMARY_TEXT_START "Multiple files: No file limit given!\n\n" PRIMARY_TEXT_END
1663         "You must specify a file size or duration at which is switched to the next capture file\n"
1664         "if you want to use multiple files.");
1665       g_free(capture_opts->save_file);
1666       capture_opts->save_file = NULL;
1667       return;
1668     }
1669   } else {
1670     capture_opts->has_autostop_filesize =
1671       gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_filesize_cb));
1672     if (capture_opts->has_autostop_filesize) {
1673       tmp = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(stop_filesize_sb));
1674       tmp = size_unit_option_menu_convert_value(stop_filesize_om, tmp);
1675       if(tmp != 0) {
1676         capture_opts->autostop_filesize = tmp;
1677       } else {
1678         simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
1679           PRIMARY_TEXT_START "Stop Capture: Requested filesize too large!\n\n" PRIMARY_TEXT_END
1680           "The setting \"... after x byte(s)\" can't be greater than %u bytes (2GB).", G_MAXINT);
1681         return;
1682       }
1683     }
1684   } /* multi_files_on */
1685 }
1686
1687 /* user requested to destroy the dialog */
1688 static void
1689 capture_prep_destroy_cb(GtkWidget *win, gpointer user_data _U_)
1690 {
1691   GtkWidget *fs;
1692
1693   /* Is there a file selection dialog associated with this
1694      Capture Options dialog? */
1695   fs = OBJECT_GET_DATA(win, E_FILE_SEL_DIALOG_PTR_KEY);
1696
1697   if (fs != NULL) {
1698     /* Yes.  Destroy it. */
1699     window_destroy(fs);
1700   }
1701
1702   /* Note that we no longer have a "Capture Options" dialog box. */
1703   cap_open_w = NULL;
1704
1705 #ifdef HAVE_AIRPCAP
1706   /* update airpcap toolbar */
1707   airpcap_set_toolbar_stop_capture(airpcap_if_active);
1708 #endif
1709 }
1710
1711 /* user changed the interface entry */
1712 static void
1713 capture_prep_interface_changed_cb(GtkWidget *entry, gpointer argp)
1714 {
1715   GtkWidget *linktype_om = argp;
1716   set_link_type_list(linktype_om, entry);
1717   /* Default to "use the default" */
1718   OBJECT_SET_DATA(linktype_om, E_CAP_OM_LT_VALUE_KEY, GINT_TO_POINTER(-1));
1719   capture_opts->linktype = GPOINTER_TO_INT(OBJECT_GET_DATA(linktype_om, E_CAP_OM_LT_VALUE_KEY));
1720   linktype_history=0;
1721 }
1722
1723 /*
1724  * Adjust the sensitivity of various widgets as per the current setting
1725  * of other widgets.
1726  */
1727 static void
1728 capture_prep_adjust_sensitivity(GtkWidget *tb _U_, gpointer parent_w)
1729 {
1730   GtkWidget *if_cb,
1731             *snap_cb, *snap_sb,
1732             *multi_files_on_cb, *ringbuffer_nbf_cb, *ringbuffer_nbf_sb, *ringbuffer_nbf_lb,
1733             *ring_filesize_cb, *ring_filesize_sb, *ring_filesize_om,
1734             *file_duration_cb, *file_duration_sb, *file_duration_om,
1735             *sync_cb, *auto_scroll_cb, *hide_info_cb,
1736             *stop_packets_cb, *stop_packets_sb, *stop_packets_lb,
1737             *stop_filesize_cb, *stop_filesize_sb, *stop_filesize_om,
1738             *stop_duration_cb, *stop_duration_sb, *stop_duration_om,
1739             *stop_files_cb, *stop_files_sb, *stop_files_lb;
1740
1741
1742   if_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_IFACE_KEY);
1743   snap_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_SNAP_CB_KEY);
1744   snap_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_SNAP_SB_KEY);
1745   multi_files_on_cb  = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_MULTI_FILES_ON_CB_KEY);
1746   ringbuffer_nbf_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_RING_NBF_CB_KEY);
1747   ringbuffer_nbf_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_RING_NBF_SB_KEY);
1748   ringbuffer_nbf_lb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_RING_NBF_LB_KEY);
1749   ring_filesize_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_RING_FILESIZE_CB_KEY);
1750   ring_filesize_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_RING_FILESIZE_SB_KEY);
1751   ring_filesize_om = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_RING_FILESIZE_OM_KEY);
1752   file_duration_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_FILE_DURATION_CB_KEY);
1753   file_duration_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_FILE_DURATION_SB_KEY);
1754   file_duration_om = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_FILE_DURATION_OM_KEY);
1755   sync_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_SYNC_KEY);
1756   auto_scroll_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_AUTO_SCROLL_KEY);
1757   hide_info_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_HIDE_INFO_KEY);
1758   stop_packets_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_PACKETS_CB_KEY);
1759   stop_packets_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_PACKETS_SB_KEY);
1760   stop_packets_lb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_PACKETS_LB_KEY);
1761   stop_filesize_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_FILESIZE_CB_KEY);
1762   stop_filesize_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_FILESIZE_SB_KEY);
1763   stop_filesize_om = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_FILESIZE_OM_KEY);
1764   stop_duration_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_DURATION_CB_KEY);
1765   stop_duration_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_DURATION_SB_KEY);
1766   stop_duration_om = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_DURATION_OM_KEY);
1767   stop_files_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_FILES_CB_KEY);
1768   stop_files_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_FILES_SB_KEY);
1769   stop_files_lb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_FILES_LB_KEY);
1770
1771   /* The snapshot length spinbox is sensitive if the "Limit each packet
1772      to" checkbox is on. */
1773   gtk_widget_set_sensitive(GTK_WIDGET(snap_sb),
1774       gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(snap_cb)));
1775
1776
1777   if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(sync_cb))) {
1778     /* "Update list of packets in real time" captures enabled; we don't
1779        support ring buffer mode for those captures, so turn ring buffer
1780        mode off if it's on, and make its toggle button, and the spin
1781        button for the number of ring buffer files (and the spin button's
1782        label), insensitive. */
1783 /*    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(multi_files_on_cb), FALSE);
1784     gtk_widget_set_sensitive(GTK_WIDGET(multi_files_on_cb), FALSE);*/
1785
1786     /* Auto-scroll mode is meaningful only in "Update list of packets
1787        in real time" captures, so make its toggle button sensitive. */
1788     gtk_widget_set_sensitive(GTK_WIDGET(auto_scroll_cb), TRUE);
1789
1790     /*gtk_widget_set_sensitive(GTK_WIDGET(hide_info_cb), TRUE);*/
1791   } else {
1792     /* "Update list of packets in real time" captures disabled; that
1793        means ring buffer mode is OK, so make its toggle button
1794        sensitive. */
1795 /*    gtk_widget_set_sensitive(GTK_WIDGET(multi_files_on_cb), TRUE);*/
1796
1797     /* Auto-scroll mode is meaningful only in "Update list of packets
1798        in real time" captures, so make its toggle button insensitive. */
1799     gtk_widget_set_sensitive(GTK_WIDGET(auto_scroll_cb), FALSE);
1800
1801     /*gtk_widget_set_sensitive(GTK_WIDGET(hide_info_cb), FALSE);*/
1802   }
1803
1804   if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(multi_files_on_cb))) {
1805     /* Ring buffer mode enabled. */
1806
1807     /* Force at least one of the "file switch" conditions (we need at least one) */
1808     if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ring_filesize_cb)) == FALSE &&
1809         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(file_duration_cb)) == FALSE) {
1810       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ring_filesize_cb), TRUE);
1811     }
1812
1813     gtk_widget_set_sensitive(GTK_WIDGET(ringbuffer_nbf_cb), TRUE);
1814     gtk_widget_set_sensitive(GTK_WIDGET(ringbuffer_nbf_sb),
1815           gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ringbuffer_nbf_cb)));
1816     gtk_widget_set_sensitive(GTK_WIDGET(ringbuffer_nbf_lb),
1817           gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ringbuffer_nbf_cb)));
1818
1819     /* The ring filesize spinbox is sensitive if the "Next capture file
1820          after N kilobytes" checkbox is on. */
1821     gtk_widget_set_sensitive(GTK_WIDGET(ring_filesize_cb), TRUE);
1822     gtk_widget_set_sensitive(GTK_WIDGET(ring_filesize_sb),
1823           gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ring_filesize_cb)));
1824     gtk_widget_set_sensitive(GTK_WIDGET(ring_filesize_om),
1825           gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ring_filesize_cb)));
1826
1827     /* The ring duration spinbox is sensitive if the "Next capture file
1828          after N seconds" checkbox is on. */
1829     gtk_widget_set_sensitive(GTK_WIDGET(file_duration_cb), TRUE);
1830     gtk_widget_set_sensitive(GTK_WIDGET(file_duration_sb),
1831           gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(file_duration_cb)));
1832     gtk_widget_set_sensitive(GTK_WIDGET(file_duration_om),
1833           gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(file_duration_cb)));
1834
1835     gtk_widget_set_sensitive(GTK_WIDGET(stop_filesize_cb), FALSE);
1836     gtk_widget_set_sensitive(GTK_WIDGET(stop_filesize_sb), FALSE);
1837     gtk_widget_set_sensitive(GTK_WIDGET(stop_filesize_om), FALSE);
1838
1839     gtk_widget_set_sensitive(GTK_WIDGET(stop_files_cb), TRUE);
1840     gtk_widget_set_sensitive(GTK_WIDGET(stop_files_sb),
1841           gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_files_cb)));
1842     gtk_widget_set_sensitive(GTK_WIDGET(stop_files_lb),
1843           gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_files_cb)));
1844   } else {
1845     /* Ring buffer mode disabled. */
1846     gtk_widget_set_sensitive(GTK_WIDGET(ringbuffer_nbf_cb), FALSE);
1847     gtk_widget_set_sensitive(GTK_WIDGET(ringbuffer_nbf_sb), FALSE);
1848     gtk_widget_set_sensitive(GTK_WIDGET(ringbuffer_nbf_lb), FALSE);
1849
1850     gtk_widget_set_sensitive(GTK_WIDGET(ring_filesize_cb), FALSE);
1851     gtk_widget_set_sensitive(GTK_WIDGET(ring_filesize_sb),FALSE);
1852     gtk_widget_set_sensitive(GTK_WIDGET(ring_filesize_om),FALSE);
1853
1854     gtk_widget_set_sensitive(GTK_WIDGET(file_duration_cb), FALSE);
1855     gtk_widget_set_sensitive(GTK_WIDGET(file_duration_sb),FALSE);
1856     gtk_widget_set_sensitive(GTK_WIDGET(file_duration_om),FALSE);
1857
1858     /* The maximum file size spinbox is sensitive if the "Stop capture
1859          after N kilobytes" checkbox is on. */
1860     gtk_widget_set_sensitive(GTK_WIDGET(stop_filesize_cb), TRUE);
1861     gtk_widget_set_sensitive(GTK_WIDGET(stop_filesize_sb),
1862           gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_filesize_cb)));
1863     gtk_widget_set_sensitive(GTK_WIDGET(stop_filesize_om),
1864           gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_filesize_cb)));
1865
1866     gtk_widget_set_sensitive(GTK_WIDGET(stop_files_cb), FALSE);
1867     gtk_widget_set_sensitive(GTK_WIDGET(stop_files_sb), FALSE);
1868     gtk_widget_set_sensitive(GTK_WIDGET(stop_files_lb), FALSE);
1869   }
1870
1871   /* The maximum packet count spinbox is sensitive if the "Stop capture
1872      after N packets" checkbox is on. */
1873   gtk_widget_set_sensitive(GTK_WIDGET(stop_packets_sb),
1874       gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_packets_cb)));
1875   gtk_widget_set_sensitive(GTK_WIDGET(stop_packets_lb),
1876       gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_packets_cb)));
1877
1878   /* The capture duration spinbox is sensitive if the "Stop capture
1879      after N seconds" checkbox is on. */
1880   gtk_widget_set_sensitive(GTK_WIDGET(stop_duration_sb),
1881       gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_duration_cb)));
1882   gtk_widget_set_sensitive(GTK_WIDGET(stop_duration_om),
1883       gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_duration_cb)));
1884 }
1885
1886 #endif /* HAVE_LIBPCAP */