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