2 * Routines for packet capture windows
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
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.
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.
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.
33 #include <stdio.h> /* menu.h needs FILE */
36 #include <epan/packet.h>
39 #include <epan/addr_resolv.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"
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"
56 #include "gtkglobals.h"
57 #include "cfilter_combo_utils.h"
60 #include "capture-wpcap.h"
67 #include "airpcap_loader.h"
68 #include "airpcap_gui_utils.h"
69 #include "airpcap_dlg.h"
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"
79 #define E_CAP_BUFFER_SIZE_SB_KEY "cap_buffer_size_sb"
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"
114 #define E_CAP_OM_LT_VALUE_KEY "cap_om_lt_value"
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.
123 static GtkWidget *cap_open_w;
124 static GtkWidget * dl_hdr_menu=NULL;
125 static guint linktype_history=0;
128 capture_prep_file_cb(GtkWidget *file_bt, GtkWidget *file_te);
131 select_link_type_cb(GtkWidget *w, gpointer data);
134 capture_prep_adjust_sensitivity(GtkWidget *tb, gpointer parent_w);
137 capture_prep_destroy_cb(GtkWidget *win, gpointer user_data);
140 capture_prep_interface_changed_cb(GtkWidget *entry, gpointer parent_w);
143 capture_dlg_prep(gpointer parent_w);
146 /* stop the currently running capture */
148 capture_stop_cb(GtkWidget *w _U_, gpointer d _U_)
151 airpcap_set_toolbar_stop_capture(airpcap_if_active);
154 capture_stop(capture_opts);
157 /* restart (stop - delete old file - start) running capture */
159 capture_restart_cb(GtkWidget *w _U_, gpointer d _U_)
162 airpcap_set_toolbar_start_capture(airpcap_if_active);
165 capture_restart(capture_opts);
168 /* init the link type list */
169 /* (often this list has only one entry and will therefore be disabled) */
171 set_link_type_list(GtkWidget *linktype_om, GtkWidget *entry)
181 GtkWidget *lt_menu, *lt_menu_item;
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);
188 GString *ip_str = g_string_new("IP address: ");
193 GtkWidget *advanced_bt;
196 /* Deallocate the existing menu for Datalink header type */
197 if (dl_hdr_menu != NULL)
198 gtk_widget_destroy(dl_hdr_menu);
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));
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)
214 gtk_widget_set_sensitive(advanced_bt,TRUE);
218 gtk_widget_set_sensitive(advanced_bt,FALSE);
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.
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.
235 if (*if_name != '\0') {
237 * Try to get the list of known interfaces.
239 if_list = get_interface_list(&err, NULL);
240 if (if_list != NULL) {
242 * We have the list - check it.
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) {
250 * Get the list of link-layer types for it.
252 lt_list = get_pcap_linktype_list(if_name, NULL);
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++) {
257 g_string_append(ip_str, ", ");
259 ip_addr = (if_addr_t *)curr_ip->data;
260 switch (ip_addr->type) {
263 g_string_append(ip_str,
264 ip_to_str((guint8 *)&ip_addr->ip_addr.ip4_addr));
268 g_string_append(ip_str,
269 ip6_to_str((struct e_in6_addr *)&ip_addr->ip_addr.ip6_addr));
273 g_assert_not_reached();
277 if (if_info->loopback)
278 g_string_append(ip_str, " (loopback)");
281 free_interface_list(if_list);
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++;
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);
303 gtk_menu_append(GTK_MENU(lt_menu), lt_menu_item);
304 gtk_widget_show(lt_menu_item);
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);
315 g_string_append(ip_str, "unknown");
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);
321 g_string_free(ip_str, TRUE);
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] = {
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;
343 unit_om=gtk_option_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);
351 /* the selected menu item can't be changed, once the option_menu
352 is created, so set the matching menu item now */
354 if(value >= 60 * 60 * 24) {
355 gtk_menu_set_active(GTK_MENU(menu), TIME_UNIT_DAY);
358 if(value >= 60 * 60) {
359 gtk_menu_set_active(GTK_MENU(menu), TIME_UNIT_HOUR);
363 gtk_menu_set_active(GTK_MENU(menu), TIME_UNIT_MINUTE);
366 gtk_menu_set_active(GTK_MENU(menu), TIME_UNIT_SECOND);
371 gtk_option_menu_set_menu(GTK_OPTION_MENU(unit_om), menu);
376 /* convert time value from raw to displayed (e.g. 60s -> 1min) */
377 static guint32 time_unit_option_menu_convert_value(
381 if(value >= 60 * 60 * 24) {
382 return value / (60 * 60 * 24);
386 if(value >= 60 * 60) {
387 return value / (60 * 60);
399 /* get raw value from unit and value fields */
400 static guint32 time_unit_option_menu_get_value(
404 GtkWidget *menu, *menu_item;
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"));
413 case(TIME_UNIT_SECOND):
416 case(TIME_UNIT_MINUTE):
419 case(TIME_UNIT_HOUR):
420 return value * 60 * 60;
423 return value * 60 * 60 * 24;
426 g_assert_not_reached();
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] = {
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;
448 unit_om=gtk_option_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);
456 /* the selected menu item can't be changed, once the option_menu
457 is created, so set the matching menu item now */
459 if(value >= 1024 * 1024) {
460 gtk_menu_set_active(GTK_MENU(menu), SIZE_UNIT_GIGABYTES);
464 gtk_menu_set_active(GTK_MENU(menu), SIZE_UNIT_MEGABYTES);
467 gtk_menu_set_active(GTK_MENU(menu), SIZE_UNIT_KILOBYTES);
471 gtk_option_menu_set_menu(GTK_OPTION_MENU(unit_om), menu);
476 /* convert size value from raw to displayed (e.g. 1024 Bytes -> 1 KB) */
477 static guint32 size_unit_option_menu_set_value(
481 if(value >= 1024 * 1024) {
482 return value / (1024 * 1024);
487 return value / (1024);
494 /* get raw value from unit and value fields */
495 static guint32 size_unit_option_menu_convert_value(
499 GtkWidget *menu, *menu_item;
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"));
508 case(SIZE_UNIT_KILOBYTES):
511 case(SIZE_UNIT_MEGABYTES):
512 if(value > G_MAXINT / 1024) {
518 case(SIZE_UNIT_GIGABYTES):
519 if(value > G_MAXINT / (1024 * 1024)) {
522 return value * 1024 * 1024;
526 g_assert_not_reached();
533 * Sets the toolbar before calling the advanced dialog with for the right interface
536 options_airpcap_advanced_cb(GtkWidget *w _U_, gpointer d _U_)
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);
544 airpcap_if_active = airpcap_if_selected;
545 airpcap_enable_toolbar_widgets(airpcap_tb,FALSE);
546 display_airpcap_advanced_cb(w,d);
550 /* show capture prepare (options) dialog */
552 capture_prep_cb(GtkWidget *w _U_, gpointer d _U_)
555 *main_hb, *left_vb, *right_vb,
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,
563 *filter_hb, *filter_bt, *filter_te, *filter_cm,
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,
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,
578 *display_fr, *display_vb,
579 *sync_cb, *auto_scroll_cb, *hide_info_cb,
581 *resolv_fr, *resolv_vb,
582 *m_resolv_cb, *n_resolv_cb, *t_resolv_cb,
583 *bbox, *ok_bt, *cancel_bt,
586 GtkWidget *advanced_hb, *advanced_bt;
588 #if GTK_MAJOR_VERSION < 2
589 GtkAccelGroup *accel_group;
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;
599 GtkAdjustment *buffer_size_adj;
600 GtkWidget *buffer_size_lb, *buffer_size_sb;
607 GtkWidget *decryption_cm;
610 if (cap_open_w != NULL) {
611 /* There's already a "Capture Options" dialog box; reactivate it. */
612 reactivate_window(cap_open_w);
617 /* Is WPcap loaded? */
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);
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);
635 /* update airpcap interface list */
637 /* load the airpcap interfaces */
638 airpcap_if_list = get_airpcap_interface_list(&err, &err_str);
640 decryption_cm = OBJECT_GET_DATA(airpcap_tb,AIRPCAP_TOOLBAR_DECRYPTION_KEY);
641 update_decryption_mode_list(decryption_cm);
643 if (airpcap_if_list == NULL && err == CANT_GET_AIRPCAP_INTERFACE_LIST) {
644 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_str);
648 /* select the first ad default (THIS SHOULD BE CHANGED) */
649 airpcap_if_active = airpcap_get_default_if(airpcap_if_list);
652 /* use user-defined title if preference is set */
653 cap_title = create_user_window_title("Wireshark: Capture Options");
655 cap_open_w = dlg_window_new(cap_title);
658 tooltips = gtk_tooltips_new();
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);
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);
672 /* Capture-related options frame */
673 capture_fr = gtk_frame_new("Capture");
674 gtk_container_add(GTK_CONTAINER(main_vb), capture_fr);
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);
681 if_hb = gtk_hbox_new(FALSE, 3);
682 gtk_container_add(GTK_CONTAINER(capture_vb), if_hb);
684 if_lb = gtk_label_new("Interface:");
685 gtk_box_pack_start(GTK_BOX(if_hb), if_lb, FALSE, FALSE, 6);
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));
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);
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);
710 } else if (combo_list != NULL) {
711 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(if_cb)->entry),
712 (char *)combo_list->data);
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);
721 if_ip_hb = gtk_hbox_new(FALSE, 3);
722 gtk_box_pack_start(GTK_BOX(capture_vb), if_ip_hb, FALSE, FALSE, 0);
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 \"...\" "
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);
738 linktype_hb = gtk_hbox_new(FALSE, 3);
739 gtk_box_pack_start(GTK_BOX(capture_vb), linktype_hb, FALSE, FALSE, 0);
741 linktype_lb = gtk_label_new("Link-layer header type:");
742 gtk_box_pack_start(GTK_BOX(linktype_hb), linktype_lb, FALSE, FALSE, 6);
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);
751 set_link_type_list(linktype_om, GTK_COMBO(if_cb)->entry);
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.
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.
765 * We leave it as "multiple link-layer types" for now.
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);
774 buffer_size_lb = gtk_label_new("Buffer size:");
775 gtk_box_pack_start (GTK_BOX(linktype_hb), buffer_size_lb, FALSE, FALSE, 0);
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);
787 buffer_size_lb = gtk_label_new("megabyte(s)");
788 gtk_box_pack_start (GTK_BOX(linktype_hb), buffer_size_lb, FALSE, FALSE, 6);
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);
802 /* Capture length row */
803 snap_hb = gtk_hbox_new(FALSE, 3);
804 gtk_container_add(GTK_CONTAINER(capture_vb), snap_hb);
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);
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);
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);
827 filter_hb = gtk_hbox_new(FALSE, 3);
828 gtk_box_pack_start(GTK_BOX(capture_vb), filter_hb, FALSE, FALSE, 0);
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.",
837 gtk_box_pack_start(GTK_BOX(filter_hb), filter_bt, FALSE, FALSE, 3);
839 /* Create the capture filter combo */
840 filter_cm = gtk_combo_new();
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;
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.",
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);
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);
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);
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);
876 advanced_hb = gtk_hbox_new(FALSE,5);
877 gtk_box_pack_start(GTK_BOX(capture_vb), advanced_hb, FALSE, FALSE, 0);
879 advanced_bt = gtk_button_new_with_label("Wireless Settings");
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");
886 /* Set the GtkButton label in GTK 1.x */
887 gtk_label_set_text(GTK_LABEL(GTK_BIN(advanced_bt)->child), "Wireless Settings");
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);
894 if(airpcap_if_selected != NULL)
896 /* It is an airpcap interface */
897 gtk_widget_set_sensitive(advanced_bt,TRUE);
901 gtk_widget_set_sensitive(advanced_bt,FALSE);
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);
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);
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);
918 file_hb = gtk_hbox_new(FALSE, 3);
919 gtk_box_pack_start(GTK_BOX(file_vb), file_hb, FALSE, FALSE, 0);
921 file_lb = gtk_label_new("File:");
922 gtk_box_pack_start(GTK_BOX(file_hb), file_lb, FALSE, FALSE, 3);
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.",
929 gtk_box_pack_start(GTK_BOX(file_hb), file_te, TRUE, TRUE, 3);
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. ",
936 gtk_box_pack_start(GTK_BOX(file_hb), file_bt, FALSE, FALSE, 3);
938 SIGNAL_CONNECT(file_bt, "clicked", capture_prep_file_cb, file_te);
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);
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,
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);
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.",
968 gtk_table_attach_defaults(GTK_TABLE(multi_tb), ring_filesize_cb, 0, 1, row, row+1);
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);
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);
980 value = size_unit_option_menu_set_value(capture_opts->autostop_filesize);
981 gtk_adjustment_set_value(ring_filesize_adj, (gfloat) value);
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.",
995 gtk_table_attach_defaults(GTK_TABLE(multi_tb), file_duration_cb, 0, 1, row, row+1);
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);
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);
1007 value = time_unit_option_menu_convert_value(capture_opts->file_duration);
1008 gtk_adjustment_set_value(file_duration_adj, (gfloat) value);
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.",
1020 gtk_table_attach_defaults(GTK_TABLE(multi_tb), ringbuffer_nbf_cb, 0, 1, row, row+1);
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);
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);
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);
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);
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);
1056 /* Capture limits frame */
1057 limit_fr = gtk_frame_new("Stop Capture ...");
1058 gtk_container_add(GTK_CONTAINER(left_vb), limit_fr);
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);
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);
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);
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);
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);
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);
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);
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);
1111 value = size_unit_option_menu_set_value(capture_opts->autostop_filesize);
1112 gtk_adjustment_set_value(stop_filesize_adj, (gfloat) value);
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);
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);
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);
1135 value = time_unit_option_menu_convert_value(capture_opts->autostop_duration);
1136 gtk_adjustment_set_value(stop_duration_adj, (gfloat) value);
1139 /* Display-related options frame */
1140 display_fr = gtk_frame_new("Display Options");
1141 gtk_container_add(GTK_CONTAINER(right_vb), display_fr);
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);
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);
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);
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);
1175 /* Name Resolution frame */
1176 resolv_fr = gtk_frame_new("Name Resolution");
1177 gtk_container_add(GTK_CONTAINER(right_vb), resolv_fr);
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);
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);
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);
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);
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);
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);
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);
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);
1226 gtk_widget_grab_default(ok_bt);
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);
1234 OBJECT_SET_DATA(cap_open_w, E_CAP_BUFFER_SIZE_SB_KEY, buffer_size_sb);
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);
1268 /* Set the sensitivity of various widgets as per the settings of other
1270 capture_prep_adjust_sensitivity(NULL, cap_open_w);
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);
1280 /* XXX - why does not
1282 gtk_widget_grab_focus(if_cb);
1284 give the initial focus to the "Interface" combo box?
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.... */
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);
1306 /* Give the initial focus to the "Filter" entry box. */
1307 gtk_widget_grab_focus(filter_te);
1309 gtk_widget_show_all(cap_open_w);
1310 window_present(cap_open_w);
1313 /* everythings prepared, now it's really time to start the capture */
1315 capture_start_confirmed(void) {
1318 /* init iface, if never used before */
1319 /* XXX - would better be doing this in main.c */
1320 if(capture_opts->iface == NULL) {
1322 const gchar *if_name;
1324 /* did the user ever selected a capture interface before? */
1325 if(prefs.capture_device == NULL) {
1326 simple_dialog(ESD_TYPE_CONFIRMATION,
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)");
1334 if_device = g_strdup(prefs.capture_device);
1335 if_name = get_if_name(if_device);
1336 capture_opts->iface = g_strdup(if_name);
1341 /* XXX - we might need to init other pref data as well... */
1342 menu_auto_scroll_live_changed(auto_scroll_live);
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);
1351 /* user confirmed the "Save capture file..." dialog */
1353 capture_start_answered_cb(gpointer dialog _U_, gint btn, gpointer data)
1357 /* save file first */
1358 file_save_as_cmd(after_save_capture_dialog, data);
1360 case(ESD_BTN_DONT_SAVE):
1361 /* XXX - unlink old file? */
1362 /* start the capture */
1363 capture_start_confirmed();
1365 case(ESD_BTN_CANCEL):
1368 g_assert_not_reached();
1372 /* user pressed the "Start" button (in dialog or toolbar) */
1374 capture_start_cb(GtkWidget *w _U_, gpointer d _U_)
1379 airpcap_if_active = airpcap_if_selected;
1380 airpcap_set_toolbar_start_capture(airpcap_if_active);
1384 /* Is WPcap loaded? */
1386 char * err_msg = cant_load_winpcap_err("Wireshark");
1388 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
1395 /* get the values and close the options dialog */
1397 capture_dlg_prep(cap_open_w);
1398 window_destroy(GTK_WIDGET(cap_open_w));
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);
1408 /* unchanged file, just capture a new one */
1409 capture_start_confirmed();
1413 /* user selected a link type, convert to internal value */
1415 select_link_type_cb(GtkWidget *w, gpointer data)
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));
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);
1433 /* user pressed "File" button */
1435 capture_prep_file_cb(GtkWidget *file_bt, GtkWidget *file_te)
1437 file_selection_browse(file_bt, file_te, "Wireshark: Specify a Capture File", FILE_SELECTION_WRITE_BROWSE);
1441 /* convert dialog settings into capture_opts values */
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;
1455 GtkWidget *buffer_size_sb;
1459 const gchar *if_name;
1460 const gchar *filter_text;
1461 const gchar *g_save_file;
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);
1471 buffer_size_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_BUFFER_SIZE_SB_KEY);
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);
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.");
1513 if (capture_opts->iface)
1514 g_free(capture_opts->iface);
1515 capture_opts->iface = g_strdup(if_name);
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)); */
1523 capture_opts->buffer_size =
1524 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(buffer_size_sb));
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;
1538 capture_opts->promisc_mode =
1539 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(promisc_cb));
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);
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);
1567 /* User didn't specify a file; save to a temporary file. */
1568 capture_opts->save_file = NULL;
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));
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);
1586 capture_opts->real_time_mode =
1587 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(sync_cb));
1590 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(auto_scroll_cb));
1592 capture_opts->show_info =
1593 !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(hide_info_cb));
1595 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m_resolv_cb)))
1596 g_resolv_flags |= RESOLV_MAC;
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;
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;
1606 g_resolv_flags &= ~RESOLV_TRANSPORT;
1608 capture_opts->has_ring_num_files =
1609 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ringbuffer_nbf_cb));
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;
1620 capture_opts->multi_files_on =
1621 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(multi_files_on_cb));
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);
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));
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);
1645 capture_opts->autostop_filesize = tmp;
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);
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.");
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;
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);
1676 capture_opts->autostop_filesize = tmp;
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);
1684 } /* multi_files_on */
1687 /* user requested to destroy the dialog */
1689 capture_prep_destroy_cb(GtkWidget *win, gpointer user_data _U_)
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);
1698 /* Yes. Destroy it. */
1702 /* Note that we no longer have a "Capture Options" dialog box. */
1706 /* update airpcap toolbar */
1707 airpcap_set_toolbar_stop_capture(airpcap_if_active);
1711 /* user changed the interface entry */
1713 capture_prep_interface_changed_cb(GtkWidget *entry, gpointer argp)
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));
1724 * Adjust the sensitivity of various widgets as per the current setting
1728 capture_prep_adjust_sensitivity(GtkWidget *tb _U_, gpointer parent_w)
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;
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);
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)));
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);*/
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);
1790 /*gtk_widget_set_sensitive(GTK_WIDGET(hide_info_cb), TRUE);*/
1792 /* "Update list of packets in real time" captures disabled; that
1793 means ring buffer mode is OK, so make its toggle button
1795 /* gtk_widget_set_sensitive(GTK_WIDGET(multi_files_on_cb), TRUE);*/
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);
1801 /*gtk_widget_set_sensitive(GTK_WIDGET(hide_info_cb), FALSE);*/
1804 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(multi_files_on_cb))) {
1805 /* Ring buffer mode enabled. */
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);
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)));
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)));
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)));
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);
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)));
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);
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);
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);
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)));
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);
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)));
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)));
1886 #endif /* HAVE_LIBPCAP */