diff options
author | Ulf Lamping <ulf.lamping@web.de> | 2004-07-17 13:50:07 +0000 |
---|---|---|
committer | Ulf Lamping <ulf.lamping@web.de> | 2004-07-17 13:50:07 +0000 |
commit | 357ebbca5a3959e9b2712333ede380e368259aa0 (patch) | |
tree | 4e6ffbd3f902c35bfc4bbebb187e9e2dde7b6201 | |
parent | 80a890cb122d08e8f886ad2d505ec865dfe21d46 (diff) |
add a new dialog box to menu "Capture/Interfaces..." to show the current state of the interfaces and a quick way to start a capture.
added the IP address of the currently selected interface to the capture options dialog
svn path=/trunk/; revision=11396
-rw-r--r-- | gtk/Makefile.common | 1 | ||||
-rw-r--r-- | gtk/capture_dlg.c | 3380 | ||||
-rw-r--r-- | gtk/capture_dlg.h | 119 | ||||
-rw-r--r-- | gtk/capture_if_dlg.c | 486 | ||||
-rw-r--r-- | gtk/menu.c | 3652 | ||||
-rw-r--r-- | gtk/toolbar.c | 13 |
6 files changed, 4110 insertions, 3541 deletions
diff --git a/gtk/Makefile.common b/gtk/Makefile.common index 73fa38630d..6b92a0b343 100644 --- a/gtk/Makefile.common +++ b/gtk/Makefile.common @@ -32,6 +32,7 @@ ETHEREAL_GTK_SRC = \ about_dlg.c \ capture_combo_utils.c \ capture_dlg.c \ + capture_if_dlg.c \ capture_info_dlg.c \ capture_prefs.c \ color_dlg.c \ diff --git a/gtk/capture_dlg.c b/gtk/capture_dlg.c index 333b406450..9c42786c99 100644 --- a/gtk/capture_dlg.c +++ b/gtk/capture_dlg.c @@ -1,1665 +1,1715 @@ -/* capture_dlg.c - * Routines for packet capture windows - * - * $Id: capture_dlg.c,v 1.138 2004/07/13 07:15:43 guy Exp $ - * - * Ethereal - Network traffic analyzer - * By Gerald Combs <gerald@ethereal.com> - * Copyright 1998 Gerald Combs - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#ifdef HAVE_LIBPCAP - -#include <pcap.h> -#include <string.h> -#include <gtk/gtk.h> - -#include <epan/packet.h> -#include "capture.h" -#include "globals.h" -#include <epan/resolv.h> -#include "main.h" -#include "ui_util.h" -#include "capture_dlg.h" -#include "filter_prefs.h" -#include "simple_dialog.h" -#include "dlg_utils.h" -#include "pcap-util.h" -#include "capture_combo_utils.h" -#include "prefs.h" -#include "ringbuffer.h" -#include <epan/filesystem.h> -#include "compat_macros.h" -#include "file_dlg.h" -#include "help_dlg.h" -#include "gtkglobals.h" - -#ifdef _WIN32 -#include "capture-wpcap.h" -#endif - -/* Capture callback data keys */ -#define E_CAP_IFACE_KEY "cap_iface" -#define E_CAP_SNAP_CB_KEY "cap_snap_cb" -#define E_CAP_LT_OM_KEY "cap_lt_om" -#define E_CAP_LT_OM_LABEL_KEY "cap_lt_om_label" -#ifdef _WIN32 -#define E_CAP_BUFFER_SIZE_SB_KEY "cap_buffer_size_sb" -#endif -#define E_CAP_SNAP_SB_KEY "cap_snap_sb" -#define E_CAP_PROMISC_KEY "cap_promisc" -#define E_CAP_FILT_KEY "cap_filter_te" -#define E_CAP_FILE_TE_KEY "cap_file_te" -#define E_CAP_MULTI_FILES_ON_CB_KEY "cap_multi_files_on_cb" -#define E_CAP_RING_FILESIZE_CB_KEY "cap_ring_filesize_cb" -#define E_CAP_RING_FILESIZE_SB_KEY "cap_ring_filesize_sb" -#define E_CAP_RING_FILESIZE_OM_KEY "cap_ring_filesize_om" -#define E_CAP_FILE_DURATION_CB_KEY "cap_file_duration_cb" -#define E_CAP_FILE_DURATION_SB_KEY "cap_file_duration_sb" -#define E_CAP_FILE_DURATION_OM_KEY "cap_file_duration_om" -#define E_CAP_RING_NBF_CB_KEY "cap_ring_nbf_cb" -#define E_CAP_RING_NBF_SB_KEY "cap_ring_nbf_sb" -#define E_CAP_RING_NBF_LB_KEY "cap_ring_nbf_lb" -#define E_CAP_STOP_FILES_CB_KEY "cap_stop_files_cb" -#define E_CAP_STOP_FILES_SB_KEY "cap_stop_files_sb" -#define E_CAP_STOP_FILES_LB_KEY "cap_stop_files_lb" -#define E_CAP_SYNC_KEY "cap_sync" -#define E_CAP_AUTO_SCROLL_KEY "cap_auto_scroll" -#define E_CAP_HIDE_INFO_KEY "cap_hide_info" -#define E_CAP_STOP_PACKETS_CB_KEY "cap_stop_packets_cb" -#define E_CAP_STOP_PACKETS_SB_KEY "cap_stop_packets_sb" -#define E_CAP_STOP_PACKETS_LB_KEY "cap_stop_packets_lb" -#define E_CAP_STOP_FILESIZE_CB_KEY "cap_stop_filesize_cb" -#define E_CAP_STOP_FILESIZE_SB_KEY "cap_stop_filesize_sb" -#define E_CAP_STOP_FILESIZE_OM_KEY "cap_stop_filesize_om" -#define E_CAP_STOP_DURATION_CB_KEY "cap_stop_duration_cb" -#define E_CAP_STOP_DURATION_SB_KEY "cap_stop_duration_sb" -#define E_CAP_STOP_DURATION_OM_KEY "cap_stop_duration_om" -#define E_CAP_M_RESOLVE_KEY "cap_m_resolve" -#define E_CAP_N_RESOLVE_KEY "cap_n_resolve" -#define E_CAP_T_RESOLVE_KEY "cap_t_resolve" - -#define E_CAP_OM_LT_VALUE_KEY "cap_om_lt_value" - -static void -capture_prep_file_cb(GtkWidget *file_bt, GtkWidget *file_te); - -static void -select_link_type_cb(GtkWidget *w, gpointer data); - -static void -capture_prep_adjust_sensitivity(GtkWidget *tb, gpointer parent_w); - -static void -capture_prep_ok_cb(GtkWidget *ok_bt, gpointer parent_w); - -static void -capture_prep_destroy_cb(GtkWidget *win, gpointer user_data); - -static void -capture_prep_interface_changed_cb(GtkWidget *entry, gpointer parent_w); - -void -capture_stop_cb(GtkWidget *w _U_, gpointer d _U_) -{ - capture_stop(); -} - -/* - * Given text that contains an interface name possibly prefixed by an - * interface description, extract the interface name. - */ -static char * -get_if_name(char *if_text) -{ - char *if_name; - -#ifdef WIN32 - /* - * We cannot assume that the interface name doesn't contain a space; - * some names on Windows OT do. - * - * We also can't assume it begins with "\Device\", either, as, on - * Windows OT, WinPcap doesn't put "\Device\" in front of the name. - * - * As I remember, we can't assume that the interface description - * doesn't contain a colon, either; I think some do. - * - * We can probably assume that the interface *name* doesn't contain - * a colon, however; if any interface name does contain a colon on - * Windows, it'll be time to just get rid of the damn interface - * descriptions in the drop-down list, have just the names in the - * drop-down list, and have a "Browse..." button to browse for interfaces, - * with names, descriptions, IP addresses, blah blah blah available when - * possible. - * - * So we search backwards for a colon. If we don't find it, just - * return the entire string; otherwise, skip the colon and any blanks - * after it, and return that string. - */ - if_name = if_text + strlen(if_text); - for (;;) { - if (if_name == if_text) { - /* We're at the beginning of the string; return it. */ - break; - } - if_name--; - if (*if_name == ':') { - /* - * We've found a colon. - * Unfortunately, a colon is used in the string "rpcap://", - * which is used in case of a remote capture. - * So we'll check to make sure the colon isn't followed by "//"; - * it'll be followed by a blank if it separates the description - * and the interface name. (We don't wire in "rpcap", in case we - * support other protocols in the same syntax.) - */ - if (strncmp(if_name, "://", 3) != 0) { - /* - * OK, we've found a colon not followed by "//". Skip blanks - * following it. - */ - if_name++; - while (*if_name == ' ') - if_name++; - break; - } - } - /* Keep looking for a colon not followed by "//". */ - } -#else - /* - * There's a space between the interface description and name, and - * the interface name shouldn't have a space in it (it doesn't, on - * UNIX systems); look backwards in the string for a space. - * - * (An interface name might, however, contain a colon in it, which - * is why we don't use the colon search on UNIX.) - */ - if_name = strrchr(if_text, ' '); - if (if_name == NULL) { - if_name = if_text; - } else { - if_name++; - } -#endif - return if_name; -} - -/* - * Keep a static pointer to the current "Capture Options" window, if - * any, so that if somebody tries to do "Capture:Start" while there's - * already a "Capture Options" window up, we just pop up the existing - * one, rather than creating a new one. - */ -static GtkWidget *cap_open_w; - -static void -set_link_type_list(GtkWidget *linktype_om, GtkWidget *entry) -{ - gchar *entry_text; - gchar *if_text; - gchar *if_name; - GList *if_list; - GList *if_entry; - if_info_t *if_info; - GList *lt_list; - int err; - char err_buf[PCAP_ERRBUF_SIZE]; - GtkWidget *lt_menu, *lt_menu_item; - GList *lt_entry; - data_link_info_t *data_link_info; - gchar *linktype_menu_label; - guint num_supported_link_types; - GtkWidget *linktype_lb = OBJECT_GET_DATA(linktype_om, E_CAP_LT_OM_LABEL_KEY); - - lt_menu = gtk_menu_new(); - entry_text = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry))); - if_text = g_strstrip(entry_text); - if_name = get_if_name(if_text); - - /* - * If the interface name is in the list of known interfaces, get - * its list of link-layer types and set the option menu to display it. - * - * If it's not, don't bother - the user might be in the middle of - * editing the list, or it might be a remote device in which case - * getting the list could take an arbitrarily-long period of time. - * The list currently won't contain any remote devices (as - * "pcap_findalldevs()" doesn't know about remote devices, and neither - * does the code we use if "pcap_findalldevs()" isn't available), but - * should contain all the local devices on which you can capture. - */ - lt_list = NULL; - if (*if_name != '\0') { - /* - * Try to get the list of known interfaces. - */ - if_list = get_interface_list(&err, err_buf); - if (if_list != NULL) { - /* - * We have the list - check it. - */ - for (if_entry = if_list; if_entry != NULL; - if_entry = g_list_next(if_entry)) { - if_info = if_entry->data; - if (strcmp(if_info->name, if_name) == 0) { - /* - * It's in the list. - * Get the list of link-layer types for it. - */ - lt_list = get_pcap_linktype_list(if_name, err_buf); - } - } - free_interface_list(if_list); - } - } - g_free(entry_text); - num_supported_link_types = 0; - for (lt_entry = lt_list; lt_entry != NULL; lt_entry = g_list_next(lt_entry)) { - data_link_info = lt_entry->data; - if (data_link_info->description != NULL) { - lt_menu_item = gtk_menu_item_new_with_label(data_link_info->description); - OBJECT_SET_DATA(lt_menu_item, E_CAP_LT_OM_KEY, linktype_om); - SIGNAL_CONNECT(lt_menu_item, "activate", select_link_type_cb, - GINT_TO_POINTER(data_link_info->dlt)); - num_supported_link_types++; - } else { - /* Not supported - tell them about it but don't let them select it. */ - linktype_menu_label = g_strdup_printf("%s (not supported)", - data_link_info->name); - lt_menu_item = gtk_menu_item_new_with_label(linktype_menu_label); - g_free(linktype_menu_label); - gtk_widget_set_sensitive(lt_menu_item, FALSE); - } - gtk_menu_append(GTK_MENU(lt_menu), lt_menu_item); - } - if (lt_list != NULL) - free_pcap_linktype_list(lt_list); - gtk_option_menu_set_menu(GTK_OPTION_MENU(linktype_om), lt_menu); - gtk_widget_set_sensitive(linktype_lb, num_supported_link_types >= 2); - gtk_widget_set_sensitive(linktype_om, num_supported_link_types >= 2); -} - - -#define TIME_UNIT_SECOND 0 -#define TIME_UNIT_MINUTE 1 -#define TIME_UNIT_HOUR 2 -#define TIME_UNIT_DAY 3 -#define MAX_TIME_UNITS 4 -static char *time_unit_name[MAX_TIME_UNITS] = { - "second(s)", - "minute(s)", - "hour(s)", - "day(s)", -}; - -static GtkWidget *time_unit_option_menu_new(guint32 value) { - GtkWidget *unit_om, *menu, *menu_item; - int i; - - unit_om=gtk_option_menu_new(); - menu=gtk_menu_new(); - for(i=0;i<MAX_TIME_UNITS;i++){ - menu_item=gtk_menu_item_new_with_label(time_unit_name[i]); - OBJECT_SET_DATA(menu_item, "time_unit", GINT_TO_POINTER(i)); - gtk_menu_append(GTK_MENU(menu), menu_item); - } - - /* the selected menu item can't be changed, once the option_menu - is created, so set the matching menu item now */ - /* days */ - if(value >= 60 * 60 * 24) { - gtk_menu_set_active(GTK_MENU(menu), TIME_UNIT_DAY); - } else { - /* hours */ - if(value >= 60 * 60) { - gtk_menu_set_active(GTK_MENU(menu), TIME_UNIT_HOUR); - } else { - /* minutes */ - if(value >= 60) { - gtk_menu_set_active(GTK_MENU(menu), TIME_UNIT_MINUTE); - } else { - /* seconds */ - gtk_menu_set_active(GTK_MENU(menu), TIME_UNIT_SECOND); - } - } - } - - gtk_option_menu_set_menu(GTK_OPTION_MENU(unit_om), menu); - - return unit_om; -} - -static guint32 time_unit_option_menu_convert_value( -guint32 value) -{ - /* days */ - if(value >= 60 * 60 * 24) { - return value / (60 * 60 * 24); - } - - /* hours */ - if(value >= 60 * 60) { - return value / (60 * 60); - } - - /* minutes */ - if(value >= 60) { - return value / 60; - } - - /* seconds */ - return value; -} - -static guint32 time_unit_option_menu_get_value( -GtkWidget *unit_om, -guint32 value) -{ - GtkWidget *menu, *menu_item; - int unit; - - menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(unit_om)); - menu_item = gtk_menu_get_active(GTK_MENU(menu)); - unit = GPOINTER_TO_INT(OBJECT_GET_DATA(menu_item, "time_unit")); - - - switch(unit) { - case(TIME_UNIT_SECOND): - return value; - break; - case(TIME_UNIT_MINUTE): - return value * 60; - break; - case(TIME_UNIT_HOUR): - return value * 60 * 60; - break; - case(TIME_UNIT_DAY): - return value * 60 * 60 * 24; - break; - default: - g_assert_not_reached(); - return 0; - } -} - - -#define SIZE_UNIT_BYTES 0 -#define SIZE_UNIT_KILOBYTES 1 -#define SIZE_UNIT_MEGABYTES 2 -#define SIZE_UNIT_GIGABYTES 3 -#define MAX_SIZE_UNITS 4 -static char *size_unit_name[MAX_SIZE_UNITS] = { - "byte(s)", - "kilobyte(s)", - "megabyte(s)", - "gigabyte(s)", -}; - -static GtkWidget *size_unit_option_menu_new(guint32 value) { - GtkWidget *unit_om, *menu, *menu_item; - int i; - - unit_om=gtk_option_menu_new(); - menu=gtk_menu_new(); - for(i=0;i<MAX_SIZE_UNITS;i++){ - menu_item=gtk_menu_item_new_with_label(size_unit_name[i]); - OBJECT_SET_DATA(menu_item, "size_unit", GINT_TO_POINTER(i)); - gtk_menu_append(GTK_MENU(menu), menu_item); - } - - /* the selected menu item can't be changed, once the option_menu - is created, so set the matching menu item now */ - /* gigabytes */ - if(value >= 1024 * 1024 * 1024) { - gtk_menu_set_active(GTK_MENU(menu), SIZE_UNIT_GIGABYTES); - } else { - /* megabytes */ - if(value >= 1024 * 1024) { - gtk_menu_set_active(GTK_MENU(menu), SIZE_UNIT_MEGABYTES); - } else { - /* kilobytes */ - if(value >= 1024) { - gtk_menu_set_active(GTK_MENU(menu), SIZE_UNIT_KILOBYTES); - } else { - /* bytes */ - gtk_menu_set_active(GTK_MENU(menu), SIZE_UNIT_BYTES); - } - } - } - - gtk_option_menu_set_menu(GTK_OPTION_MENU(unit_om), menu); - - return unit_om; -} - -static guint32 size_unit_option_menu_set_value( -guint32 value) -{ - /* gigabytes */ - if(value >= 1024 * 1024 * 1024) { - return value / (1024 * 1024 * 1024); - } - - /* megabytes */ - if(value >= 1024 * 1024) { - return value / (1024 * 1024); - } - - /* kilobytes */ - if(value >= 1024) { - return value / 1024; - } - - /* bytes */ - return value; -} - -static guint32 size_unit_option_menu_convert_value( -GtkWidget *unit_om, -guint32 value) -{ - GtkWidget *menu, *menu_item; - int unit; - - menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(unit_om)); - menu_item = gtk_menu_get_active(GTK_MENU(menu)); - unit = GPOINTER_TO_INT(OBJECT_GET_DATA(menu_item, "size_unit")); - - - switch(unit) { - case(SIZE_UNIT_BYTES): - return value; - break; - case(SIZE_UNIT_KILOBYTES): - if(value > G_MAXINT / 1024) { - return 0; - } else { - return value * 1024; - } - break; - case(SIZE_UNIT_MEGABYTES): - if(value > G_MAXINT / (1024 * 1024)) { - return 0; - } else { - return value * 1024 * 1024; - } - break; - case(SIZE_UNIT_GIGABYTES): - if(value > G_MAXINT / (1024 * 1024 * 1024)) { - return 0; - } else { - return value * 1024 * 1024 * 1024; - } - break; - default: - g_assert_not_reached(); - return 0; - } -} - - -void -capture_prep(void) -{ - GtkWidget *main_vb, - *main_hb, *left_vb, *right_vb, - - *capture_fr, *capture_vb, - *if_hb, *if_cb, *if_lb, - *linktype_hb, *linktype_lb, *linktype_om, - *snap_hb, *snap_cb, *snap_sb, *snap_lb, - *promisc_cb, - *filter_hb, *filter_bt, *filter_te, - - *file_fr, *file_vb, - *file_hb, *file_bt, *file_lb, *file_te, - *multi_tb, *multi_files_on_cb, - *ring_filesize_cb, *ring_filesize_sb, *ring_filesize_om, - *file_duration_cb, *file_duration_sb, *file_duration_om, - *ringbuffer_nbf_cb, *ringbuffer_nbf_sb, *ringbuffer_nbf_lb, - *stop_files_cb, *stop_files_sb, *stop_files_lb, - - *limit_fr, *limit_vb, *limit_tb, - *stop_packets_cb, *stop_packets_sb, *stop_packets_lb, - *stop_filesize_cb, *stop_filesize_sb, *stop_filesize_om, - *stop_duration_cb, *stop_duration_sb, *stop_duration_om, - - *display_fr, *display_vb, - *sync_cb, *auto_scroll_cb, *hide_info_cb, - - *resolv_fr, *resolv_vb, - *m_resolv_cb, *n_resolv_cb, *t_resolv_cb, - *bbox, *ok_bt, *cancel_bt, - *help_bt; -#if GTK_MAJOR_VERSION < 2 - GtkAccelGroup *accel_group; -#endif - GtkTooltips *tooltips; - GtkAdjustment *snap_adj, *ringbuffer_nbf_adj, - *stop_packets_adj, *stop_filesize_adj, *stop_duration_adj, *stop_files_adj, *ring_filesize_adj, *file_duration_adj; - GList *if_list, *combo_list; - int err; - int row; - char err_str[PCAP_ERRBUF_SIZE]; - gchar *cant_get_if_list_errstr; -#ifdef _WIN32 - GtkAdjustment *buffer_size_adj; - GtkWidget *buffer_size_lb, *buffer_size_sb; -#endif - guint32 value; - - if (cap_open_w != NULL) { - /* There's already a "Capture Options" dialog box; reactivate it. */ - reactivate_window(cap_open_w); - return; - } - -#ifdef _WIN32 - /* Is WPcap loaded? */ - if (!has_wpcap) { - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - "Unable to load WinPcap (wpcap.dll); Ethereal will not be able\n" - "to capture packets.\n\n" - "In order to capture packets, WinPcap must be installed; see\n" - "\n" - " http://winpcap.polito.it/\n" - "\n" - "or the mirror at\n" - "\n" - " http://winpcap.mirror.ethereal.com/\n" - "\n" - "or the mirror at\n" - "\n" - " http://www.mirrors.wiretapped.net/security/packet-capture/winpcap/\n" - "\n" - "for a downloadable version of WinPcap and for instructions\n" - "on how to install WinPcap."); - return; - } -#endif - - if_list = get_interface_list(&err, err_str); - if (if_list == NULL && err == CANT_GET_INTERFACE_LIST) { - cant_get_if_list_errstr = cant_get_if_list_error_message(err_str); - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", - cant_get_if_list_errstr); - g_free(cant_get_if_list_errstr); - } - - cap_open_w = dlg_window_new("Ethereal: Capture Options"); - - tooltips = gtk_tooltips_new(); - -#if GTK_MAJOR_VERSION < 2 - /* Accelerator group for the accelerators (or, as they're called in - Windows and, I think, in Motif, "mnemonics"; Alt+<key> is a mnemonic, - Ctrl+<key> is an accelerator). */ - accel_group = gtk_accel_group_new(); - gtk_window_add_accel_group(GTK_WINDOW(cap_open_w), accel_group); -#endif - - main_vb = gtk_vbox_new(FALSE, 0); - gtk_container_border_width(GTK_CONTAINER(main_vb), 5); - gtk_container_add(GTK_CONTAINER(cap_open_w), main_vb); - - /* Capture-related options frame */ - capture_fr = gtk_frame_new("Capture"); - gtk_container_add(GTK_CONTAINER(main_vb), capture_fr); - - capture_vb = gtk_vbox_new(FALSE, 3); - gtk_container_border_width(GTK_CONTAINER(capture_vb), 5); - gtk_container_add(GTK_CONTAINER(capture_fr), capture_vb); - - /* Interface row */ - if_hb = gtk_hbox_new(FALSE, 3); - gtk_container_add(GTK_CONTAINER(capture_vb), if_hb); - - if_lb = gtk_label_new("Interface:"); - gtk_box_pack_start(GTK_BOX(if_hb), if_lb, FALSE, FALSE, 6); - - if_cb = gtk_combo_new(); - combo_list = build_capture_combo_list(if_list, TRUE); - if (combo_list != NULL) - gtk_combo_set_popdown_strings(GTK_COMBO(if_cb), combo_list); - if (cfile.iface == NULL && prefs.capture_device != NULL) { - /* No interface was specified on the command line or in a previous - capture, but there is one specified in the preferences file; - make the one from the preferences file the default */ - cfile.iface = g_strdup(prefs.capture_device); - } - if (cfile.iface != NULL) - gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(if_cb)->entry), cfile.iface); - else if (combo_list != NULL) { - gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(if_cb)->entry), - (char *)combo_list->data); - } - free_capture_combo_list(combo_list); - free_interface_list(if_list); - gtk_tooltips_set_tip(tooltips, GTK_COMBO(if_cb)->entry, - "Choose which interface (network card) will be used to capture packets from. " - "Be sure to select the correct one, as it's a common mistake to select the wrong interface.", NULL); - gtk_box_pack_start(GTK_BOX(if_hb), if_cb, TRUE, TRUE, 6); - - /* Linktype row */ - linktype_hb = gtk_hbox_new(FALSE, 3); - gtk_box_pack_start(GTK_BOX(capture_vb), linktype_hb, FALSE, FALSE, 0); - - linktype_lb = gtk_label_new("Link-layer header type:"); - gtk_box_pack_start(GTK_BOX(linktype_hb), linktype_lb, FALSE, FALSE, 6); - - linktype_om = gtk_option_menu_new(); - OBJECT_SET_DATA(linktype_om, E_CAP_LT_OM_LABEL_KEY, linktype_lb); - /* Default to "use the default" */ - OBJECT_SET_DATA(linktype_om, E_CAP_OM_LT_VALUE_KEY, GINT_TO_POINTER(-1)); - set_link_type_list(linktype_om, GTK_COMBO(if_cb)->entry); - /* - * XXX - in some cases, this is "multiple link-layer header types", e.g. - * some 802.11 interfaces on FreeBSD 5.2 and later, where you can request - * fake Ethernet, 802.11, or 802.11-plus-radio-information headers. - * - * In other cases, it's "multiple link-layer types", e.g., with recent - * versions of libpcap, a DAG card on an "HDLC" WAN, where you can - * request Cisco HDLC or PPP depending on what type of traffic is going - * over the WAN, or an Ethernet interface, where you can request Ethernet - * or DOCSIS, the latter being for some Cisco cable modem equipment that - * can be configured to send raw DOCSIS frames over an Ethernet inside - * Ethernet low-level framing, for traffic capture purposes. - * - * We leave it as "multiple link-layer types" for now. - */ - gtk_tooltips_set_tip(tooltips, linktype_om, - "The selected interface supports multiple link-layer types; select the desired one.", NULL); - gtk_box_pack_start (GTK_BOX(linktype_hb), linktype_om, FALSE, FALSE, 0); - SIGNAL_CONNECT(GTK_ENTRY(GTK_COMBO(if_cb)->entry), "changed", - capture_prep_interface_changed_cb, linktype_om); - -#ifdef _WIN32 - buffer_size_lb = gtk_label_new("Buffer size:"); - gtk_box_pack_start (GTK_BOX(linktype_hb), buffer_size_lb, FALSE, FALSE, 0); - - buffer_size_adj = (GtkAdjustment *) gtk_adjustment_new((gfloat) capture_opts.buffer_size, - 1, 65535, 1.0, 10.0, 0.0); - buffer_size_sb = gtk_spin_button_new (buffer_size_adj, 0, 0); - gtk_spin_button_set_value(GTK_SPIN_BUTTON (buffer_size_sb), (gfloat) capture_opts.buffer_size); - gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (buffer_size_sb), TRUE); - WIDGET_SET_SIZE(buffer_size_sb, 80, -1); - gtk_tooltips_set_tip(tooltips, buffer_size_sb, - "The memory buffer size used while capturing. If you notice packet drops, you can try to increase this size.", NULL); - gtk_box_pack_start (GTK_BOX(linktype_hb), buffer_size_sb, FALSE, FALSE, 0); - - buffer_size_lb = gtk_label_new("megabyte(s)"); - gtk_box_pack_start (GTK_BOX(linktype_hb), buffer_size_lb, FALSE, FALSE, 0); -#endif - - /* Promiscuous mode row */ - promisc_cb = CHECK_BUTTON_NEW_WITH_MNEMONIC( - "Capture packets in _promiscuous mode", accel_group); - gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(promisc_cb), - capture_opts.promisc_mode); - gtk_tooltips_set_tip(tooltips, promisc_cb, - "Usually a network card will only capture the traffic sent to its own network address. " - "If you want to capture all traffic that the network card can \"see\", mark this option. " - "See the FAQ for some more details of capturing packets from a switched network.", NULL); - gtk_container_add(GTK_CONTAINER(capture_vb), promisc_cb); - - /* Capture length row */ - snap_hb = gtk_hbox_new(FALSE, 3); - gtk_container_add(GTK_CONTAINER(capture_vb), snap_hb); - - snap_cb = CHECK_BUTTON_NEW_WITH_MNEMONIC("_Limit each packet to", accel_group); - gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(snap_cb), - capture_opts.has_snaplen); - SIGNAL_CONNECT(snap_cb, "toggled", capture_prep_adjust_sensitivity, cap_open_w); - gtk_tooltips_set_tip(tooltips, snap_cb, - "Limit the maximum number of bytes to be captured from each packet. This size includes the " - "link-layer header and all subsequent headers. ", NULL); - gtk_box_pack_start(GTK_BOX(snap_hb), snap_cb, FALSE, FALSE, 0); - - snap_adj = (GtkAdjustment *) gtk_adjustment_new((gfloat) capture_opts.snaplen, - MIN_PACKET_SIZE, WTAP_MAX_PACKET_SIZE, 1.0, 10.0, 0.0); - snap_sb = gtk_spin_button_new (snap_adj, 0, 0); - gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (snap_sb), TRUE); - WIDGET_SET_SIZE(snap_sb, 80, -1); - gtk_box_pack_start (GTK_BOX(snap_hb), snap_sb, FALSE, FALSE, 0); - - snap_lb = gtk_label_new("bytes"); - gtk_misc_set_alignment(GTK_MISC(snap_lb), 0, 0.5); - gtk_box_pack_start(GTK_BOX(snap_hb), snap_lb, FALSE, FALSE, 0); - - /* Filter row */ - filter_hb = gtk_hbox_new(FALSE, 3); - gtk_box_pack_start(GTK_BOX(capture_vb), filter_hb, FALSE, FALSE, 0); - - filter_bt = BUTTON_NEW_FROM_STOCK(ETHEREAL_STOCK_CAPTURE_FILTER_ENTRY); - SIGNAL_CONNECT(filter_bt, "clicked", capture_filter_construct_cb, NULL); - SIGNAL_CONNECT(filter_bt, "destroy", filter_button_destroy_cb, NULL); - gtk_tooltips_set_tip(tooltips, filter_bt, - "Select a capture filter to reduce the amount of packets to be captured. " - "See \"Capture Filters\" in the online help for further information how to use it.", - NULL); - gtk_box_pack_start(GTK_BOX(filter_hb), filter_bt, FALSE, FALSE, 3); - - filter_te = gtk_entry_new(); - if (cfile.cfilter) gtk_entry_set_text(GTK_ENTRY(filter_te), cfile.cfilter); - OBJECT_SET_DATA(filter_bt, E_FILT_TE_PTR_KEY, filter_te); - gtk_tooltips_set_tip(tooltips, filter_te, - "Enter a capture filter to reduce the amount of packets to be captured. " - "See \"Capture Filters\" in the online help for further information how to use it.", - NULL); - gtk_box_pack_start(GTK_BOX(filter_hb), filter_te, TRUE, TRUE, 3); - - main_hb = gtk_hbox_new(FALSE, 5); - gtk_container_border_width(GTK_CONTAINER(main_hb), 0); - gtk_container_add(GTK_CONTAINER(main_vb), main_hb); - - left_vb = gtk_vbox_new(FALSE, 0); - gtk_container_border_width(GTK_CONTAINER(left_vb), 0); - gtk_box_pack_start(GTK_BOX(main_hb), left_vb, TRUE, TRUE, 0); - - right_vb = gtk_vbox_new(FALSE, 0); - gtk_container_border_width(GTK_CONTAINER(right_vb), 0); - gtk_box_pack_start(GTK_BOX(main_hb), right_vb, FALSE, FALSE, 0); - - - /* Capture file-related options frame */ - file_fr = gtk_frame_new("Capture File(s)"); - gtk_container_add(GTK_CONTAINER(left_vb), file_fr); - - file_vb = gtk_vbox_new(FALSE, 3); - gtk_container_border_width(GTK_CONTAINER(file_vb), 5); - gtk_container_add(GTK_CONTAINER(file_fr), file_vb); - - /* File row */ - file_hb = gtk_hbox_new(FALSE, 3); - gtk_box_pack_start(GTK_BOX(file_vb), file_hb, FALSE, FALSE, 0); - - file_lb = gtk_label_new("File:"); - gtk_box_pack_start(GTK_BOX(file_hb), file_lb, FALSE, FALSE, 3); - - file_te = gtk_entry_new(); - gtk_tooltips_set_tip(tooltips, file_te, - "Enter the file name to which captured data will be written. " - "If you don't enter something here, a temporary file will be used.", - NULL); - gtk_box_pack_start(GTK_BOX(file_hb), file_te, TRUE, TRUE, 3); - - file_bt = BUTTON_NEW_FROM_STOCK(ETHEREAL_STOCK_BROWSE); - gtk_tooltips_set_tip(tooltips, file_bt, - "Select a file to which captured data will be written, " - "instead of entering the file name directly. ", - NULL); - gtk_box_pack_start(GTK_BOX(file_hb), file_bt, FALSE, FALSE, 3); - - SIGNAL_CONNECT(file_bt, "clicked", capture_prep_file_cb, file_te); - - /* multiple files table */ - multi_tb = gtk_table_new(5, 3, FALSE); - gtk_table_set_row_spacings(GTK_TABLE(multi_tb), 1); - gtk_table_set_col_spacings(GTK_TABLE(multi_tb), 3); - gtk_box_pack_start(GTK_BOX(file_vb), multi_tb, FALSE, FALSE, 0); - row = 0; - - /* multiple files row */ - multi_files_on_cb = CHECK_BUTTON_NEW_WITH_MNEMONIC("Use _multiple files", accel_group); - gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(multi_files_on_cb), - capture_opts.multi_files_on); - SIGNAL_CONNECT(multi_files_on_cb, "toggled", capture_prep_adjust_sensitivity, - cap_open_w); - gtk_tooltips_set_tip(tooltips, multi_files_on_cb, - "Instead of using a single capture file, multiple files will be created. " - "The generated file names will contain an incrementing number and the start time of the capture.", NULL); - gtk_table_attach_defaults(GTK_TABLE(multi_tb), multi_files_on_cb, 0, 1, row, row+1); - row++; - - /* Ring buffer filesize row */ - ring_filesize_cb = gtk_check_button_new_with_label("Next file every"); - gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(ring_filesize_cb), - capture_opts.has_autostop_filesize); - SIGNAL_CONNECT(ring_filesize_cb, "toggled", capture_prep_adjust_sensitivity, cap_open_w); - gtk_tooltips_set_tip(tooltips, ring_filesize_cb, - "If the selected file size is exceeded, capturing switches to the next file.", - NULL); - gtk_table_attach_defaults(GTK_TABLE(multi_tb), ring_filesize_cb, 0, 1, row, row+1); - - ring_filesize_adj = (GtkAdjustment *) gtk_adjustment_new(0.0, - 1, (gfloat)INT_MAX, 1.0, 10.0, 0.0); - ring_filesize_sb = gtk_spin_button_new (ring_filesize_adj, 0, 0); - gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (ring_filesize_sb), TRUE); - WIDGET_SET_SIZE(ring_filesize_sb, 80, -1); - gtk_table_attach_defaults(GTK_TABLE(multi_tb), ring_filesize_sb, 1, 2, row, row+1); - - ring_filesize_om = size_unit_option_menu_new(capture_opts.autostop_filesize); - gtk_table_attach_defaults(GTK_TABLE(multi_tb), ring_filesize_om, 2, 3, row, row+1); - - value = size_unit_option_menu_set_value(capture_opts.autostop_filesize); - gtk_adjustment_set_value(ring_filesize_adj, (gfloat) value); - - row++; - - /* Ring buffer duration row */ - file_duration_cb = gtk_check_button_new_with_label("Next file every"); - gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(file_duration_cb), - capture_opts.has_file_duration); - SIGNAL_CONNECT(file_duration_cb, "toggled", - capture_prep_adjust_sensitivity, cap_open_w); - gtk_tooltips_set_tip(tooltips, file_duration_cb, - "If the selected duration is exceeded, capturing switches to the next file.", - NULL); - gtk_table_attach_defaults(GTK_TABLE(multi_tb), file_duration_cb, 0, 1, row, row+1); - - file_duration_adj = (GtkAdjustment *)gtk_adjustment_new(0.0, - 1, (gfloat)INT_MAX, 1.0, 10.0, 0.0); - file_duration_sb = gtk_spin_button_new (file_duration_adj, 0, 0); - gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (file_duration_sb), TRUE); - WIDGET_SET_SIZE(file_duration_sb, 80, -1); - gtk_table_attach_defaults(GTK_TABLE(multi_tb), file_duration_sb, 1, 2, row, row+1); - - file_duration_om = time_unit_option_menu_new(capture_opts.file_duration); - gtk_table_attach_defaults(GTK_TABLE(multi_tb), file_duration_om, 2, 3, row, row+1); - - value = time_unit_option_menu_convert_value(capture_opts.file_duration); - gtk_adjustment_set_value(file_duration_adj, (gfloat) value); - row++; - - /* Ring buffer files row */ - ringbuffer_nbf_cb = gtk_check_button_new_with_label("Ring buffer with"); - gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(ringbuffer_nbf_cb), - capture_opts.has_ring_num_files); - SIGNAL_CONNECT(ringbuffer_nbf_cb, "toggled", capture_prep_adjust_sensitivity, cap_open_w); - gtk_tooltips_set_tip(tooltips, ringbuffer_nbf_cb, - "After capturing has switched to the next file and the given number of files has exceeded, " - "the oldest file will be removed.", - NULL); - gtk_table_attach_defaults(GTK_TABLE(multi_tb), ringbuffer_nbf_cb, 0, 1, row, row+1); - - ringbuffer_nbf_adj = (GtkAdjustment *) gtk_adjustment_new((gfloat) capture_opts.ring_num_files, - 2/*RINGBUFFER_MIN_NUM_FILES*/, RINGBUFFER_MAX_NUM_FILES, 1.0, 10.0, 0.0); - ringbuffer_nbf_sb = gtk_spin_button_new (ringbuffer_nbf_adj, 0, 0); - gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (ringbuffer_nbf_sb), TRUE); - WIDGET_SET_SIZE(ringbuffer_nbf_sb, 80, -1); - SIGNAL_CONNECT(ringbuffer_nbf_sb, "changed", capture_prep_adjust_sensitivity, cap_open_w); - gtk_table_attach_defaults(GTK_TABLE(multi_tb), ringbuffer_nbf_sb, 1, 2, row, row+1); - - ringbuffer_nbf_lb = gtk_label_new("files"); - gtk_misc_set_alignment(GTK_MISC(ringbuffer_nbf_lb), 0, 0.5); - gtk_table_attach_defaults(GTK_TABLE(multi_tb), ringbuffer_nbf_lb, 2, 3, row, row+1); - row++; - - /* Files row */ - stop_files_cb = gtk_check_button_new_with_label("Stop capture after"); - gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(stop_files_cb), - capture_opts.has_autostop_files); - SIGNAL_CONNECT(stop_files_cb, "toggled", capture_prep_adjust_sensitivity, cap_open_w); - gtk_tooltips_set_tip(tooltips, stop_files_cb, - "Stop capturing after the given number of \"file switches\" have been done.", NULL); - gtk_table_attach_defaults(GTK_TABLE(multi_tb), stop_files_cb, 0, 1, row, row+1); - - stop_files_adj = (GtkAdjustment *) gtk_adjustment_new((gfloat)capture_opts.autostop_files, - 1, (gfloat)INT_MAX, 1.0, 10.0, 0.0); - stop_files_sb = gtk_spin_button_new (stop_files_adj, 0, 0); - gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (stop_files_sb), TRUE); - WIDGET_SET_SIZE(stop_files_sb, 80, -1); - gtk_table_attach_defaults(GTK_TABLE(multi_tb), stop_files_sb, 1, 2, row, row+1); - - stop_files_lb = gtk_label_new("file(s)"); - gtk_misc_set_alignment(GTK_MISC(stop_files_lb), 0, 0.5); - gtk_table_attach_defaults(GTK_TABLE(multi_tb), stop_files_lb, 2, 3, row, row+1); - row++; - - /* Capture limits frame */ - limit_fr = gtk_frame_new("Stop Capture ..."); - gtk_container_add(GTK_CONTAINER(left_vb), limit_fr); - - limit_vb = gtk_vbox_new(FALSE, 3); - gtk_container_border_width(GTK_CONTAINER(limit_vb), 5); - gtk_container_add(GTK_CONTAINER(limit_fr), limit_vb); - - /* limits table */ - limit_tb = gtk_table_new(3, 3, FALSE); - gtk_table_set_row_spacings(GTK_TABLE(limit_tb), 1); - gtk_table_set_col_spacings(GTK_TABLE(limit_tb), 3); - gtk_box_pack_start(GTK_BOX(limit_vb), limit_tb, FALSE, FALSE, 0); - row = 0; - - /* Packet count row */ - stop_packets_cb = gtk_check_button_new_with_label("... after"); - gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(stop_packets_cb), - capture_opts.has_autostop_packets); - SIGNAL_CONNECT(stop_packets_cb, "toggled", capture_prep_adjust_sensitivity, cap_open_w); - gtk_tooltips_set_tip(tooltips, stop_packets_cb, - "Stop capturing after the given number of packets have been captured.", NULL); - gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_packets_cb, 0, 1, row, row+1); - - stop_packets_adj = (GtkAdjustment *) gtk_adjustment_new((gfloat)capture_opts.autostop_packets, - 1, (gfloat)INT_MAX, 1.0, 10.0, 0.0); - stop_packets_sb = gtk_spin_button_new (stop_packets_adj, 0, 0); - gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (stop_packets_sb), TRUE); - WIDGET_SET_SIZE(stop_packets_sb, 80, -1); - gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_packets_sb, 1, 2, row, row+1); - - stop_packets_lb = gtk_label_new("packet(s)"); - gtk_misc_set_alignment(GTK_MISC(stop_packets_lb), 0, 0.5); - gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_packets_lb, 2, 3, row, row+1); - row++; - - /* Filesize row */ - stop_filesize_cb = gtk_check_button_new_with_label("... after"); - gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(stop_filesize_cb), - capture_opts.has_autostop_filesize); - SIGNAL_CONNECT(stop_filesize_cb, "toggled", capture_prep_adjust_sensitivity, cap_open_w); - gtk_tooltips_set_tip(tooltips, stop_filesize_cb, - "Stop capturing after the given amount of capture data has been captured.", NULL); - gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_filesize_cb, 0, 1, row, row+1); - - stop_filesize_adj = (GtkAdjustment *) gtk_adjustment_new(0.0, - 1, (gfloat)INT_MAX, 1.0, 10.0, 0.0); - stop_filesize_sb = gtk_spin_button_new (stop_filesize_adj, 0, 0); - gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (stop_filesize_sb), TRUE); - WIDGET_SET_SIZE(stop_filesize_sb, 80, -1); - gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_filesize_sb, 1, 2, row, row+1); - - stop_filesize_om = size_unit_option_menu_new(capture_opts.autostop_filesize); - gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_filesize_om, 2, 3, row, row+1); - - value = size_unit_option_menu_set_value(capture_opts.autostop_filesize); - gtk_adjustment_set_value(stop_filesize_adj, (gfloat) value); - - row++; - - /* Duration row */ - stop_duration_cb = gtk_check_button_new_with_label("... after"); - gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(stop_duration_cb), - capture_opts.has_autostop_duration); - SIGNAL_CONNECT(stop_duration_cb, "toggled", capture_prep_adjust_sensitivity, cap_open_w); - gtk_tooltips_set_tip(tooltips, stop_duration_cb, - "Stop capturing after the given time is exceeded.", NULL); - gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_duration_cb, 0, 1, row, row+1); - - stop_duration_adj = (GtkAdjustment *) gtk_adjustment_new(0.0, - 1, (gfloat)INT_MAX, 1.0, 10.0, 0.0); - stop_duration_sb = gtk_spin_button_new (stop_duration_adj, 0, 0); - gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (stop_duration_sb), TRUE); - WIDGET_SET_SIZE(stop_duration_sb, 80, -1); - gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_duration_sb, 1, 2, row, row+1); - - stop_duration_om = time_unit_option_menu_new(capture_opts.autostop_duration); - gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_duration_om, 2, 3, row, row+1); - - value = time_unit_option_menu_convert_value(capture_opts.autostop_duration); - gtk_adjustment_set_value(stop_duration_adj, (gfloat) value); - row++; - - /* Display-related options frame */ - display_fr = gtk_frame_new("Display Options"); - gtk_container_add(GTK_CONTAINER(right_vb), display_fr); - - display_vb = gtk_vbox_new(FALSE, 0); - gtk_container_border_width(GTK_CONTAINER(display_vb), 5); - gtk_container_add(GTK_CONTAINER(display_fr), display_vb); - - /* "Update display in real time" row */ - sync_cb = CHECK_BUTTON_NEW_WITH_MNEMONIC( - "_Update list of packets in real time", accel_group); - gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(sync_cb), - capture_opts.sync_mode); - SIGNAL_CONNECT(sync_cb, "toggled", capture_prep_adjust_sensitivity, cap_open_w); - gtk_tooltips_set_tip(tooltips, sync_cb, - "Using this option will show the captured packets immediately on the main screen. " - "Please note: this will slow down capturing, so increased packet drops might appear.", NULL); - gtk_container_add(GTK_CONTAINER(display_vb), sync_cb); - - /* "Auto-scroll live update" row */ - auto_scroll_cb = CHECK_BUTTON_NEW_WITH_MNEMONIC( - "_Automatic scrolling in live capture", accel_group); - gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(auto_scroll_cb), auto_scroll_live); - gtk_tooltips_set_tip(tooltips, auto_scroll_cb, - "This will scroll the \"Packet List\" automatically to the latest captured packet, " - "when the \"Update List of packets in real time\" option is used.", NULL); - gtk_container_add(GTK_CONTAINER(display_vb), auto_scroll_cb); - - /* "Hide capture info" row */ - hide_info_cb = CHECK_BUTTON_NEW_WITH_MNEMONIC( - "_Hide capture info dialog", accel_group); - gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(hide_info_cb), !capture_opts.show_info); - gtk_tooltips_set_tip(tooltips, hide_info_cb, - "Hide the capture info dialog while capturing.", NULL); - gtk_container_add(GTK_CONTAINER(display_vb), hide_info_cb); - - /* Name Resolution frame */ - resolv_fr = gtk_frame_new("Name Resolution"); - gtk_container_add(GTK_CONTAINER(right_vb), resolv_fr); - - resolv_vb = gtk_vbox_new(FALSE, 0); - gtk_container_border_width(GTK_CONTAINER(resolv_vb), 5); - gtk_container_add(GTK_CONTAINER(resolv_fr), resolv_vb); - - m_resolv_cb = CHECK_BUTTON_NEW_WITH_MNEMONIC( - "Enable _MAC name resolution", accel_group); - gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(m_resolv_cb), - g_resolv_flags & RESOLV_MAC); - gtk_tooltips_set_tip(tooltips, m_resolv_cb, - "Perform MAC layer name resolution while capturing.", NULL); - gtk_container_add(GTK_CONTAINER(resolv_vb), m_resolv_cb); - - n_resolv_cb = CHECK_BUTTON_NEW_WITH_MNEMONIC( - "Enable _network name resolution", accel_group); - gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(n_resolv_cb), - g_resolv_flags & RESOLV_NETWORK); - gtk_tooltips_set_tip(tooltips, n_resolv_cb, - "Perform network layer name resolution while capturing.", NULL); - gtk_container_add(GTK_CONTAINER(resolv_vb), n_resolv_cb); - - t_resolv_cb = CHECK_BUTTON_NEW_WITH_MNEMONIC( - "Enable _transport name resolution", accel_group); - gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(t_resolv_cb), - g_resolv_flags & RESOLV_TRANSPORT); - gtk_tooltips_set_tip(tooltips, t_resolv_cb, - "Perform transport layer name resolution while capturing.", NULL); - gtk_container_add(GTK_CONTAINER(resolv_vb), t_resolv_cb); - - /* Button row: OK and cancel buttons */ - bbox = dlg_button_row_new(GTK_STOCK_OK, GTK_STOCK_CANCEL, GTK_STOCK_HELP, NULL); - gtk_box_pack_start(GTK_BOX(main_vb), bbox, FALSE, FALSE, 5); - - ok_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_OK); - SIGNAL_CONNECT(ok_bt, "clicked", capture_prep_ok_cb, cap_open_w); - gtk_tooltips_set_tip(tooltips, ok_bt, - "Start the capture process.", NULL); - - cancel_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_CANCEL); - gtk_tooltips_set_tip(tooltips, cancel_bt, - "Cancel and exit dialog.", NULL); - window_set_cancel_button(cap_open_w, cancel_bt, window_cancel_button_cb); - - help_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_HELP); - gtk_tooltips_set_tip(tooltips, help_bt, - "Show help about capturing.", NULL); - SIGNAL_CONNECT(help_bt, "clicked", help_topic_cb, "Capturing"); - - gtk_widget_grab_default(ok_bt); - - /* Attach pointers to needed widgets to the capture prefs window/object */ - OBJECT_SET_DATA(cap_open_w, E_CAP_IFACE_KEY, if_cb); - OBJECT_SET_DATA(cap_open_w, E_CAP_SNAP_CB_KEY, snap_cb); - OBJECT_SET_DATA(cap_open_w, E_CAP_SNAP_SB_KEY, snap_sb); - OBJECT_SET_DATA(cap_open_w, E_CAP_LT_OM_KEY, linktype_om); -#ifdef _WIN32 - OBJECT_SET_DATA(cap_open_w, E_CAP_BUFFER_SIZE_SB_KEY, buffer_size_sb); -#endif - OBJECT_SET_DATA(cap_open_w, E_CAP_PROMISC_KEY, promisc_cb); - OBJECT_SET_DATA(cap_open_w, E_CAP_FILT_KEY, filter_te); - OBJECT_SET_DATA(cap_open_w, E_CAP_FILE_TE_KEY, file_te); - OBJECT_SET_DATA(cap_open_w, E_CAP_MULTI_FILES_ON_CB_KEY, multi_files_on_cb); - OBJECT_SET_DATA(cap_open_w, E_CAP_RING_NBF_CB_KEY, ringbuffer_nbf_cb); - OBJECT_SET_DATA(cap_open_w, E_CAP_RING_NBF_SB_KEY, ringbuffer_nbf_sb); - OBJECT_SET_DATA(cap_open_w, E_CAP_RING_NBF_LB_KEY, ringbuffer_nbf_lb); - OBJECT_SET_DATA(cap_open_w, E_CAP_RING_FILESIZE_CB_KEY, ring_filesize_cb); - OBJECT_SET_DATA(cap_open_w, E_CAP_RING_FILESIZE_SB_KEY, ring_filesize_sb); - OBJECT_SET_DATA(cap_open_w, E_CAP_RING_FILESIZE_OM_KEY, ring_filesize_om); - OBJECT_SET_DATA(cap_open_w, E_CAP_FILE_DURATION_CB_KEY, file_duration_cb); - OBJECT_SET_DATA(cap_open_w, E_CAP_FILE_DURATION_SB_KEY, file_duration_sb); - OBJECT_SET_DATA(cap_open_w, E_CAP_FILE_DURATION_OM_KEY, file_duration_om); - OBJECT_SET_DATA(cap_open_w, E_CAP_SYNC_KEY, sync_cb); - OBJECT_SET_DATA(cap_open_w, E_CAP_AUTO_SCROLL_KEY, auto_scroll_cb); - OBJECT_SET_DATA(cap_open_w, E_CAP_HIDE_INFO_KEY, hide_info_cb); - OBJECT_SET_DATA(cap_open_w, E_CAP_STOP_PACKETS_CB_KEY, stop_packets_cb); - OBJECT_SET_DATA(cap_open_w, E_CAP_STOP_PACKETS_SB_KEY, stop_packets_sb); - OBJECT_SET_DATA(cap_open_w, E_CAP_STOP_PACKETS_LB_KEY, stop_packets_lb); - OBJECT_SET_DATA(cap_open_w, E_CAP_STOP_FILESIZE_CB_KEY, stop_filesize_cb); - OBJECT_SET_DATA(cap_open_w, E_CAP_STOP_FILESIZE_SB_KEY, stop_filesize_sb); - OBJECT_SET_DATA(cap_open_w, E_CAP_STOP_FILESIZE_OM_KEY, stop_filesize_om); - OBJECT_SET_DATA(cap_open_w, E_CAP_STOP_DURATION_CB_KEY, stop_duration_cb); - OBJECT_SET_DATA(cap_open_w, E_CAP_STOP_DURATION_SB_KEY, stop_duration_sb); - OBJECT_SET_DATA(cap_open_w, E_CAP_STOP_DURATION_OM_KEY, stop_duration_om); - OBJECT_SET_DATA(cap_open_w, E_CAP_STOP_FILES_CB_KEY, stop_files_cb); - OBJECT_SET_DATA(cap_open_w, E_CAP_STOP_FILES_SB_KEY, stop_files_sb); - OBJECT_SET_DATA(cap_open_w, E_CAP_STOP_FILES_LB_KEY, stop_files_lb); - OBJECT_SET_DATA(cap_open_w, E_CAP_M_RESOLVE_KEY, m_resolv_cb); - OBJECT_SET_DATA(cap_open_w, E_CAP_N_RESOLVE_KEY, n_resolv_cb); - OBJECT_SET_DATA(cap_open_w, E_CAP_T_RESOLVE_KEY, t_resolv_cb); - - /* Set the sensitivity of various widgets as per the settings of other - widgets. */ - capture_prep_adjust_sensitivity(NULL, cap_open_w); - - /* Catch the "activate" signal on the text - entries, so that if the user types Return there, we act as if the - "OK" button had been selected, as happens if Return is typed if some - widget that *doesn't* handle the Return key has the input focus. */ - dlg_set_activate(GTK_COMBO(if_cb)->entry, ok_bt); - dlg_set_activate(filter_te, ok_bt); - dlg_set_activate(file_te, ok_bt); - - /* XXX - why does not - - gtk_widget_grab_focus(if_cb); - - give the initial focus to the "Interface" combo box? - - Or should I phrase that as "why does GTK+ continually frustrate - attempts to make GUIs driveable from the keyboard?" We have to - go catch the activate signal on every single GtkEntry widget - (rather than having widgets whose activate signal is *not* - caught not catch the Return keystroke, so that it passes on, - ultimately, to the window, which can activate the default - widget, i.e. the "OK" button); we have to catch the "key_press_event" - signal and have the handler check for ESC, so that we can have ESC - activate the "Cancel" button; in order to support Alt+<key> mnemonics - for buttons and the like, we may have to construct an accelerator - group by hand and set up the accelerators by hand (if that even - works - I've not tried it yet); we have to do a "gtk_widget_grab_focus()" - to keep some container widget from getting the initial focus, so that - you don't have to tab into the first widget in order to start typing - in it; and it now appears that you simply *can't* make a combo box - get the initial focus, at least not in the obvious fashion. Sigh.... */ - - SIGNAL_CONNECT(cap_open_w, "delete_event", window_delete_event_cb, NULL); - SIGNAL_CONNECT(cap_open_w, "destroy", capture_prep_destroy_cb, NULL); - - gtk_widget_show_all(cap_open_w); - window_present(cap_open_w); -} - -static void -capture_prep_answered_cb(gpointer dialog _U_, gint btn, gpointer data) -{ - switch(btn) { - case(ESD_BTN_SAVE): - /* save file first */ - file_save_as_cmd(after_save_capture_dialog, data); - break; - case(ESD_BTN_DONT_SAVE): - capture_prep(); - break; - case(ESD_BTN_CANCEL): - break; - default: - g_assert_not_reached(); - } -} - -void -capture_prep_cb(GtkWidget *w _U_, gpointer d _U_) -{ - gpointer dialog; - - if((cfile.state != FILE_CLOSED) && !cfile.user_saved && prefs.gui_ask_unsaved) { - /* user didn't saved his current file, ask him */ - dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_SAVE_DONTSAVE_CANCEL, - PRIMARY_TEXT_START "Save capture file before starting a new capture?" PRIMARY_TEXT_END "\n\n" - "If you start a new capture without saving, your current capture data will\nbe discarded."); - simple_dialog_set_cb(dialog, capture_prep_answered_cb, NULL); - } else { - /* unchanged file, just capture a new one */ - capture_prep(); - } -} - -static void -select_link_type_cb(GtkWidget *w, gpointer data) -{ - int new_linktype = GPOINTER_TO_INT(data); - GtkWidget *linktype_om = OBJECT_GET_DATA(w, E_CAP_LT_OM_KEY); - int old_linktype = GPOINTER_TO_INT(OBJECT_GET_DATA(linktype_om, E_CAP_OM_LT_VALUE_KEY)); - - if (old_linktype != new_linktype) - OBJECT_SET_DATA(linktype_om, E_CAP_OM_LT_VALUE_KEY, GINT_TO_POINTER(new_linktype)); -} - -static void -capture_prep_file_cb(GtkWidget *file_bt, GtkWidget *file_te) -{ - file_selection_browse(file_bt, file_te, "Ethereal: Specify a Capture File", FILE_SELECTION_OPEN); -} - - -static void -capture_prep_ok_cb(GtkWidget *ok_bt _U_, gpointer parent_w) { - GtkWidget *if_cb, *snap_cb, *snap_sb, *promisc_cb, *filter_te, - *file_te, *multi_files_on_cb, *ringbuffer_nbf_sb, *ringbuffer_nbf_cb, - *linktype_om, *sync_cb, *auto_scroll_cb, *hide_info_cb, - *stop_packets_cb, *stop_packets_sb, - *stop_filesize_cb, *stop_filesize_sb, *stop_filesize_om, - *stop_duration_cb, *stop_duration_sb, *stop_duration_om, - *ring_filesize_cb, *ring_filesize_sb, *ring_filesize_om, - *file_duration_cb, *file_duration_sb, *file_duration_om, - *stop_files_cb, *stop_files_sb, - *m_resolv_cb, *n_resolv_cb, *t_resolv_cb; -#ifdef _WIN32 - GtkWidget *buffer_size_sb; -#endif - gchar *entry_text; - gchar *if_text; - gchar *if_name; - const gchar *filter_text; - gchar *save_file; - const gchar *g_save_file; - gchar *cf_name; - gchar *dirname; - gint32 tmp; - - if_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_IFACE_KEY); - snap_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_SNAP_CB_KEY); - snap_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_SNAP_SB_KEY); - linktype_om = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_LT_OM_KEY); -#ifdef _WIN32 - buffer_size_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_BUFFER_SIZE_SB_KEY); -#endif - promisc_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_PROMISC_KEY); - filter_te = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_FILT_KEY); - file_te = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_FILE_TE_KEY); - multi_files_on_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_MULTI_FILES_ON_CB_KEY); - ringbuffer_nbf_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_RING_NBF_CB_KEY); - ringbuffer_nbf_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_RING_NBF_SB_KEY); - ring_filesize_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_RING_FILESIZE_CB_KEY); - ring_filesize_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_RING_FILESIZE_SB_KEY); - ring_filesize_om = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_RING_FILESIZE_OM_KEY); - file_duration_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_FILE_DURATION_CB_KEY); - file_duration_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_FILE_DURATION_SB_KEY); - file_duration_om = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_FILE_DURATION_OM_KEY); - sync_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_SYNC_KEY); - auto_scroll_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_AUTO_SCROLL_KEY); - hide_info_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_HIDE_INFO_KEY); - stop_packets_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_PACKETS_CB_KEY); - stop_packets_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_PACKETS_SB_KEY); - stop_filesize_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_FILESIZE_CB_KEY); - stop_filesize_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_FILESIZE_SB_KEY); - stop_filesize_om = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_FILESIZE_OM_KEY); - stop_duration_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_DURATION_CB_KEY); - stop_duration_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_DURATION_SB_KEY); - stop_duration_om = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_DURATION_OM_KEY); - stop_files_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_FILES_CB_KEY); - stop_files_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_FILES_SB_KEY); - m_resolv_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_M_RESOLVE_KEY); - n_resolv_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_N_RESOLVE_KEY); - t_resolv_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_T_RESOLVE_KEY); - - entry_text = - g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(if_cb)->entry))); - if_text = g_strstrip(entry_text); - if_name = get_if_name(if_text); - if (*if_name == '\0') { - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - "You didn't specify an interface on which to capture packets."); - g_free(entry_text); - return; - } - if (cfile.iface) - g_free(cfile.iface); - cfile.iface = g_strdup(if_name); - g_free(entry_text); - - capture_opts.linktype = - GPOINTER_TO_INT(OBJECT_GET_DATA(linktype_om, E_CAP_OM_LT_VALUE_KEY)); - -#ifdef _WIN32 - capture_opts.buffer_size = - gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(buffer_size_sb)); -#endif - - capture_opts.has_snaplen = - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(snap_cb)); - if (capture_opts.has_snaplen) { - capture_opts.snaplen = - gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(snap_sb)); - if (capture_opts.snaplen < 1) - capture_opts.snaplen = WTAP_MAX_PACKET_SIZE; - else if (capture_opts.snaplen < MIN_PACKET_SIZE) - capture_opts.snaplen = MIN_PACKET_SIZE; - } - - capture_opts.promisc_mode = - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(promisc_cb)); - - /* XXX - don't try to get clever and set "cfile.filter" to NULL if the - filter string is empty, as an indication that we don't have a filter - and thus don't have to set a filter when capturing - the version of - libpcap in Red Hat Linux 6.1, and versions based on later patches - in that series, don't bind the AF_PACKET socket to an interface - until a filter is set, which means they aren't bound at all if - no filter is set, which means no packets arrive as input on that - socket, which means Ethereal never sees any packets. */ - filter_text = gtk_entry_get_text(GTK_ENTRY(filter_te)); - if (cfile.cfilter) - g_free(cfile.cfilter); - g_assert(filter_text != NULL); - cfile.cfilter = g_strdup(filter_text); - - g_save_file = gtk_entry_get_text(GTK_ENTRY(file_te)); - if (g_save_file && g_save_file[0]) { - /* User specified a file to which the capture should be written. */ - save_file = g_strdup(g_save_file); - /* Save the directory name for future file dialogs. */ - cf_name = g_strdup(g_save_file); - dirname = get_dirname(cf_name); /* Overwrites cf_name */ - set_last_open_dir(dirname); - g_free(cf_name); - } else { - /* User didn't specify a file; save to a temporary file. */ - save_file = NULL; - } - - capture_opts.has_autostop_packets = - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_packets_cb)); - if (capture_opts.has_autostop_packets) - capture_opts.autostop_packets = - gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(stop_packets_sb)); - - capture_opts.has_autostop_duration = - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_duration_cb)); - if (capture_opts.has_autostop_duration) { - capture_opts.autostop_duration = - gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(stop_duration_sb)); - capture_opts.autostop_duration = - time_unit_option_menu_get_value(stop_duration_om, capture_opts.autostop_duration); - } - - capture_opts.sync_mode = - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(sync_cb)); - - auto_scroll_live = - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(auto_scroll_cb)); - - capture_opts.show_info = - !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(hide_info_cb)); - - g_resolv_flags |= g_resolv_flags & RESOLV_CONCURRENT; - if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m_resolv_cb))) - g_resolv_flags |= RESOLV_MAC; - if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(n_resolv_cb))) - g_resolv_flags |= RESOLV_NETWORK; - if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t_resolv_cb))) - g_resolv_flags |= RESOLV_TRANSPORT; - - capture_opts.has_ring_num_files = - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ringbuffer_nbf_cb)); - - capture_opts.ring_num_files = - gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(ringbuffer_nbf_sb)); - if (capture_opts.ring_num_files > RINGBUFFER_MAX_NUM_FILES) - capture_opts.ring_num_files = RINGBUFFER_MAX_NUM_FILES; -#if RINGBUFFER_MIN_NUM_FILES > 0 - else if (capture_opts.ring_num_files < RINGBUFFER_MIN_NUM_FILES) - capture_opts.ring_num_files = RINGBUFFER_MIN_NUM_FILES; -#endif - - capture_opts.multi_files_on = - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(multi_files_on_cb)); - - if(capture_opts.sync_mode) - capture_opts.multi_files_on = FALSE; - - if (capture_opts.multi_files_on) { - capture_opts.has_autostop_filesize = - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ring_filesize_cb)); - if (capture_opts.has_autostop_filesize) { - tmp = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(ring_filesize_sb)); - tmp = size_unit_option_menu_convert_value(ring_filesize_om, tmp); - if(tmp != 0) { - capture_opts.autostop_filesize = tmp; - } else { - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - PRIMARY_TEXT_START "Multiple files: Requested filesize too large!\n\n" PRIMARY_TEXT_END - "The setting \"Next file every x byte(s)\" can't be greater than %u bytes (2GB).", G_MAXINT); - return; - } - } - - /* test if the settings are ok for a ringbuffer */ - if (save_file == NULL) { - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - PRIMARY_TEXT_START "Multiple files: No capture file name given!\n\n" PRIMARY_TEXT_END - "You must specify a filename if you want to use multiple files."); - return; - } else if (!capture_opts.has_autostop_filesize) { - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - PRIMARY_TEXT_START "Multiple files: No file limit given!\n\n" PRIMARY_TEXT_END - "You must specify a file size at which is switched to the next capture file\n" - "if you want to use multiple files."); - g_free(save_file); - return; - } - } else { - capture_opts.has_autostop_filesize = - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_filesize_cb)); - if (capture_opts.has_autostop_filesize) { - tmp = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(stop_filesize_sb)); - tmp = size_unit_option_menu_convert_value(stop_filesize_om, tmp); - if(tmp != 0) { - capture_opts.autostop_filesize = tmp; - } else { - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - PRIMARY_TEXT_START "Stop Capture: Requested filesize too large!\n\n" PRIMARY_TEXT_END - "The setting \"... after x byte(s)\" can't be greater than %u bytes (2GB).", G_MAXINT); - return; - } - } - } - - capture_opts.has_file_duration = - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(file_duration_cb)); - if (capture_opts.has_file_duration) { - capture_opts.file_duration = - gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(file_duration_sb)); - capture_opts.file_duration = - time_unit_option_menu_get_value(file_duration_om, capture_opts.file_duration); - } - - capture_opts.has_autostop_files = - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_files_cb)); - if (capture_opts.has_autostop_files) - capture_opts.autostop_files = - gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(stop_files_sb)); - - window_destroy(GTK_WIDGET(parent_w)); - - do_capture(save_file); - if (save_file != NULL) - g_free(save_file); -} - -static void -capture_prep_destroy_cb(GtkWidget *win, gpointer user_data _U_) -{ - GtkWidget *fs; - - /* Is there a file selection dialog associated with this - Capture Options dialog? */ - fs = OBJECT_GET_DATA(win, E_FILE_SEL_DIALOG_PTR_KEY); - - if (fs != NULL) { - /* Yes. Destroy it. */ - window_destroy(fs); - } - - /* Note that we no longer have a "Capture Options" dialog box. */ - cap_open_w = NULL; -} - -static void -capture_prep_interface_changed_cb(GtkWidget *entry, gpointer argp) -{ - GtkWidget *linktype_om = argp; - - set_link_type_list(linktype_om, entry); -} - -/* - * Adjust the sensitivity of various widgets as per the current setting - * of other widgets. - */ -static void -capture_prep_adjust_sensitivity(GtkWidget *tb _U_, gpointer parent_w) -{ - GtkWidget *if_cb, - *snap_cb, *snap_sb, - *multi_files_on_cb, *ringbuffer_nbf_cb, *ringbuffer_nbf_sb, *ringbuffer_nbf_lb, - *ring_filesize_cb, *ring_filesize_sb, *ring_filesize_om, - *file_duration_cb, *file_duration_sb, *file_duration_om, - *sync_cb, *auto_scroll_cb, *hide_info_cb, - *stop_packets_cb, *stop_packets_sb, *stop_packets_lb, - *stop_filesize_cb, *stop_filesize_sb, *stop_filesize_om, - *stop_duration_cb, *stop_duration_sb, *stop_duration_om, - *stop_files_cb, *stop_files_sb, *stop_files_lb; - - - if_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_IFACE_KEY); - snap_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_SNAP_CB_KEY); - snap_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_SNAP_SB_KEY); - multi_files_on_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_MULTI_FILES_ON_CB_KEY); - ringbuffer_nbf_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_RING_NBF_CB_KEY); - ringbuffer_nbf_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_RING_NBF_SB_KEY); - ringbuffer_nbf_lb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_RING_NBF_LB_KEY); - ring_filesize_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_RING_FILESIZE_CB_KEY); - ring_filesize_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_RING_FILESIZE_SB_KEY); - ring_filesize_om = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_RING_FILESIZE_OM_KEY); - file_duration_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_FILE_DURATION_CB_KEY); - file_duration_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_FILE_DURATION_SB_KEY); - file_duration_om = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_FILE_DURATION_OM_KEY); - sync_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_SYNC_KEY); - auto_scroll_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_AUTO_SCROLL_KEY); - hide_info_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_HIDE_INFO_KEY); - stop_packets_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_PACKETS_CB_KEY); - stop_packets_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_PACKETS_SB_KEY); - stop_packets_lb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_PACKETS_LB_KEY); - stop_filesize_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_FILESIZE_CB_KEY); - stop_filesize_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_FILESIZE_SB_KEY); - stop_filesize_om = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_FILESIZE_OM_KEY); - stop_duration_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_DURATION_CB_KEY); - stop_duration_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_DURATION_SB_KEY); - stop_duration_om = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_DURATION_OM_KEY); - stop_files_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_FILES_CB_KEY); - stop_files_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_FILES_SB_KEY); - stop_files_lb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_FILES_LB_KEY); - - /* The snapshot length spinbox is sensitive if the "Limit each packet - to" checkbox is on. */ - gtk_widget_set_sensitive(GTK_WIDGET(snap_sb), - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(snap_cb))); - - - if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(sync_cb))) { - /* "Update list of packets in real time" captures enabled; we don't - support ring buffer mode for those captures, so turn ring buffer - mode off if it's on, and make its toggle button, and the spin - button for the number of ring buffer files (and the spin button's - label), insensitive. */ - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(multi_files_on_cb), FALSE); - gtk_widget_set_sensitive(GTK_WIDGET(multi_files_on_cb), FALSE); - - /* Auto-scroll mode is meaningful only in "Update list of packets - in real time" captures, so make its toggle button sensitive. */ - gtk_widget_set_sensitive(GTK_WIDGET(auto_scroll_cb), TRUE); - - gtk_widget_set_sensitive(GTK_WIDGET(hide_info_cb), TRUE); - } else { - /* "Update list of packets in real time" captures disabled; that - means ring buffer mode is OK, so make its toggle button - sensitive. */ - gtk_widget_set_sensitive(GTK_WIDGET(multi_files_on_cb), TRUE); - - /* Auto-scroll mode is meaningful only in "Update list of packets - in real time" captures, so make its toggle button insensitive. */ - gtk_widget_set_sensitive(GTK_WIDGET(auto_scroll_cb), FALSE); - - gtk_widget_set_sensitive(GTK_WIDGET(hide_info_cb), FALSE); - } - - if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(multi_files_on_cb))) { - /* Ring buffer mode enabled. */ - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ring_filesize_cb), TRUE); - - gtk_widget_set_sensitive(GTK_WIDGET(ringbuffer_nbf_cb), TRUE); - gtk_widget_set_sensitive(GTK_WIDGET(ringbuffer_nbf_sb), - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ringbuffer_nbf_cb))); - gtk_widget_set_sensitive(GTK_WIDGET(ringbuffer_nbf_lb), - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ringbuffer_nbf_cb))); - - /* The ring filesize spinbox is sensitive if the "Next capture file - after N kilobytes" checkbox is on. */ - gtk_widget_set_sensitive(GTK_WIDGET(ring_filesize_cb), TRUE); - gtk_widget_set_sensitive(GTK_WIDGET(ring_filesize_sb), - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ring_filesize_cb))); - gtk_widget_set_sensitive(GTK_WIDGET(ring_filesize_om), - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ring_filesize_cb))); - - /* The ring duration spinbox is sensitive if the "Next capture file - after N seconds" checkbox is on. */ - gtk_widget_set_sensitive(GTK_WIDGET(file_duration_cb), TRUE); - gtk_widget_set_sensitive(GTK_WIDGET(file_duration_sb), - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(file_duration_cb))); - gtk_widget_set_sensitive(GTK_WIDGET(file_duration_om), - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(file_duration_cb))); - - gtk_widget_set_sensitive(GTK_WIDGET(stop_filesize_cb), FALSE); - gtk_widget_set_sensitive(GTK_WIDGET(stop_filesize_sb), FALSE); - gtk_widget_set_sensitive(GTK_WIDGET(stop_filesize_om), FALSE); - - gtk_widget_set_sensitive(GTK_WIDGET(stop_files_cb), TRUE); - gtk_widget_set_sensitive(GTK_WIDGET(stop_files_sb), - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_files_cb))); - gtk_widget_set_sensitive(GTK_WIDGET(stop_files_lb), - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_files_cb))); - } else { - /* Ring buffer mode disabled. */ - gtk_widget_set_sensitive(GTK_WIDGET(ringbuffer_nbf_cb), FALSE); - gtk_widget_set_sensitive(GTK_WIDGET(ringbuffer_nbf_sb), FALSE); - gtk_widget_set_sensitive(GTK_WIDGET(ringbuffer_nbf_lb), FALSE); - - gtk_widget_set_sensitive(GTK_WIDGET(ring_filesize_cb), FALSE); - gtk_widget_set_sensitive(GTK_WIDGET(ring_filesize_sb),FALSE); - gtk_widget_set_sensitive(GTK_WIDGET(ring_filesize_om),FALSE); - - gtk_widget_set_sensitive(GTK_WIDGET(file_duration_cb), FALSE); - gtk_widget_set_sensitive(GTK_WIDGET(file_duration_sb),FALSE); - gtk_widget_set_sensitive(GTK_WIDGET(file_duration_om),FALSE); - - /* The maximum file size spinbox is sensitive if the "Stop capture - after N kilobytes" checkbox is on. */ - gtk_widget_set_sensitive(GTK_WIDGET(stop_filesize_cb), TRUE); - gtk_widget_set_sensitive(GTK_WIDGET(stop_filesize_sb), - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_filesize_cb))); - gtk_widget_set_sensitive(GTK_WIDGET(stop_filesize_om), - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_filesize_cb))); - - gtk_widget_set_sensitive(GTK_WIDGET(stop_files_cb), FALSE); - gtk_widget_set_sensitive(GTK_WIDGET(stop_files_sb), FALSE); - gtk_widget_set_sensitive(GTK_WIDGET(stop_files_lb), FALSE); - } - - /* The maximum packet count spinbox is sensitive if the "Stop capture - after N packets" checkbox is on. */ - gtk_widget_set_sensitive(GTK_WIDGET(stop_packets_sb), - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_packets_cb))); - gtk_widget_set_sensitive(GTK_WIDGET(stop_packets_lb), - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_packets_cb))); - - /* The capture duration spinbox is sensitive if the "Stop capture - after N seconds" checkbox is on. */ - gtk_widget_set_sensitive(GTK_WIDGET(stop_duration_sb), - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_duration_cb))); - gtk_widget_set_sensitive(GTK_WIDGET(stop_duration_om), - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_duration_cb))); -} - -#endif /* HAVE_LIBPCAP */ +/* capture_dlg.c
+ * Routines for packet capture windows
+ *
+ * $Id: capture_dlg.c,v 1.138 2004/07/13 07:15:43 guy Exp $
+ *
+ * Ethereal - Network traffic analyzer
+ * By Gerald Combs <gerald@ethereal.com>
+ * Copyright 1998 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#ifdef HAVE_LIBPCAP
+
+#include <pcap.h>
+#include <string.h>
+#include <gtk/gtk.h>
+
+#include <epan/packet.h>
+#include "capture.h"
+#include "globals.h"
+#include <epan/resolv.h>
+#include "main.h"
+#include "ui_util.h"
+#include "capture_dlg.h"
+#include "filter_prefs.h"
+#include "simple_dialog.h"
+#include "dlg_utils.h"
+#include "pcap-util.h"
+#include "capture_combo_utils.h"
+#include "prefs.h"
+#include "ringbuffer.h"
+#include <epan/filesystem.h>
+#include "compat_macros.h"
+#include "file_dlg.h"
+#include "help_dlg.h"
+#include "gtkglobals.h"
+
+#ifdef _WIN32
+#include "capture-wpcap.h"
+#endif
+
+/* Capture callback data keys */
+#define E_CAP_IFACE_KEY "cap_iface"
+#define E_CAP_IFACE_IP_KEY "cap_iface_ip"
+#define E_CAP_SNAP_CB_KEY "cap_snap_cb"
+#define E_CAP_LT_OM_KEY "cap_lt_om"
+#define E_CAP_LT_OM_LABEL_KEY "cap_lt_om_label"
+#ifdef _WIN32
+#define E_CAP_BUFFER_SIZE_SB_KEY "cap_buffer_size_sb"
+#endif
+#define E_CAP_SNAP_SB_KEY "cap_snap_sb"
+#define E_CAP_PROMISC_KEY "cap_promisc"
+#define E_CAP_FILT_KEY "cap_filter_te"
+#define E_CAP_FILE_TE_KEY "cap_file_te"
+#define E_CAP_MULTI_FILES_ON_CB_KEY "cap_multi_files_on_cb"
+#define E_CAP_RING_FILESIZE_CB_KEY "cap_ring_filesize_cb"
+#define E_CAP_RING_FILESIZE_SB_KEY "cap_ring_filesize_sb"
+#define E_CAP_RING_FILESIZE_OM_KEY "cap_ring_filesize_om"
+#define E_CAP_FILE_DURATION_CB_KEY "cap_file_duration_cb"
+#define E_CAP_FILE_DURATION_SB_KEY "cap_file_duration_sb"
+#define E_CAP_FILE_DURATION_OM_KEY "cap_file_duration_om"
+#define E_CAP_RING_NBF_CB_KEY "cap_ring_nbf_cb"
+#define E_CAP_RING_NBF_SB_KEY "cap_ring_nbf_sb"
+#define E_CAP_RING_NBF_LB_KEY "cap_ring_nbf_lb"
+#define E_CAP_STOP_FILES_CB_KEY "cap_stop_files_cb"
+#define E_CAP_STOP_FILES_SB_KEY "cap_stop_files_sb"
+#define E_CAP_STOP_FILES_LB_KEY "cap_stop_files_lb"
+#define E_CAP_SYNC_KEY "cap_sync"
+#define E_CAP_AUTO_SCROLL_KEY "cap_auto_scroll"
+#define E_CAP_HIDE_INFO_KEY "cap_hide_info"
+#define E_CAP_STOP_PACKETS_CB_KEY "cap_stop_packets_cb"
+#define E_CAP_STOP_PACKETS_SB_KEY "cap_stop_packets_sb"
+#define E_CAP_STOP_PACKETS_LB_KEY "cap_stop_packets_lb"
+#define E_CAP_STOP_FILESIZE_CB_KEY "cap_stop_filesize_cb"
+#define E_CAP_STOP_FILESIZE_SB_KEY "cap_stop_filesize_sb"
+#define E_CAP_STOP_FILESIZE_OM_KEY "cap_stop_filesize_om"
+#define E_CAP_STOP_DURATION_CB_KEY "cap_stop_duration_cb"
+#define E_CAP_STOP_DURATION_SB_KEY "cap_stop_duration_sb"
+#define E_CAP_STOP_DURATION_OM_KEY "cap_stop_duration_om"
+#define E_CAP_M_RESOLVE_KEY "cap_m_resolve"
+#define E_CAP_N_RESOLVE_KEY "cap_n_resolve"
+#define E_CAP_T_RESOLVE_KEY "cap_t_resolve"
+
+#define E_CAP_OM_LT_VALUE_KEY "cap_om_lt_value"
+
+static void
+capture_prep_file_cb(GtkWidget *file_bt, GtkWidget *file_te);
+
+static void
+select_link_type_cb(GtkWidget *w, gpointer data);
+
+static void
+capture_prep_adjust_sensitivity(GtkWidget *tb, gpointer parent_w);
+
+static void
+capture_prep_ok_cb(GtkWidget *ok_bt, gpointer parent_w);
+
+static void
+capture_prep_destroy_cb(GtkWidget *win, gpointer user_data);
+
+static void
+capture_prep_interface_changed_cb(GtkWidget *entry, gpointer parent_w);
+
+void
+capture_stop_cb(GtkWidget *w _U_, gpointer d _U_)
+{
+ capture_stop();
+}
+
+/*
+ * Given text that contains an interface name possibly prefixed by an
+ * interface description, extract the interface name.
+ */
+static char *
+get_if_name(char *if_text)
+{
+ char *if_name;
+
+#ifdef WIN32
+ /*
+ * We cannot assume that the interface name doesn't contain a space;
+ * some names on Windows OT do.
+ *
+ * We also can't assume it begins with "\Device\", either, as, on
+ * Windows OT, WinPcap doesn't put "\Device\" in front of the name.
+ *
+ * As I remember, we can't assume that the interface description
+ * doesn't contain a colon, either; I think some do.
+ *
+ * We can probably assume that the interface *name* doesn't contain
+ * a colon, however; if any interface name does contain a colon on
+ * Windows, it'll be time to just get rid of the damn interface
+ * descriptions in the drop-down list, have just the names in the
+ * drop-down list, and have a "Browse..." button to browse for interfaces,
+ * with names, descriptions, IP addresses, blah blah blah available when
+ * possible.
+ *
+ * So we search backwards for a colon. If we don't find it, just
+ * return the entire string; otherwise, skip the colon and any blanks
+ * after it, and return that string.
+ */
+ if_name = if_text + strlen(if_text);
+ for (;;) {
+ if (if_name == if_text) {
+ /* We're at the beginning of the string; return it. */
+ break;
+ }
+ if_name--;
+ if (*if_name == ':') {
+ /*
+ * We've found a colon.
+ * Unfortunately, a colon is used in the string "rpcap://",
+ * which is used in case of a remote capture.
+ * So we'll check to make sure the colon isn't followed by "//";
+ * it'll be followed by a blank if it separates the description
+ * and the interface name. (We don't wire in "rpcap", in case we
+ * support other protocols in the same syntax.)
+ */
+ if (strncmp(if_name, "://", 3) != 0) {
+ /*
+ * OK, we've found a colon not followed by "//". Skip blanks
+ * following it.
+ */
+ if_name++;
+ while (*if_name == ' ')
+ if_name++;
+ break;
+ }
+ }
+ /* Keep looking for a colon not followed by "//". */
+ }
+#else
+ /*
+ * There's a space between the interface description and name, and
+ * the interface name shouldn't have a space in it (it doesn't, on
+ * UNIX systems); look backwards in the string for a space.
+ *
+ * (An interface name might, however, contain a colon in it, which
+ * is why we don't use the colon search on UNIX.)
+ */
+ if_name = strrchr(if_text, ' ');
+ if (if_name == NULL) {
+ if_name = if_text;
+ } else {
+ if_name++;
+ }
+#endif
+ return if_name;
+}
+
+/*
+ * Keep a static pointer to the current "Capture Options" window, if
+ * any, so that if somebody tries to do "Capture:Start" while there's
+ * already a "Capture Options" window up, we just pop up the existing
+ * one, rather than creating a new one.
+ */
+static GtkWidget *cap_open_w;
+
+
+/* From tcptraceroute, convert a numeric IP address to a string */
+/* XXX - this functionality is already somewhere in our code */
+#define IPTOSBUFFERS 12
+char *iptos(u_long in)
+{
+ static char output[IPTOSBUFFERS][3*4+3+1];
+ static short which;
+ u_char *p;
+
+ p = (u_char *)∈
+ which = (which + 1 == IPTOSBUFFERS ? 0 : which + 1);
+ sprintf(output[which], "%d.%d.%d.%d", p[0], p[1], p[2], p[3]);
+ return output[which];
+}
+
+
+static void
+set_link_type_list(GtkWidget *linktype_om, GtkWidget *entry)
+{
+ gchar *entry_text;
+ gchar *if_text;
+ gchar *if_name;
+ GList *if_list;
+ GList *if_entry;
+ if_info_t *if_info;
+ GList *lt_list;
+ int err;
+ char err_buf[PCAP_ERRBUF_SIZE];
+ GtkWidget *lt_menu, *lt_menu_item;
+ GList *lt_entry;
+ data_link_info_t *data_link_info;
+ gchar *linktype_menu_label;
+ guint num_supported_link_types;
+ GtkWidget *linktype_lb = OBJECT_GET_DATA(linktype_om, E_CAP_LT_OM_LABEL_KEY);
+ GtkWidget *if_ip_lb;
+ GString *ip_str = g_string_new("IP address: ");
+ int ips = 0;
+ GSList *curr_ip;
+
+ lt_menu = gtk_menu_new();
+ entry_text = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry)));
+ if_text = g_strstrip(entry_text);
+ if_name = get_if_name(if_text);
+
+ /*
+ * If the interface name is in the list of known interfaces, get
+ * its list of link-layer types and set the option menu to display it.
+ *
+ * If it's not, don't bother - the user might be in the middle of
+ * editing the list, or it might be a remote device in which case
+ * getting the list could take an arbitrarily-long period of time.
+ * The list currently won't contain any remote devices (as
+ * "pcap_findalldevs()" doesn't know about remote devices, and neither
+ * does the code we use if "pcap_findalldevs()" isn't available), but
+ * should contain all the local devices on which you can capture.
+ */
+ lt_list = NULL;
+ if (*if_name != '\0') {
+ /*
+ * Try to get the list of known interfaces.
+ */
+ if_list = get_interface_list(&err, err_buf);
+ if (if_list != NULL) {
+ /*
+ * We have the list - check it.
+ */
+ for (if_entry = if_list; if_entry != NULL;
+ if_entry = g_list_next(if_entry)) {
+ if_info = if_entry->data;
+ if (strcmp(if_info->name, if_name) == 0) {
+ /*
+ * It's in the list.
+ * Get the list of link-layer types for it.
+ */
+ lt_list = get_pcap_linktype_list(if_name, err_buf);
+
+ /* create string of list of IP addresses of this interface */
+ for( ; curr_ip = g_slist_nth(if_info->ip_addr, ips); ips++) {
+ if (ips != 0) {
+ g_string_append(ip_str, ", ");
+ }
+
+ g_string_append(ip_str, iptos(*((guint32 *)curr_ip->data)));
+ }
+
+ if(if_info->loopback) {
+ g_string_append(ip_str, " (loopback)");
+ }
+ }
+ }
+ free_interface_list(if_list);
+ }
+ }
+ g_free(entry_text);
+ num_supported_link_types = 0;
+ for (lt_entry = lt_list; lt_entry != NULL; lt_entry = g_list_next(lt_entry)) {
+ data_link_info = lt_entry->data;
+ if (data_link_info->description != NULL) {
+ lt_menu_item = gtk_menu_item_new_with_label(data_link_info->description);
+ OBJECT_SET_DATA(lt_menu_item, E_CAP_LT_OM_KEY, linktype_om);
+ SIGNAL_CONNECT(lt_menu_item, "activate", select_link_type_cb,
+ GINT_TO_POINTER(data_link_info->dlt));
+ num_supported_link_types++;
+ } else {
+ /* Not supported - tell them about it but don't let them select it. */
+ linktype_menu_label = g_strdup_printf("%s (not supported)",
+ data_link_info->name);
+ lt_menu_item = gtk_menu_item_new_with_label(linktype_menu_label);
+ g_free(linktype_menu_label);
+ gtk_widget_set_sensitive(lt_menu_item, FALSE);
+ }
+ gtk_menu_append(GTK_MENU(lt_menu), lt_menu_item);
+ }
+ if (lt_list != NULL)
+ free_pcap_linktype_list(lt_list);
+ gtk_option_menu_set_menu(GTK_OPTION_MENU(linktype_om), lt_menu);
+ gtk_widget_set_sensitive(linktype_lb, num_supported_link_types >= 2);
+ gtk_widget_set_sensitive(linktype_om, num_supported_link_types >= 2);
+
+ if_ip_lb = OBJECT_GET_DATA(linktype_om, E_CAP_IFACE_KEY);
+ if(ips == 0) {
+ g_string_append(ip_str, "unknown");
+ }
+ gtk_label_set_text(GTK_LABEL(if_ip_lb), ip_str->str);
+ g_string_free(ip_str, TRUE);
+}
+
+
+#define TIME_UNIT_SECOND 0
+#define TIME_UNIT_MINUTE 1
+#define TIME_UNIT_HOUR 2
+#define TIME_UNIT_DAY 3
+#define MAX_TIME_UNITS 4
+static char *time_unit_name[MAX_TIME_UNITS] = {
+ "second(s)",
+ "minute(s)",
+ "hour(s)",
+ "day(s)",
+};
+
+static GtkWidget *time_unit_option_menu_new(guint32 value) {
+ GtkWidget *unit_om, *menu, *menu_item;
+ int i;
+
+ unit_om=gtk_option_menu_new();
+ menu=gtk_menu_new();
+ for(i=0;i<MAX_TIME_UNITS;i++){
+ menu_item=gtk_menu_item_new_with_label(time_unit_name[i]);
+ OBJECT_SET_DATA(menu_item, "time_unit", GINT_TO_POINTER(i));
+ gtk_menu_append(GTK_MENU(menu), menu_item);
+ }
+
+ /* the selected menu item can't be changed, once the option_menu
+ is created, so set the matching menu item now */
+ /* days */
+ if(value >= 60 * 60 * 24) {
+ gtk_menu_set_active(GTK_MENU(menu), TIME_UNIT_DAY);
+ } else {
+ /* hours */
+ if(value >= 60 * 60) {
+ gtk_menu_set_active(GTK_MENU(menu), TIME_UNIT_HOUR);
+ } else {
+ /* minutes */
+ if(value >= 60) {
+ gtk_menu_set_active(GTK_MENU(menu), TIME_UNIT_MINUTE);
+ } else {
+ /* seconds */
+ gtk_menu_set_active(GTK_MENU(menu), TIME_UNIT_SECOND);
+ }
+ }
+ }
+
+ gtk_option_menu_set_menu(GTK_OPTION_MENU(unit_om), menu);
+
+ return unit_om;
+}
+
+static guint32 time_unit_option_menu_convert_value(
+guint32 value)
+{
+ /* days */
+ if(value >= 60 * 60 * 24) {
+ return value / (60 * 60 * 24);
+ }
+
+ /* hours */
+ if(value >= 60 * 60) {
+ return value / (60 * 60);
+ }
+
+ /* minutes */
+ if(value >= 60) {
+ return value / 60;
+ }
+
+ /* seconds */
+ return value;
+}
+
+static guint32 time_unit_option_menu_get_value(
+GtkWidget *unit_om,
+guint32 value)
+{
+ GtkWidget *menu, *menu_item;
+ int unit;
+
+ menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(unit_om));
+ menu_item = gtk_menu_get_active(GTK_MENU(menu));
+ unit = GPOINTER_TO_INT(OBJECT_GET_DATA(menu_item, "time_unit"));
+
+
+ switch(unit) {
+ case(TIME_UNIT_SECOND):
+ return value;
+ break;
+ case(TIME_UNIT_MINUTE):
+ return value * 60;
+ break;
+ case(TIME_UNIT_HOUR):
+ return value * 60 * 60;
+ break;
+ case(TIME_UNIT_DAY):
+ return value * 60 * 60 * 24;
+ break;
+ default:
+ g_assert_not_reached();
+ return 0;
+ }
+}
+
+
+#define SIZE_UNIT_BYTES 0
+#define SIZE_UNIT_KILOBYTES 1
+#define SIZE_UNIT_MEGABYTES 2
+#define SIZE_UNIT_GIGABYTES 3
+#define MAX_SIZE_UNITS 4
+static char *size_unit_name[MAX_SIZE_UNITS] = {
+ "byte(s)",
+ "kilobyte(s)",
+ "megabyte(s)",
+ "gigabyte(s)",
+};
+
+static GtkWidget *size_unit_option_menu_new(guint32 value) {
+ GtkWidget *unit_om, *menu, *menu_item;
+ int i;
+
+ unit_om=gtk_option_menu_new();
+ menu=gtk_menu_new();
+ for(i=0;i<MAX_SIZE_UNITS;i++){
+ menu_item=gtk_menu_item_new_with_label(size_unit_name[i]);
+ OBJECT_SET_DATA(menu_item, "size_unit", GINT_TO_POINTER(i));
+ gtk_menu_append(GTK_MENU(menu), menu_item);
+ }
+
+ /* the selected menu item can't be changed, once the option_menu
+ is created, so set the matching menu item now */
+ /* gigabytes */
+ if(value >= 1024 * 1024 * 1024) {
+ gtk_menu_set_active(GTK_MENU(menu), SIZE_UNIT_GIGABYTES);
+ } else {
+ /* megabytes */
+ if(value >= 1024 * 1024) {
+ gtk_menu_set_active(GTK_MENU(menu), SIZE_UNIT_MEGABYTES);
+ } else {
+ /* kilobytes */
+ if(value >= 1024) {
+ gtk_menu_set_active(GTK_MENU(menu), SIZE_UNIT_KILOBYTES);
+ } else {
+ /* bytes */
+ gtk_menu_set_active(GTK_MENU(menu), SIZE_UNIT_BYTES);
+ }
+ }
+ }
+
+ gtk_option_menu_set_menu(GTK_OPTION_MENU(unit_om), menu);
+
+ return unit_om;
+}
+
+static guint32 size_unit_option_menu_set_value(
+guint32 value)
+{
+ /* gigabytes */
+ if(value >= 1024 * 1024 * 1024) {
+ return value / (1024 * 1024 * 1024);
+ }
+
+ /* megabytes */
+ if(value >= 1024 * 1024) {
+ return value / (1024 * 1024);
+ }
+
+ /* kilobytes */
+ if(value >= 1024) {
+ return value / 1024;
+ }
+
+ /* bytes */
+ return value;
+}
+
+static guint32 size_unit_option_menu_convert_value(
+GtkWidget *unit_om,
+guint32 value)
+{
+ GtkWidget *menu, *menu_item;
+ int unit;
+
+ menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(unit_om));
+ menu_item = gtk_menu_get_active(GTK_MENU(menu));
+ unit = GPOINTER_TO_INT(OBJECT_GET_DATA(menu_item, "size_unit"));
+
+
+ switch(unit) {
+ case(SIZE_UNIT_BYTES):
+ return value;
+ break;
+ case(SIZE_UNIT_KILOBYTES):
+ if(value > G_MAXINT / 1024) {
+ return 0;
+ } else {
+ return value * 1024;
+ }
+ break;
+ case(SIZE_UNIT_MEGABYTES):
+ if(value > G_MAXINT / (1024 * 1024)) {
+ return 0;
+ } else {
+ return value * 1024 * 1024;
+ }
+ break;
+ case(SIZE_UNIT_GIGABYTES):
+ if(value > G_MAXINT / (1024 * 1024 * 1024)) {
+ return 0;
+ } else {
+ return value * 1024 * 1024 * 1024;
+ }
+ break;
+ default:
+ g_assert_not_reached();
+ return 0;
+ }
+}
+
+
+void
+capture_prep(void)
+{
+ GtkWidget *main_vb,
+ *main_hb, *left_vb, *right_vb,
+
+ *capture_fr, *capture_vb,
+ *if_hb, *if_cb, *if_lb,
+ *if_ip_hb, *if_ip_lb,
+ *linktype_hb, *linktype_lb, *linktype_om,
+ *snap_hb, *snap_cb, *snap_sb, *snap_lb,
+ *promisc_cb,
+ *filter_hb, *filter_bt, *filter_te,
+
+ *file_fr, *file_vb,
+ *file_hb, *file_bt, *file_lb, *file_te,
+ *multi_tb, *multi_files_on_cb,
+ *ring_filesize_cb, *ring_filesize_sb, *ring_filesize_om,
+ *file_duration_cb, *file_duration_sb, *file_duration_om,
+ *ringbuffer_nbf_cb, *ringbuffer_nbf_sb, *ringbuffer_nbf_lb,
+ *stop_files_cb, *stop_files_sb, *stop_files_lb,
+
+ *limit_fr, *limit_vb, *limit_tb,
+ *stop_packets_cb, *stop_packets_sb, *stop_packets_lb,
+ *stop_filesize_cb, *stop_filesize_sb, *stop_filesize_om,
+ *stop_duration_cb, *stop_duration_sb, *stop_duration_om,
+
+ *display_fr, *display_vb,
+ *sync_cb, *auto_scroll_cb, *hide_info_cb,
+
+ *resolv_fr, *resolv_vb,
+ *m_resolv_cb, *n_resolv_cb, *t_resolv_cb,
+ *bbox, *ok_bt, *cancel_bt,
+ *help_bt;
+#if GTK_MAJOR_VERSION < 2
+ GtkAccelGroup *accel_group;
+#endif
+ GtkTooltips *tooltips;
+ GtkAdjustment *snap_adj, *ringbuffer_nbf_adj,
+ *stop_packets_adj, *stop_filesize_adj, *stop_duration_adj, *stop_files_adj, *ring_filesize_adj, *file_duration_adj;
+ GList *if_list, *combo_list;
+ int err;
+ int row;
+ char err_str[PCAP_ERRBUF_SIZE];
+ gchar *cant_get_if_list_errstr;
+#ifdef _WIN32
+ GtkAdjustment *buffer_size_adj;
+ GtkWidget *buffer_size_lb, *buffer_size_sb;
+#endif
+ guint32 value;
+
+ if (cap_open_w != NULL) {
+ /* There's already a "Capture Options" dialog box; reactivate it. */
+ reactivate_window(cap_open_w);
+ return;
+ }
+
+#ifdef _WIN32
+ /* Is WPcap loaded? */
+ if (!has_wpcap) {
+ simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
+ "Unable to load WinPcap (wpcap.dll); Ethereal will not be able\n"
+ "to capture packets.\n\n"
+ "In order to capture packets, WinPcap must be installed; see\n"
+ "\n"
+ " http://winpcap.polito.it/\n"
+ "\n"
+ "or the mirror at\n"
+ "\n"
+ " http://winpcap.mirror.ethereal.com/\n"
+ "\n"
+ "or the mirror at\n"
+ "\n"
+ " http://www.mirrors.wiretapped.net/security/packet-capture/winpcap/\n"
+ "\n"
+ "for a downloadable version of WinPcap and for instructions\n"
+ "on how to install WinPcap.");
+ return;
+ }
+#endif
+
+ if_list = get_interface_list(&err, err_str);
+ if (if_list == NULL && err == CANT_GET_INTERFACE_LIST) {
+ cant_get_if_list_errstr = cant_get_if_list_error_message(err_str);
+ simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s",
+ cant_get_if_list_errstr);
+ g_free(cant_get_if_list_errstr);
+ }
+
+ cap_open_w = dlg_window_new("Ethereal: Capture Options");
+
+ tooltips = gtk_tooltips_new();
+
+#if GTK_MAJOR_VERSION < 2
+ /* Accelerator group for the accelerators (or, as they're called in
+ Windows and, I think, in Motif, "mnemonics"; Alt+<key> is a mnemonic,
+ Ctrl+<key> is an accelerator). */
+ accel_group = gtk_accel_group_new();
+ gtk_window_add_accel_group(GTK_WINDOW(cap_open_w), accel_group);
+#endif
+
+ main_vb = gtk_vbox_new(FALSE, 0);
+ gtk_container_border_width(GTK_CONTAINER(main_vb), 5);
+ gtk_container_add(GTK_CONTAINER(cap_open_w), main_vb);
+
+ /* Capture-related options frame */
+ capture_fr = gtk_frame_new("Capture");
+ gtk_container_add(GTK_CONTAINER(main_vb), capture_fr);
+
+ capture_vb = gtk_vbox_new(FALSE, 3);
+ gtk_container_border_width(GTK_CONTAINER(capture_vb), 5);
+ gtk_container_add(GTK_CONTAINER(capture_fr), capture_vb);
+
+ /* Interface row */
+ if_hb = gtk_hbox_new(FALSE, 3);
+ gtk_container_add(GTK_CONTAINER(capture_vb), if_hb);
+
+ if_lb = gtk_label_new("Interface:");
+ gtk_box_pack_start(GTK_BOX(if_hb), if_lb, FALSE, FALSE, 6);
+
+ if_cb = gtk_combo_new();
+ combo_list = build_capture_combo_list(if_list, TRUE);
+ if (combo_list != NULL)
+ gtk_combo_set_popdown_strings(GTK_COMBO(if_cb), combo_list);
+ if (cfile.iface == NULL && prefs.capture_device != NULL) {
+ /* No interface was specified on the command line or in a previous
+ capture, but there is one specified in the preferences file;
+ make the one from the preferences file the default */
+ cfile.iface = g_strdup(prefs.capture_device);
+ }
+ if (cfile.iface != NULL)
+ gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(if_cb)->entry), cfile.iface);
+ else if (combo_list != NULL) {
+ gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(if_cb)->entry),
+ (char *)combo_list->data);
+ }
+ free_capture_combo_list(combo_list);
+ free_interface_list(if_list);
+ gtk_tooltips_set_tip(tooltips, GTK_COMBO(if_cb)->entry,
+ "Choose which interface (network card) will be used to capture packets from. "
+ "Be sure to select the correct one, as it's a common mistake to select the wrong interface.", NULL);
+ gtk_box_pack_start(GTK_BOX(if_hb), if_cb, TRUE, TRUE, 6);
+
+ if_ip_hb = gtk_hbox_new(FALSE, 3);
+ gtk_box_pack_start(GTK_BOX(capture_vb), if_ip_hb, FALSE, FALSE, 0);
+
+ if_ip_lb = gtk_label_new("");
+ gtk_box_pack_start(GTK_BOX(if_ip_hb), if_ip_lb, FALSE, FALSE, 6);
+
+ /* Linktype row */
+ linktype_hb = gtk_hbox_new(FALSE, 3);
+ gtk_box_pack_start(GTK_BOX(capture_vb), linktype_hb, FALSE, FALSE, 0);
+
+ linktype_lb = gtk_label_new("Link-layer header type:");
+ gtk_box_pack_start(GTK_BOX(linktype_hb), linktype_lb, FALSE, FALSE, 6);
+
+ linktype_om = gtk_option_menu_new();
+ OBJECT_SET_DATA(linktype_om, E_CAP_LT_OM_LABEL_KEY, linktype_lb);
+ /* Default to "use the default" */
+ OBJECT_SET_DATA(linktype_om, E_CAP_OM_LT_VALUE_KEY, GINT_TO_POINTER(-1));
+ OBJECT_SET_DATA(linktype_om, E_CAP_IFACE_KEY, if_ip_lb);
+ set_link_type_list(linktype_om, GTK_COMBO(if_cb)->entry);
+ /*
+ * XXX - in some cases, this is "multiple link-layer header types", e.g.
+ * some 802.11 interfaces on FreeBSD 5.2 and later, where you can request
+ * fake Ethernet, 802.11, or 802.11-plus-radio-information headers.
+ *
+ * In other cases, it's "multiple link-layer types", e.g., with recent
+ * versions of libpcap, a DAG card on an "HDLC" WAN, where you can
+ * request Cisco HDLC or PPP depending on what type of traffic is going
+ * over the WAN, or an Ethernet interface, where you can request Ethernet
+ * or DOCSIS, the latter being for some Cisco cable modem equipment that
+ * can be configured to send raw DOCSIS frames over an Ethernet inside
+ * Ethernet low-level framing, for traffic capture purposes.
+ *
+ * We leave it as "multiple link-layer types" for now.
+ */
+ gtk_tooltips_set_tip(tooltips, linktype_om,
+ "The selected interface supports multiple link-layer types; select the desired one.", NULL);
+ gtk_box_pack_start (GTK_BOX(linktype_hb), linktype_om, FALSE, FALSE, 0);
+ SIGNAL_CONNECT(GTK_ENTRY(GTK_COMBO(if_cb)->entry), "changed",
+ capture_prep_interface_changed_cb, linktype_om);
+
+#ifdef _WIN32
+ buffer_size_lb = gtk_label_new("Buffer size:");
+ gtk_box_pack_start (GTK_BOX(linktype_hb), buffer_size_lb, FALSE, FALSE, 0);
+
+ buffer_size_adj = (GtkAdjustment *) gtk_adjustment_new((gfloat) capture_opts.buffer_size,
+ 1, 65535, 1.0, 10.0, 0.0);
+ buffer_size_sb = gtk_spin_button_new (buffer_size_adj, 0, 0);
+ gtk_spin_button_set_value(GTK_SPIN_BUTTON (buffer_size_sb), (gfloat) capture_opts.buffer_size);
+ gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (buffer_size_sb), TRUE);
+ WIDGET_SET_SIZE(buffer_size_sb, 80, -1);
+ gtk_tooltips_set_tip(tooltips, buffer_size_sb,
+ "The memory buffer size used while capturing. If you notice packet drops, you can try to increase this size.", NULL);
+ gtk_box_pack_start (GTK_BOX(linktype_hb), buffer_size_sb, FALSE, FALSE, 0);
+
+ buffer_size_lb = gtk_label_new("megabyte(s)");
+ gtk_box_pack_start (GTK_BOX(linktype_hb), buffer_size_lb, FALSE, FALSE, 0);
+#endif
+
+ /* Promiscuous mode row */
+ promisc_cb = CHECK_BUTTON_NEW_WITH_MNEMONIC(
+ "Capture packets in _promiscuous mode", accel_group);
+ gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(promisc_cb),
+ capture_opts.promisc_mode);
+ gtk_tooltips_set_tip(tooltips, promisc_cb,
+ "Usually a network card will only capture the traffic sent to its own network address. "
+ "If you want to capture all traffic that the network card can \"see\", mark this option. "
+ "See the FAQ for some more details of capturing packets from a switched network.", NULL);
+ gtk_container_add(GTK_CONTAINER(capture_vb), promisc_cb);
+
+ /* Capture length row */
+ snap_hb = gtk_hbox_new(FALSE, 3);
+ gtk_container_add(GTK_CONTAINER(capture_vb), snap_hb);
+
+ snap_cb = CHECK_BUTTON_NEW_WITH_MNEMONIC("_Limit each packet to", accel_group);
+ gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(snap_cb),
+ capture_opts.has_snaplen);
+ SIGNAL_CONNECT(snap_cb, "toggled", capture_prep_adjust_sensitivity, cap_open_w);
+ gtk_tooltips_set_tip(tooltips, snap_cb,
+ "Limit the maximum number of bytes to be captured from each packet. This size includes the "
+ "link-layer header and all subsequent headers. ", NULL);
+ gtk_box_pack_start(GTK_BOX(snap_hb), snap_cb, FALSE, FALSE, 0);
+
+ snap_adj = (GtkAdjustment *) gtk_adjustment_new((gfloat) capture_opts.snaplen,
+ MIN_PACKET_SIZE, WTAP_MAX_PACKET_SIZE, 1.0, 10.0, 0.0);
+ snap_sb = gtk_spin_button_new (snap_adj, 0, 0);
+ gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (snap_sb), TRUE);
+ WIDGET_SET_SIZE(snap_sb, 80, -1);
+ gtk_box_pack_start (GTK_BOX(snap_hb), snap_sb, FALSE, FALSE, 0);
+
+ snap_lb = gtk_label_new("bytes");
+ gtk_misc_set_alignment(GTK_MISC(snap_lb), 0, 0.5);
+ gtk_box_pack_start(GTK_BOX(snap_hb), snap_lb, FALSE, FALSE, 0);
+
+ /* Filter row */
+ filter_hb = gtk_hbox_new(FALSE, 3);
+ gtk_box_pack_start(GTK_BOX(capture_vb), filter_hb, FALSE, FALSE, 0);
+
+ filter_bt = BUTTON_NEW_FROM_STOCK(ETHEREAL_STOCK_CAPTURE_FILTER_ENTRY);
+ SIGNAL_CONNECT(filter_bt, "clicked", capture_filter_construct_cb, NULL);
+ SIGNAL_CONNECT(filter_bt, "destroy", filter_button_destroy_cb, NULL);
+ gtk_tooltips_set_tip(tooltips, filter_bt,
+ "Select a capture filter to reduce the amount of packets to be captured. "
+ "See \"Capture Filters\" in the online help for further information how to use it.",
+ NULL);
+ gtk_box_pack_start(GTK_BOX(filter_hb), filter_bt, FALSE, FALSE, 3);
+
+ filter_te = gtk_entry_new();
+ if (cfile.cfilter) gtk_entry_set_text(GTK_ENTRY(filter_te), cfile.cfilter);
+ OBJECT_SET_DATA(filter_bt, E_FILT_TE_PTR_KEY, filter_te);
+ gtk_tooltips_set_tip(tooltips, filter_te,
+ "Enter a capture filter to reduce the amount of packets to be captured. "
+ "See \"Capture Filters\" in the online help for further information how to use it.",
+ NULL);
+ gtk_box_pack_start(GTK_BOX(filter_hb), filter_te, TRUE, TRUE, 3);
+
+ main_hb = gtk_hbox_new(FALSE, 5);
+ gtk_container_border_width(GTK_CONTAINER(main_hb), 0);
+ gtk_container_add(GTK_CONTAINER(main_vb), main_hb);
+
+ left_vb = gtk_vbox_new(FALSE, 0);
+ gtk_container_border_width(GTK_CONTAINER(left_vb), 0);
+ gtk_box_pack_start(GTK_BOX(main_hb), left_vb, TRUE, TRUE, 0);
+
+ right_vb = gtk_vbox_new(FALSE, 0);
+ gtk_container_border_width(GTK_CONTAINER(right_vb), 0);
+ gtk_box_pack_start(GTK_BOX(main_hb), right_vb, FALSE, FALSE, 0);
+
+
+ /* Capture file-related options frame */
+ file_fr = gtk_frame_new("Capture File(s)");
+ gtk_container_add(GTK_CONTAINER(left_vb), file_fr);
+
+ file_vb = gtk_vbox_new(FALSE, 3);
+ gtk_container_border_width(GTK_CONTAINER(file_vb), 5);
+ gtk_container_add(GTK_CONTAINER(file_fr), file_vb);
+
+ /* File row */
+ file_hb = gtk_hbox_new(FALSE, 3);
+ gtk_box_pack_start(GTK_BOX(file_vb), file_hb, FALSE, FALSE, 0);
+
+ file_lb = gtk_label_new("File:");
+ gtk_box_pack_start(GTK_BOX(file_hb), file_lb, FALSE, FALSE, 3);
+
+ file_te = gtk_entry_new();
+ gtk_tooltips_set_tip(tooltips, file_te,
+ "Enter the file name to which captured data will be written. "
+ "If you don't enter something here, a temporary file will be used.",
+ NULL);
+ gtk_box_pack_start(GTK_BOX(file_hb), file_te, TRUE, TRUE, 3);
+
+ file_bt = BUTTON_NEW_FROM_STOCK(ETHEREAL_STOCK_BROWSE);
+ gtk_tooltips_set_tip(tooltips, file_bt,
+ "Select a file to which captured data will be written, "
+ "instead of entering the file name directly. ",
+ NULL);
+ gtk_box_pack_start(GTK_BOX(file_hb), file_bt, FALSE, FALSE, 3);
+
+ SIGNAL_CONNECT(file_bt, "clicked", capture_prep_file_cb, file_te);
+
+ /* multiple files table */
+ multi_tb = gtk_table_new(5, 3, FALSE);
+ gtk_table_set_row_spacings(GTK_TABLE(multi_tb), 1);
+ gtk_table_set_col_spacings(GTK_TABLE(multi_tb), 3);
+ gtk_box_pack_start(GTK_BOX(file_vb), multi_tb, FALSE, FALSE, 0);
+ row = 0;
+
+ /* multiple files row */
+ multi_files_on_cb = CHECK_BUTTON_NEW_WITH_MNEMONIC("Use _multiple files", accel_group);
+ gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(multi_files_on_cb),
+ capture_opts.multi_files_on);
+ SIGNAL_CONNECT(multi_files_on_cb, "toggled", capture_prep_adjust_sensitivity,
+ cap_open_w);
+ gtk_tooltips_set_tip(tooltips, multi_files_on_cb,
+ "Instead of using a single capture file, multiple files will be created. "
+ "The generated file names will contain an incrementing number and the start time of the capture.", NULL);
+ gtk_table_attach_defaults(GTK_TABLE(multi_tb), multi_files_on_cb, 0, 1, row, row+1);
+ row++;
+
+ /* Ring buffer filesize row */
+ ring_filesize_cb = gtk_check_button_new_with_label("Next file every");
+ gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(ring_filesize_cb),
+ capture_opts.has_autostop_filesize);
+ SIGNAL_CONNECT(ring_filesize_cb, "toggled", capture_prep_adjust_sensitivity, cap_open_w);
+ gtk_tooltips_set_tip(tooltips, ring_filesize_cb,
+ "If the selected file size is exceeded, capturing switches to the next file.",
+ NULL);
+ gtk_table_attach_defaults(GTK_TABLE(multi_tb), ring_filesize_cb, 0, 1, row, row+1);
+
+ ring_filesize_adj = (GtkAdjustment *) gtk_adjustment_new(0.0,
+ 1, (gfloat)INT_MAX, 1.0, 10.0, 0.0);
+ ring_filesize_sb = gtk_spin_button_new (ring_filesize_adj, 0, 0);
+ gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (ring_filesize_sb), TRUE);
+ WIDGET_SET_SIZE(ring_filesize_sb, 80, -1);
+ gtk_table_attach_defaults(GTK_TABLE(multi_tb), ring_filesize_sb, 1, 2, row, row+1);
+
+ ring_filesize_om = size_unit_option_menu_new(capture_opts.autostop_filesize);
+ gtk_table_attach_defaults(GTK_TABLE(multi_tb), ring_filesize_om, 2, 3, row, row+1);
+
+ value = size_unit_option_menu_set_value(capture_opts.autostop_filesize);
+ gtk_adjustment_set_value(ring_filesize_adj, (gfloat) value);
+
+ row++;
+
+ /* Ring buffer duration row */
+ file_duration_cb = gtk_check_button_new_with_label("Next file every");
+ gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(file_duration_cb),
+ capture_opts.has_file_duration);
+ SIGNAL_CONNECT(file_duration_cb, "toggled",
+ capture_prep_adjust_sensitivity, cap_open_w);
+ gtk_tooltips_set_tip(tooltips, file_duration_cb,
+ "If the selected duration is exceeded, capturing switches to the next file.",
+ NULL);
+ gtk_table_attach_defaults(GTK_TABLE(multi_tb), file_duration_cb, 0, 1, row, row+1);
+
+ file_duration_adj = (GtkAdjustment *)gtk_adjustment_new(0.0,
+ 1, (gfloat)INT_MAX, 1.0, 10.0, 0.0);
+ file_duration_sb = gtk_spin_button_new (file_duration_adj, 0, 0);
+ gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (file_duration_sb), TRUE);
+ WIDGET_SET_SIZE(file_duration_sb, 80, -1);
+ gtk_table_attach_defaults(GTK_TABLE(multi_tb), file_duration_sb, 1, 2, row, row+1);
+
+ file_duration_om = time_unit_option_menu_new(capture_opts.file_duration);
+ gtk_table_attach_defaults(GTK_TABLE(multi_tb), file_duration_om, 2, 3, row, row+1);
+
+ value = time_unit_option_menu_convert_value(capture_opts.file_duration);
+ gtk_adjustment_set_value(file_duration_adj, (gfloat) value);
+ row++;
+
+ /* Ring buffer files row */
+ ringbuffer_nbf_cb = gtk_check_button_new_with_label("Ring buffer with");
+ gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(ringbuffer_nbf_cb),
+ capture_opts.has_ring_num_files);
+ SIGNAL_CONNECT(ringbuffer_nbf_cb, "toggled", capture_prep_adjust_sensitivity, cap_open_w);
+ gtk_tooltips_set_tip(tooltips, ringbuffer_nbf_cb,
+ "After capturing has switched to the next file and the given number of files has exceeded, "
+ "the oldest file will be removed.",
+ NULL);
+ gtk_table_attach_defaults(GTK_TABLE(multi_tb), ringbuffer_nbf_cb, 0, 1, row, row+1);
+
+ ringbuffer_nbf_adj = (GtkAdjustment *) gtk_adjustment_new((gfloat) capture_opts.ring_num_files,
+ 2/*RINGBUFFER_MIN_NUM_FILES*/, RINGBUFFER_MAX_NUM_FILES, 1.0, 10.0, 0.0);
+ ringbuffer_nbf_sb = gtk_spin_button_new (ringbuffer_nbf_adj, 0, 0);
+ gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (ringbuffer_nbf_sb), TRUE);
+ WIDGET_SET_SIZE(ringbuffer_nbf_sb, 80, -1);
+ SIGNAL_CONNECT(ringbuffer_nbf_sb, "changed", capture_prep_adjust_sensitivity, cap_open_w);
+ gtk_table_attach_defaults(GTK_TABLE(multi_tb), ringbuffer_nbf_sb, 1, 2, row, row+1);
+
+ ringbuffer_nbf_lb = gtk_label_new("files");
+ gtk_misc_set_alignment(GTK_MISC(ringbuffer_nbf_lb), 0, 0.5);
+ gtk_table_attach_defaults(GTK_TABLE(multi_tb), ringbuffer_nbf_lb, 2, 3, row, row+1);
+ row++;
+
+ /* Files row */
+ stop_files_cb = gtk_check_button_new_with_label("Stop capture after");
+ gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(stop_files_cb),
+ capture_opts.has_autostop_files);
+ SIGNAL_CONNECT(stop_files_cb, "toggled", capture_prep_adjust_sensitivity, cap_open_w);
+ gtk_tooltips_set_tip(tooltips, stop_files_cb,
+ "Stop capturing after the given number of \"file switches\" have been done.", NULL);
+ gtk_table_attach_defaults(GTK_TABLE(multi_tb), stop_files_cb, 0, 1, row, row+1);
+
+ stop_files_adj = (GtkAdjustment *) gtk_adjustment_new((gfloat)capture_opts.autostop_files,
+ 1, (gfloat)INT_MAX, 1.0, 10.0, 0.0);
+ stop_files_sb = gtk_spin_button_new (stop_files_adj, 0, 0);
+ gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (stop_files_sb), TRUE);
+ WIDGET_SET_SIZE(stop_files_sb, 80, -1);
+ gtk_table_attach_defaults(GTK_TABLE(multi_tb), stop_files_sb, 1, 2, row, row+1);
+
+ stop_files_lb = gtk_label_new("file(s)");
+ gtk_misc_set_alignment(GTK_MISC(stop_files_lb), 0, 0.5);
+ gtk_table_attach_defaults(GTK_TABLE(multi_tb), stop_files_lb, 2, 3, row, row+1);
+ row++;
+
+ /* Capture limits frame */
+ limit_fr = gtk_frame_new("Stop Capture ...");
+ gtk_container_add(GTK_CONTAINER(left_vb), limit_fr);
+
+ limit_vb = gtk_vbox_new(FALSE, 3);
+ gtk_container_border_width(GTK_CONTAINER(limit_vb), 5);
+ gtk_container_add(GTK_CONTAINER(limit_fr), limit_vb);
+
+ /* limits table */
+ limit_tb = gtk_table_new(3, 3, FALSE);
+ gtk_table_set_row_spacings(GTK_TABLE(limit_tb), 1);
+ gtk_table_set_col_spacings(GTK_TABLE(limit_tb), 3);
+ gtk_box_pack_start(GTK_BOX(limit_vb), limit_tb, FALSE, FALSE, 0);
+ row = 0;
+
+ /* Packet count row */
+ stop_packets_cb = gtk_check_button_new_with_label("... after");
+ gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(stop_packets_cb),
+ capture_opts.has_autostop_packets);
+ SIGNAL_CONNECT(stop_packets_cb, "toggled", capture_prep_adjust_sensitivity, cap_open_w);
+ gtk_tooltips_set_tip(tooltips, stop_packets_cb,
+ "Stop capturing after the given number of packets have been captured.", NULL);
+ gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_packets_cb, 0, 1, row, row+1);
+
+ stop_packets_adj = (GtkAdjustment *) gtk_adjustment_new((gfloat)capture_opts.autostop_packets,
+ 1, (gfloat)INT_MAX, 1.0, 10.0, 0.0);
+ stop_packets_sb = gtk_spin_button_new (stop_packets_adj, 0, 0);
+ gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (stop_packets_sb), TRUE);
+ WIDGET_SET_SIZE(stop_packets_sb, 80, -1);
+ gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_packets_sb, 1, 2, row, row+1);
+
+ stop_packets_lb = gtk_label_new("packet(s)");
+ gtk_misc_set_alignment(GTK_MISC(stop_packets_lb), 0, 0.5);
+ gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_packets_lb, 2, 3, row, row+1);
+ row++;
+
+ /* Filesize row */
+ stop_filesize_cb = gtk_check_button_new_with_label("... after");
+ gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(stop_filesize_cb),
+ capture_opts.has_autostop_filesize);
+ SIGNAL_CONNECT(stop_filesize_cb, "toggled", capture_prep_adjust_sensitivity, cap_open_w);
+ gtk_tooltips_set_tip(tooltips, stop_filesize_cb,
+ "Stop capturing after the given amount of capture data has been captured.", NULL);
+ gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_filesize_cb, 0, 1, row, row+1);
+
+ stop_filesize_adj = (GtkAdjustment *) gtk_adjustment_new(0.0,
+ 1, (gfloat)INT_MAX, 1.0, 10.0, 0.0);
+ stop_filesize_sb = gtk_spin_button_new (stop_filesize_adj, 0, 0);
+ gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (stop_filesize_sb), TRUE);
+ WIDGET_SET_SIZE(stop_filesize_sb, 80, -1);
+ gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_filesize_sb, 1, 2, row, row+1);
+
+ stop_filesize_om = size_unit_option_menu_new(capture_opts.autostop_filesize);
+ gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_filesize_om, 2, 3, row, row+1);
+
+ value = size_unit_option_menu_set_value(capture_opts.autostop_filesize);
+ gtk_adjustment_set_value(stop_filesize_adj, (gfloat) value);
+
+ row++;
+
+ /* Duration row */
+ stop_duration_cb = gtk_check_button_new_with_label("... after");
+ gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(stop_duration_cb),
+ capture_opts.has_autostop_duration);
+ SIGNAL_CONNECT(stop_duration_cb, "toggled", capture_prep_adjust_sensitivity, cap_open_w);
+ gtk_tooltips_set_tip(tooltips, stop_duration_cb,
+ "Stop capturing after the given time is exceeded.", NULL);
+ gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_duration_cb, 0, 1, row, row+1);
+
+ stop_duration_adj = (GtkAdjustment *) gtk_adjustment_new(0.0,
+ 1, (gfloat)INT_MAX, 1.0, 10.0, 0.0);
+ stop_duration_sb = gtk_spin_button_new (stop_duration_adj, 0, 0);
+ gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (stop_duration_sb), TRUE);
+ WIDGET_SET_SIZE(stop_duration_sb, 80, -1);
+ gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_duration_sb, 1, 2, row, row+1);
+
+ stop_duration_om = time_unit_option_menu_new(capture_opts.autostop_duration);
+ gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_duration_om, 2, 3, row, row+1);
+
+ value = time_unit_option_menu_convert_value(capture_opts.autostop_duration);
+ gtk_adjustment_set_value(stop_duration_adj, (gfloat) value);
+ row++;
+
+ /* Display-related options frame */
+ display_fr = gtk_frame_new("Display Options");
+ gtk_container_add(GTK_CONTAINER(right_vb), display_fr);
+
+ display_vb = gtk_vbox_new(FALSE, 0);
+ gtk_container_border_width(GTK_CONTAINER(display_vb), 5);
+ gtk_container_add(GTK_CONTAINER(display_fr), display_vb);
+
+ /* "Update display in real time" row */
+ sync_cb = CHECK_BUTTON_NEW_WITH_MNEMONIC(
+ "_Update list of packets in real time", accel_group);
+ gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(sync_cb),
+ capture_opts.sync_mode);
+ SIGNAL_CONNECT(sync_cb, "toggled", capture_prep_adjust_sensitivity, cap_open_w);
+ gtk_tooltips_set_tip(tooltips, sync_cb,
+ "Using this option will show the captured packets immediately on the main screen. "
+ "Please note: this will slow down capturing, so increased packet drops might appear.", NULL);
+ gtk_container_add(GTK_CONTAINER(display_vb), sync_cb);
+
+ /* "Auto-scroll live update" row */
+ auto_scroll_cb = CHECK_BUTTON_NEW_WITH_MNEMONIC(
+ "_Automatic scrolling in live capture", accel_group);
+ gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(auto_scroll_cb), auto_scroll_live);
+ gtk_tooltips_set_tip(tooltips, auto_scroll_cb,
+ "This will scroll the \"Packet List\" automatically to the latest captured packet, "
+ "when the \"Update List of packets in real time\" option is used.", NULL);
+ gtk_container_add(GTK_CONTAINER(display_vb), auto_scroll_cb);
+
+ /* "Hide capture info" row */
+ hide_info_cb = CHECK_BUTTON_NEW_WITH_MNEMONIC(
+ "_Hide capture info dialog", accel_group);
+ gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(hide_info_cb), !capture_opts.show_info);
+ gtk_tooltips_set_tip(tooltips, hide_info_cb,
+ "Hide the capture info dialog while capturing.", NULL);
+ gtk_container_add(GTK_CONTAINER(display_vb), hide_info_cb);
+
+ /* Name Resolution frame */
+ resolv_fr = gtk_frame_new("Name Resolution");
+ gtk_container_add(GTK_CONTAINER(right_vb), resolv_fr);
+
+ resolv_vb = gtk_vbox_new(FALSE, 0);
+ gtk_container_border_width(GTK_CONTAINER(resolv_vb), 5);
+ gtk_container_add(GTK_CONTAINER(resolv_fr), resolv_vb);
+
+ m_resolv_cb = CHECK_BUTTON_NEW_WITH_MNEMONIC(
+ "Enable _MAC name resolution", accel_group);
+ gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(m_resolv_cb),
+ g_resolv_flags & RESOLV_MAC);
+ gtk_tooltips_set_tip(tooltips, m_resolv_cb,
+ "Perform MAC layer name resolution while capturing.", NULL);
+ gtk_container_add(GTK_CONTAINER(resolv_vb), m_resolv_cb);
+
+ n_resolv_cb = CHECK_BUTTON_NEW_WITH_MNEMONIC(
+ "Enable _network name resolution", accel_group);
+ gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(n_resolv_cb),
+ g_resolv_flags & RESOLV_NETWORK);
+ gtk_tooltips_set_tip(tooltips, n_resolv_cb,
+ "Perform network layer name resolution while capturing.", NULL);
+ gtk_container_add(GTK_CONTAINER(resolv_vb), n_resolv_cb);
+
+ t_resolv_cb = CHECK_BUTTON_NEW_WITH_MNEMONIC(
+ "Enable _transport name resolution", accel_group);
+ gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(t_resolv_cb),
+ g_resolv_flags & RESOLV_TRANSPORT);
+ gtk_tooltips_set_tip(tooltips, t_resolv_cb,
+ "Perform transport layer name resolution while capturing.", NULL);
+ gtk_container_add(GTK_CONTAINER(resolv_vb), t_resolv_cb);
+
+ /* Button row: OK and cancel buttons */
+ bbox = dlg_button_row_new(GTK_STOCK_OK, GTK_STOCK_CANCEL, GTK_STOCK_HELP, NULL);
+ gtk_box_pack_start(GTK_BOX(main_vb), bbox, FALSE, FALSE, 5);
+
+ ok_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_OK);
+ SIGNAL_CONNECT(ok_bt, "clicked", capture_prep_ok_cb, cap_open_w);
+ gtk_tooltips_set_tip(tooltips, ok_bt,
+ "Start the capture process.", NULL);
+
+ cancel_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_CANCEL);
+ gtk_tooltips_set_tip(tooltips, cancel_bt,
+ "Cancel and exit dialog.", NULL);
+ window_set_cancel_button(cap_open_w, cancel_bt, window_cancel_button_cb);
+
+ help_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_HELP);
+ gtk_tooltips_set_tip(tooltips, help_bt,
+ "Show help about capturing.", NULL);
+ SIGNAL_CONNECT(help_bt, "clicked", help_topic_cb, "Capturing");
+
+ gtk_widget_grab_default(ok_bt);
+
+ /* Attach pointers to needed widgets to the capture prefs window/object */
+ OBJECT_SET_DATA(cap_open_w, E_CAP_IFACE_KEY, if_cb);
+ OBJECT_SET_DATA(cap_open_w, E_CAP_SNAP_CB_KEY, snap_cb);
+ OBJECT_SET_DATA(cap_open_w, E_CAP_SNAP_SB_KEY, snap_sb);
+ OBJECT_SET_DATA(cap_open_w, E_CAP_LT_OM_KEY, linktype_om);
+#ifdef _WIN32
+ OBJECT_SET_DATA(cap_open_w, E_CAP_BUFFER_SIZE_SB_KEY, buffer_size_sb);
+#endif
+ OBJECT_SET_DATA(cap_open_w, E_CAP_PROMISC_KEY, promisc_cb);
+ OBJECT_SET_DATA(cap_open_w, E_CAP_FILT_KEY, filter_te);
+ OBJECT_SET_DATA(cap_open_w, E_CAP_FILE_TE_KEY, file_te);
+ OBJECT_SET_DATA(cap_open_w, E_CAP_MULTI_FILES_ON_CB_KEY, multi_files_on_cb);
+ OBJECT_SET_DATA(cap_open_w, E_CAP_RING_NBF_CB_KEY, ringbuffer_nbf_cb);
+ OBJECT_SET_DATA(cap_open_w, E_CAP_RING_NBF_SB_KEY, ringbuffer_nbf_sb);
+ OBJECT_SET_DATA(cap_open_w, E_CAP_RING_NBF_LB_KEY, ringbuffer_nbf_lb);
+ OBJECT_SET_DATA(cap_open_w, E_CAP_RING_FILESIZE_CB_KEY, ring_filesize_cb);
+ OBJECT_SET_DATA(cap_open_w, E_CAP_RING_FILESIZE_SB_KEY, ring_filesize_sb);
+ OBJECT_SET_DATA(cap_open_w, E_CAP_RING_FILESIZE_OM_KEY, ring_filesize_om);
+ OBJECT_SET_DATA(cap_open_w, E_CAP_FILE_DURATION_CB_KEY, file_duration_cb);
+ OBJECT_SET_DATA(cap_open_w, E_CAP_FILE_DURATION_SB_KEY, file_duration_sb);
+ OBJECT_SET_DATA(cap_open_w, E_CAP_FILE_DURATION_OM_KEY, file_duration_om);
+ OBJECT_SET_DATA(cap_open_w, E_CAP_SYNC_KEY, sync_cb);
+ OBJECT_SET_DATA(cap_open_w, E_CAP_AUTO_SCROLL_KEY, auto_scroll_cb);
+ OBJECT_SET_DATA(cap_open_w, E_CAP_HIDE_INFO_KEY, hide_info_cb);
+ OBJECT_SET_DATA(cap_open_w, E_CAP_STOP_PACKETS_CB_KEY, stop_packets_cb);
+ OBJECT_SET_DATA(cap_open_w, E_CAP_STOP_PACKETS_SB_KEY, stop_packets_sb);
+ OBJECT_SET_DATA(cap_open_w, E_CAP_STOP_PACKETS_LB_KEY, stop_packets_lb);
+ OBJECT_SET_DATA(cap_open_w, E_CAP_STOP_FILESIZE_CB_KEY, stop_filesize_cb);
+ OBJECT_SET_DATA(cap_open_w, E_CAP_STOP_FILESIZE_SB_KEY, stop_filesize_sb);
+ OBJECT_SET_DATA(cap_open_w, E_CAP_STOP_FILESIZE_OM_KEY, stop_filesize_om);
+ OBJECT_SET_DATA(cap_open_w, E_CAP_STOP_DURATION_CB_KEY, stop_duration_cb);
+ OBJECT_SET_DATA(cap_open_w, E_CAP_STOP_DURATION_SB_KEY, stop_duration_sb);
+ OBJECT_SET_DATA(cap_open_w, E_CAP_STOP_DURATION_OM_KEY, stop_duration_om);
+ OBJECT_SET_DATA(cap_open_w, E_CAP_STOP_FILES_CB_KEY, stop_files_cb);
+ OBJECT_SET_DATA(cap_open_w, E_CAP_STOP_FILES_SB_KEY, stop_files_sb);
+ OBJECT_SET_DATA(cap_open_w, E_CAP_STOP_FILES_LB_KEY, stop_files_lb);
+ OBJECT_SET_DATA(cap_open_w, E_CAP_M_RESOLVE_KEY, m_resolv_cb);
+ OBJECT_SET_DATA(cap_open_w, E_CAP_N_RESOLVE_KEY, n_resolv_cb);
+ OBJECT_SET_DATA(cap_open_w, E_CAP_T_RESOLVE_KEY, t_resolv_cb);
+
+ /* Set the sensitivity of various widgets as per the settings of other
+ widgets. */
+ capture_prep_adjust_sensitivity(NULL, cap_open_w);
+
+ /* Catch the "activate" signal on the text
+ entries, so that if the user types Return there, we act as if the
+ "OK" button had been selected, as happens if Return is typed if some
+ widget that *doesn't* handle the Return key has the input focus. */
+ dlg_set_activate(GTK_COMBO(if_cb)->entry, ok_bt);
+ dlg_set_activate(filter_te, ok_bt);
+ dlg_set_activate(file_te, ok_bt);
+
+ /* XXX - why does not
+
+ gtk_widget_grab_focus(if_cb);
+
+ give the initial focus to the "Interface" combo box?
+
+ Or should I phrase that as "why does GTK+ continually frustrate
+ attempts to make GUIs driveable from the keyboard?" We have to
+ go catch the activate signal on every single GtkEntry widget
+ (rather than having widgets whose activate signal is *not*
+ caught not catch the Return keystroke, so that it passes on,
+ ultimately, to the window, which can activate the default
+ widget, i.e. the "OK" button); we have to catch the "key_press_event"
+ signal and have the handler check for ESC, so that we can have ESC
+ activate the "Cancel" button; in order to support Alt+<key> mnemonics
+ for buttons and the like, we may have to construct an accelerator
+ group by hand and set up the accelerators by hand (if that even
+ works - I've not tried it yet); we have to do a "gtk_widget_grab_focus()"
+ to keep some container widget from getting the initial focus, so that
+ you don't have to tab into the first widget in order to start typing
+ in it; and it now appears that you simply *can't* make a combo box
+ get the initial focus, at least not in the obvious fashion. Sigh.... */
+
+ SIGNAL_CONNECT(cap_open_w, "delete_event", window_delete_event_cb, NULL);
+ SIGNAL_CONNECT(cap_open_w, "destroy", capture_prep_destroy_cb, NULL);
+
+ gtk_widget_show_all(cap_open_w);
+ window_present(cap_open_w);
+}
+
+static void
+capture_prep_answered_cb(gpointer dialog _U_, gint btn, gpointer data)
+{
+ switch(btn) {
+ case(ESD_BTN_SAVE):
+ /* save file first */
+ file_save_as_cmd(after_save_capture_dialog, data);
+ break;
+ case(ESD_BTN_DONT_SAVE):
+ capture_prep();
+ break;
+ case(ESD_BTN_CANCEL):
+ break;
+ default:
+ g_assert_not_reached();
+ }
+}
+
+void
+capture_prep_cb(GtkWidget *w _U_, gpointer d _U_)
+{
+ gpointer dialog;
+
+ if((cfile.state != FILE_CLOSED) && !cfile.user_saved && prefs.gui_ask_unsaved) {
+ /* user didn't saved his current file, ask him */
+ dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_SAVE_DONTSAVE_CANCEL,
+ PRIMARY_TEXT_START "Save capture file before starting a new capture?" PRIMARY_TEXT_END "\n\n"
+ "If you start a new capture without saving, your current capture data will\nbe discarded.");
+ simple_dialog_set_cb(dialog, capture_prep_answered_cb, NULL);
+ } else {
+ /* unchanged file, just capture a new one */
+ capture_prep();
+ }
+}
+
+static void
+select_link_type_cb(GtkWidget *w, gpointer data)
+{
+ int new_linktype = GPOINTER_TO_INT(data);
+ GtkWidget *linktype_om = OBJECT_GET_DATA(w, E_CAP_LT_OM_KEY);
+ int old_linktype = GPOINTER_TO_INT(OBJECT_GET_DATA(linktype_om, E_CAP_OM_LT_VALUE_KEY));
+
+ if (old_linktype != new_linktype)
+ OBJECT_SET_DATA(linktype_om, E_CAP_OM_LT_VALUE_KEY, GINT_TO_POINTER(new_linktype));
+}
+
+static void
+capture_prep_file_cb(GtkWidget *file_bt, GtkWidget *file_te)
+{
+ file_selection_browse(file_bt, file_te, "Ethereal: Specify a Capture File", FILE_SELECTION_OPEN);
+}
+
+
+static void
+capture_prep_ok_cb(GtkWidget *ok_bt _U_, gpointer parent_w) {
+ GtkWidget *if_cb, *snap_cb, *snap_sb, *promisc_cb, *filter_te,
+ *file_te, *multi_files_on_cb, *ringbuffer_nbf_sb, *ringbuffer_nbf_cb,
+ *linktype_om, *sync_cb, *auto_scroll_cb, *hide_info_cb,
+ *stop_packets_cb, *stop_packets_sb,
+ *stop_filesize_cb, *stop_filesize_sb, *stop_filesize_om,
+ *stop_duration_cb, *stop_duration_sb, *stop_duration_om,
+ *ring_filesize_cb, *ring_filesize_sb, *ring_filesize_om,
+ *file_duration_cb, *file_duration_sb, *file_duration_om,
+ *stop_files_cb, *stop_files_sb,
+ *m_resolv_cb, *n_resolv_cb, *t_resolv_cb;
+#ifdef _WIN32
+ GtkWidget *buffer_size_sb;
+#endif
+ gchar *entry_text;
+ gchar *if_text;
+ gchar *if_name;
+ const gchar *filter_text;
+ gchar *save_file;
+ const gchar *g_save_file;
+ gchar *cf_name;
+ gchar *dirname;
+ gint32 tmp;
+
+ if_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_IFACE_KEY);
+ snap_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_SNAP_CB_KEY);
+ snap_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_SNAP_SB_KEY);
+ linktype_om = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_LT_OM_KEY);
+#ifdef _WIN32
+ buffer_size_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_BUFFER_SIZE_SB_KEY);
+#endif
+ promisc_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_PROMISC_KEY);
+ filter_te = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_FILT_KEY);
+ file_te = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_FILE_TE_KEY);
+ multi_files_on_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_MULTI_FILES_ON_CB_KEY);
+ ringbuffer_nbf_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_RING_NBF_CB_KEY);
+ ringbuffer_nbf_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_RING_NBF_SB_KEY);
+ ring_filesize_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_RING_FILESIZE_CB_KEY);
+ ring_filesize_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_RING_FILESIZE_SB_KEY);
+ ring_filesize_om = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_RING_FILESIZE_OM_KEY);
+ file_duration_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_FILE_DURATION_CB_KEY);
+ file_duration_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_FILE_DURATION_SB_KEY);
+ file_duration_om = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_FILE_DURATION_OM_KEY);
+ sync_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_SYNC_KEY);
+ auto_scroll_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_AUTO_SCROLL_KEY);
+ hide_info_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_HIDE_INFO_KEY);
+ stop_packets_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_PACKETS_CB_KEY);
+ stop_packets_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_PACKETS_SB_KEY);
+ stop_filesize_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_FILESIZE_CB_KEY);
+ stop_filesize_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_FILESIZE_SB_KEY);
+ stop_filesize_om = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_FILESIZE_OM_KEY);
+ stop_duration_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_DURATION_CB_KEY);
+ stop_duration_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_DURATION_SB_KEY);
+ stop_duration_om = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_DURATION_OM_KEY);
+ stop_files_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_FILES_CB_KEY);
+ stop_files_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_FILES_SB_KEY);
+ m_resolv_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_M_RESOLVE_KEY);
+ n_resolv_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_N_RESOLVE_KEY);
+ t_resolv_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_T_RESOLVE_KEY);
+
+ entry_text =
+ g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(if_cb)->entry)));
+ if_text = g_strstrip(entry_text);
+ if_name = get_if_name(if_text);
+ if (*if_name == '\0') {
+ simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
+ "You didn't specify an interface on which to capture packets.");
+ g_free(entry_text);
+ return;
+ }
+ if (cfile.iface)
+ g_free(cfile.iface);
+ cfile.iface = g_strdup(if_name);
+ g_free(entry_text);
+
+ capture_opts.linktype =
+ GPOINTER_TO_INT(OBJECT_GET_DATA(linktype_om, E_CAP_OM_LT_VALUE_KEY));
+
+#ifdef _WIN32
+ capture_opts.buffer_size =
+ gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(buffer_size_sb));
+#endif
+
+ capture_opts.has_snaplen =
+ gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(snap_cb));
+ if (capture_opts.has_snaplen) {
+ capture_opts.snaplen =
+ gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(snap_sb));
+ if (capture_opts.snaplen < 1)
+ capture_opts.snaplen = WTAP_MAX_PACKET_SIZE;
+ else if (capture_opts.snaplen < MIN_PACKET_SIZE)
+ capture_opts.snaplen = MIN_PACKET_SIZE;
+ }
+
+ capture_opts.promisc_mode =
+ gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(promisc_cb));
+
+ /* XXX - don't try to get clever and set "cfile.filter" to NULL if the
+ filter string is empty, as an indication that we don't have a filter
+ and thus don't have to set a filter when capturing - the version of
+ libpcap in Red Hat Linux 6.1, and versions based on later patches
+ in that series, don't bind the AF_PACKET socket to an interface
+ until a filter is set, which means they aren't bound at all if
+ no filter is set, which means no packets arrive as input on that
+ socket, which means Ethereal never sees any packets. */
+ filter_text = gtk_entry_get_text(GTK_ENTRY(filter_te));
+ if (cfile.cfilter)
+ g_free(cfile.cfilter);
+ g_assert(filter_text != NULL);
+ cfile.cfilter = g_strdup(filter_text);
+
+ g_save_file = gtk_entry_get_text(GTK_ENTRY(file_te));
+ if (g_save_file && g_save_file[0]) {
+ /* User specified a file to which the capture should be written. */
+ save_file = g_strdup(g_save_file);
+ /* Save the directory name for future file dialogs. */
+ cf_name = g_strdup(g_save_file);
+ dirname = get_dirname(cf_name); /* Overwrites cf_name */
+ set_last_open_dir(dirname);
+ g_free(cf_name);
+ } else {
+ /* User didn't specify a file; save to a temporary file. */
+ save_file = NULL;
+ }
+
+ capture_opts.has_autostop_packets =
+ gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_packets_cb));
+ if (capture_opts.has_autostop_packets)
+ capture_opts.autostop_packets =
+ gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(stop_packets_sb));
+
+ capture_opts.has_autostop_duration =
+ gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_duration_cb));
+ if (capture_opts.has_autostop_duration) {
+ capture_opts.autostop_duration =
+ gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(stop_duration_sb));
+ capture_opts.autostop_duration =
+ time_unit_option_menu_get_value(stop_duration_om, capture_opts.autostop_duration);
+ }
+
+ capture_opts.sync_mode =
+ gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(sync_cb));
+
+ auto_scroll_live =
+ gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(auto_scroll_cb));
+
+ capture_opts.show_info =
+ !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(hide_info_cb));
+
+ g_resolv_flags |= g_resolv_flags & RESOLV_CONCURRENT;
+ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m_resolv_cb)))
+ g_resolv_flags |= RESOLV_MAC;
+ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(n_resolv_cb)))
+ g_resolv_flags |= RESOLV_NETWORK;
+ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t_resolv_cb)))
+ g_resolv_flags |= RESOLV_TRANSPORT;
+
+ capture_opts.has_ring_num_files =
+ gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ringbuffer_nbf_cb));
+
+ capture_opts.ring_num_files =
+ gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(ringbuffer_nbf_sb));
+ if (capture_opts.ring_num_files > RINGBUFFER_MAX_NUM_FILES)
+ capture_opts.ring_num_files = RINGBUFFER_MAX_NUM_FILES;
+#if RINGBUFFER_MIN_NUM_FILES > 0
+ else if (capture_opts.ring_num_files < RINGBUFFER_MIN_NUM_FILES)
+ capture_opts.ring_num_files = RINGBUFFER_MIN_NUM_FILES;
+#endif
+
+ capture_opts.multi_files_on =
+ gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(multi_files_on_cb));
+
+ if(capture_opts.sync_mode)
+ capture_opts.multi_files_on = FALSE;
+
+ if (capture_opts.multi_files_on) {
+ capture_opts.has_autostop_filesize =
+ gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ring_filesize_cb));
+ if (capture_opts.has_autostop_filesize) {
+ tmp = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(ring_filesize_sb));
+ tmp = size_unit_option_menu_convert_value(ring_filesize_om, tmp);
+ if(tmp != 0) {
+ capture_opts.autostop_filesize = tmp;
+ } else {
+ simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
+ PRIMARY_TEXT_START "Multiple files: Requested filesize too large!\n\n" PRIMARY_TEXT_END
+ "The setting \"Next file every x byte(s)\" can't be greater than %u bytes (2GB).", G_MAXINT);
+ return;
+ }
+ }
+
+ /* test if the settings are ok for a ringbuffer */
+ if (save_file == NULL) {
+ simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
+ PRIMARY_TEXT_START "Multiple files: No capture file name given!\n\n" PRIMARY_TEXT_END
+ "You must specify a filename if you want to use multiple files.");
+ return;
+ } else if (!capture_opts.has_autostop_filesize) {
+ simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
+ PRIMARY_TEXT_START "Multiple files: No file limit given!\n\n" PRIMARY_TEXT_END
+ "You must specify a file size at which is switched to the next capture file\n"
+ "if you want to use multiple files.");
+ g_free(save_file);
+ return;
+ }
+ } else {
+ capture_opts.has_autostop_filesize =
+ gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_filesize_cb));
+ if (capture_opts.has_autostop_filesize) {
+ tmp = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(stop_filesize_sb));
+ tmp = size_unit_option_menu_convert_value(stop_filesize_om, tmp);
+ if(tmp != 0) {
+ capture_opts.autostop_filesize = tmp;
+ } else {
+ simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
+ PRIMARY_TEXT_START "Stop Capture: Requested filesize too large!\n\n" PRIMARY_TEXT_END
+ "The setting \"... after x byte(s)\" can't be greater than %u bytes (2GB).", G_MAXINT);
+ return;
+ }
+ }
+ }
+
+ capture_opts.has_file_duration =
+ gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(file_duration_cb));
+ if (capture_opts.has_file_duration) {
+ capture_opts.file_duration =
+ gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(file_duration_sb));
+ capture_opts.file_duration =
+ time_unit_option_menu_get_value(file_duration_om, capture_opts.file_duration);
+ }
+
+ capture_opts.has_autostop_files =
+ gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_files_cb));
+ if (capture_opts.has_autostop_files)
+ capture_opts.autostop_files =
+ gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(stop_files_sb));
+
+ window_destroy(GTK_WIDGET(parent_w));
+
+ do_capture(save_file);
+ if (save_file != NULL)
+ g_free(save_file);
+}
+
+static void
+capture_prep_destroy_cb(GtkWidget *win, gpointer user_data _U_)
+{
+ GtkWidget *fs;
+
+ /* Is there a file selection dialog associated with this
+ Capture Options dialog? */
+ fs = OBJECT_GET_DATA(win, E_FILE_SEL_DIALOG_PTR_KEY);
+
+ if (fs != NULL) {
+ /* Yes. Destroy it. */
+ window_destroy(fs);
+ }
+
+ /* Note that we no longer have a "Capture Options" dialog box. */
+ cap_open_w = NULL;
+}
+
+static void
+capture_prep_interface_changed_cb(GtkWidget *entry, gpointer argp)
+{
+ GtkWidget *linktype_om = argp;
+
+ set_link_type_list(linktype_om, entry);
+}
+
+/*
+ * Adjust the sensitivity of various widgets as per the current setting
+ * of other widgets.
+ */
+static void
+capture_prep_adjust_sensitivity(GtkWidget *tb _U_, gpointer parent_w)
+{
+ GtkWidget *if_cb,
+ *snap_cb, *snap_sb,
+ *multi_files_on_cb, *ringbuffer_nbf_cb, *ringbuffer_nbf_sb, *ringbuffer_nbf_lb,
+ *ring_filesize_cb, *ring_filesize_sb, *ring_filesize_om,
+ *file_duration_cb, *file_duration_sb, *file_duration_om,
+ *sync_cb, *auto_scroll_cb, *hide_info_cb,
+ *stop_packets_cb, *stop_packets_sb, *stop_packets_lb,
+ *stop_filesize_cb, *stop_filesize_sb, *stop_filesize_om,
+ *stop_duration_cb, *stop_duration_sb, *stop_duration_om,
+ *stop_files_cb, *stop_files_sb, *stop_files_lb;
+
+
+ if_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_IFACE_KEY);
+ snap_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_SNAP_CB_KEY);
+ snap_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_SNAP_SB_KEY);
+ multi_files_on_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_MULTI_FILES_ON_CB_KEY);
+ ringbuffer_nbf_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_RING_NBF_CB_KEY);
+ ringbuffer_nbf_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_RING_NBF_SB_KEY);
+ ringbuffer_nbf_lb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_RING_NBF_LB_KEY);
+ ring_filesize_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_RING_FILESIZE_CB_KEY);
+ ring_filesize_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_RING_FILESIZE_SB_KEY);
+ ring_filesize_om = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_RING_FILESIZE_OM_KEY);
+ file_duration_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_FILE_DURATION_CB_KEY);
+ file_duration_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_FILE_DURATION_SB_KEY);
+ file_duration_om = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_FILE_DURATION_OM_KEY);
+ sync_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_SYNC_KEY);
+ auto_scroll_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_AUTO_SCROLL_KEY);
+ hide_info_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_HIDE_INFO_KEY);
+ stop_packets_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_PACKETS_CB_KEY);
+ stop_packets_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_PACKETS_SB_KEY);
+ stop_packets_lb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_PACKETS_LB_KEY);
+ stop_filesize_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_FILESIZE_CB_KEY);
+ stop_filesize_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_FILESIZE_SB_KEY);
+ stop_filesize_om = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_FILESIZE_OM_KEY);
+ stop_duration_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_DURATION_CB_KEY);
+ stop_duration_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_DURATION_SB_KEY);
+ stop_duration_om = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_DURATION_OM_KEY);
+ stop_files_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_FILES_CB_KEY);
+ stop_files_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_FILES_SB_KEY);
+ stop_files_lb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_STOP_FILES_LB_KEY);
+
+ /* The snapshot length spinbox is sensitive if the "Limit each packet
+ to" checkbox is on. */
+ gtk_widget_set_sensitive(GTK_WIDGET(snap_sb),
+ gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(snap_cb)));
+
+
+ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(sync_cb))) {
+ /* "Update list of packets in real time" captures enabled; we don't
+ support ring buffer mode for those captures, so turn ring buffer
+ mode off if it's on, and make its toggle button, and the spin
+ button for the number of ring buffer files (and the spin button's
+ label), insensitive. */
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(multi_files_on_cb), FALSE);
+ gtk_widget_set_sensitive(GTK_WIDGET(multi_files_on_cb), FALSE);
+
+ /* Auto-scroll mode is meaningful only in "Update list of packets
+ in real time" captures, so make its toggle button sensitive. */
+ gtk_widget_set_sensitive(GTK_WIDGET(auto_scroll_cb), TRUE);
+
+ gtk_widget_set_sensitive(GTK_WIDGET(hide_info_cb), TRUE);
+ } else {
+ /* "Update list of packets in real time" captures disabled; that
+ means ring buffer mode is OK, so make its toggle button
+ sensitive. */
+ gtk_widget_set_sensitive(GTK_WIDGET(multi_files_on_cb), TRUE);
+
+ /* Auto-scroll mode is meaningful only in "Update list of packets
+ in real time" captures, so make its toggle button insensitive. */
+ gtk_widget_set_sensitive(GTK_WIDGET(auto_scroll_cb), FALSE);
+
+ gtk_widget_set_sensitive(GTK_WIDGET(hide_info_cb), FALSE);
+ }
+
+ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(multi_files_on_cb))) {
+ /* Ring buffer mode enabled. */
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ring_filesize_cb), TRUE);
+
+ gtk_widget_set_sensitive(GTK_WIDGET(ringbuffer_nbf_cb), TRUE);
+ gtk_widget_set_sensitive(GTK_WIDGET(ringbuffer_nbf_sb),
+ gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ringbuffer_nbf_cb)));
+ gtk_widget_set_sensitive(GTK_WIDGET(ringbuffer_nbf_lb),
+ gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ringbuffer_nbf_cb)));
+
+ /* The ring filesize spinbox is sensitive if the "Next capture file
+ after N kilobytes" checkbox is on. */
+ gtk_widget_set_sensitive(GTK_WIDGET(ring_filesize_cb), TRUE);
+ gtk_widget_set_sensitive(GTK_WIDGET(ring_filesize_sb),
+ gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ring_filesize_cb)));
+ gtk_widget_set_sensitive(GTK_WIDGET(ring_filesize_om),
+ gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ring_filesize_cb)));
+
+ /* The ring duration spinbox is sensitive if the "Next capture file
+ after N seconds" checkbox is on. */
+ gtk_widget_set_sensitive(GTK_WIDGET(file_duration_cb), TRUE);
+ gtk_widget_set_sensitive(GTK_WIDGET(file_duration_sb),
+ gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(file_duration_cb)));
+ gtk_widget_set_sensitive(GTK_WIDGET(file_duration_om),
+ gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(file_duration_cb)));
+
+ gtk_widget_set_sensitive(GTK_WIDGET(stop_filesize_cb), FALSE);
+ gtk_widget_set_sensitive(GTK_WIDGET(stop_filesize_sb), FALSE);
+ gtk_widget_set_sensitive(GTK_WIDGET(stop_filesize_om), FALSE);
+
+ gtk_widget_set_sensitive(GTK_WIDGET(stop_files_cb), TRUE);
+ gtk_widget_set_sensitive(GTK_WIDGET(stop_files_sb),
+ gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_files_cb)));
+ gtk_widget_set_sensitive(GTK_WIDGET(stop_files_lb),
+ gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_files_cb)));
+ } else {
+ /* Ring buffer mode disabled. */
+ gtk_widget_set_sensitive(GTK_WIDGET(ringbuffer_nbf_cb), FALSE);
+ gtk_widget_set_sensitive(GTK_WIDGET(ringbuffer_nbf_sb), FALSE);
+ gtk_widget_set_sensitive(GTK_WIDGET(ringbuffer_nbf_lb), FALSE);
+
+ gtk_widget_set_sensitive(GTK_WIDGET(ring_filesize_cb), FALSE);
+ gtk_widget_set_sensitive(GTK_WIDGET(ring_filesize_sb),FALSE);
+ gtk_widget_set_sensitive(GTK_WIDGET(ring_filesize_om),FALSE);
+
+ gtk_widget_set_sensitive(GTK_WIDGET(file_duration_cb), FALSE);
+ gtk_widget_set_sensitive(GTK_WIDGET(file_duration_sb),FALSE);
+ gtk_widget_set_sensitive(GTK_WIDGET(file_duration_om),FALSE);
+
+ /* The maximum file size spinbox is sensitive if the "Stop capture
+ after N kilobytes" checkbox is on. */
+ gtk_widget_set_sensitive(GTK_WIDGET(stop_filesize_cb), TRUE);
+ gtk_widget_set_sensitive(GTK_WIDGET(stop_filesize_sb),
+ gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_filesize_cb)));
+ gtk_widget_set_sensitive(GTK_WIDGET(stop_filesize_om),
+ gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_filesize_cb)));
+
+ gtk_widget_set_sensitive(GTK_WIDGET(stop_files_cb), FALSE);
+ gtk_widget_set_sensitive(GTK_WIDGET(stop_files_sb), FALSE);
+ gtk_widget_set_sensitive(GTK_WIDGET(stop_files_lb), FALSE);
+ }
+
+ /* The maximum packet count spinbox is sensitive if the "Stop capture
+ after N packets" checkbox is on. */
+ gtk_widget_set_sensitive(GTK_WIDGET(stop_packets_sb),
+ gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_packets_cb)));
+ gtk_widget_set_sensitive(GTK_WIDGET(stop_packets_lb),
+ gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_packets_cb)));
+
+ /* The capture duration spinbox is sensitive if the "Stop capture
+ after N seconds" checkbox is on. */
+ gtk_widget_set_sensitive(GTK_WIDGET(stop_duration_sb),
+ gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_duration_cb)));
+ gtk_widget_set_sensitive(GTK_WIDGET(stop_duration_om),
+ gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_duration_cb)));
+}
+
+#endif /* HAVE_LIBPCAP */
diff --git a/gtk/capture_dlg.h b/gtk/capture_dlg.h index d9a0ac62e2..c6df90775b 100644 --- a/gtk/capture_dlg.h +++ b/gtk/capture_dlg.h @@ -1,52 +1,67 @@ -/* capture_dlg.h - * Definitions for packet capture windows - * - * $Id: capture_dlg.h,v 1.6 2004/06/04 20:05:30 ulfl Exp $ - * - * Ethereal - Network traffic analyzer - * By Gerald Combs <gerald@zing.org> - * Copyright 1998 Gerald Combs - * - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef __CAPTURE_DLG_H__ -#define __CAPTURE_DLG_H__ - -/** @file - * "Capture Options" dialog box. - * @ingroup dialog_group - */ - -/** User requested the "Capture Options" dialog box by menu or toolbar. - * - * @param widget parent widget (unused) - * @param data unused - */ -void capture_prep_cb(GtkWidget *widget, gpointer data); - -/** User requested capture stop by menu or toolbar. - * - * @param widget parent widget (unused) - * @param data unused - */ -void capture_stop_cb(GtkWidget *widget, gpointer data); - -/** Create the "Capture Options" dialog box. - */ -void capture_prep(void); - -#endif /* capture.h */ +/* capture_dlg.h
+ * Definitions for packet capture windows
+ *
+ * $Id: capture_dlg.h,v 1.6 2004/06/04 20:05:30 ulfl Exp $
+ *
+ * Ethereal - Network traffic analyzer
+ * By Gerald Combs <gerald@zing.org>
+ * Copyright 1998 Gerald Combs
+ *
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __CAPTURE_DLG_H__
+#define __CAPTURE_DLG_H__
+
+/** @file
+ * "Capture Options" dialog box.
+ * @ingroup dialog_group
+ */
+
+/** User requested the "Capture Options" dialog box by menu or toolbar.
+ *
+ * @param widget parent widget (unused)
+ * @param data unused
+ */
+void capture_prep_cb(GtkWidget *widget, gpointer data);
+
+/** User requested capture stop by menu or toolbar.
+ *
+ * @param widget parent widget (unused)
+ * @param data unused
+ */
+void capture_stop_cb(GtkWidget *widget, gpointer data);
+
+/** Create the "Capture Options" dialog box.
+ */
+void capture_prep(void);
+
+/** User requested the "Capture Interfaces" dialog box by menu or toolbar.
+ *
+ * @param widget parent widget (unused)
+ * @param data unused
+ */
+void
+capture_if_cb(GtkWidget *widget, gpointer data);
+
+/** User requested the "Capture Interfaces" dialog box by menu or toolbar.
+ *
+ * @param capture_in_progress capture is in progress
+ */
+void
+set_capture_if_dialog_for_capture_in_progress(gboolean capture_in_progress);
+
+#endif /* capture.h */
diff --git a/gtk/capture_if_dlg.c b/gtk/capture_if_dlg.c new file mode 100644 index 0000000000..f4d7eb21ae --- /dev/null +++ b/gtk/capture_if_dlg.c @@ -0,0 +1,486 @@ +/* capture_if_dlg.c
+ * Routines for the capture interface dialog
+ *
+ * $Id: capture_if_dlg.c,v 1.254 2004/06/30 06:58:56 guy Exp $
+ *
+ * Ethereal - Network traffic analyzer
+ * By Gerald Combs <gerald@ethereal.com>
+ * Copyright 1998 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+/* With MSVC and a libethereal.dll this file needs to import some variables
+ in a special way. Therefore _NEED_VAR_IMPORT_ is defined. */
+/*#define _NEED_VAR_IMPORT_*/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#ifdef HAVE_LIBPCAP
+
+#ifdef HAVE_SYS_STAT_H
+# include <sys/stat.h>
+#endif
+
+#ifdef HAVE_SYS_WAIT_H
+# include <sys/wait.h>
+#endif
+
+
+#include <pcap.h>
+
+#include <gtk/gtk.h>
+
+#include "globals.h"
+#include "pcap-util.h"
+
+#ifdef _WIN32
+#include "capture-wpcap.h"
+#endif
+
+#include "compat_macros.h"
+#include "simple_dialog.h"
+#include "capture_dlg.h"
+
+#include "ui_util.h"
+#include "dlg_utils.h"
+
+#include "wtap.h"
+#include "capture.h"
+
+
+extern char *iptos(u_long in);
+
+extern gboolean is_capture_in_progress(void);
+
+/*
+ * Keep a static pointer to the current "Capture Interfaces" window, if
+ * any, so that if somebody tries to do "Capture:Start" while there's
+ * already a "Capture Interfaces" window up, we just pop up the existing
+ * one, rather than creating a new one.
+ */
+static GtkWidget *cap_if_w;
+
+GList *if_data = NULL;
+
+guint timer_id;
+
+GtkWidget *stop_bt;
+
+GList *if_list;
+
+/*
+ * Timeout, in milliseconds, for reads from the stream of captured packets.
+ */
+#define CAP_READ_TIMEOUT 250
+
+
+/* the "runtime" data of one interface */
+typedef struct if_dlg_data_s {
+ pcap_t *pch;
+ GtkWidget *device_lb;
+ GtkWidget *descr_lb;
+ GtkWidget *ip_lb;
+ GtkWidget *curr_lb;
+ GtkWidget *last_lb;
+ GtkWidget *capture_bt;
+ GtkWidget *prepare_bt;
+ guint32 last_packets;
+ gchar *device;
+} if_dlg_data_t;
+
+void update_if(if_dlg_data_t *if_dlg_data);
+
+
+/* start capture button was pressed */
+static void
+capture_do_cb(GtkWidget *capture_bt _U_, gpointer if_data)
+{
+ if_dlg_data_t *if_dlg_data = if_data;
+
+ if (cfile.iface)
+ g_free(cfile.iface);
+
+ cfile.iface = g_strdup(if_dlg_data->device);
+
+ do_capture(NULL /* save_file */);
+}
+
+
+/* prepare capture button was pressed */
+static void
+capture_prepare_cb(GtkWidget *prepare_bt _U_, gpointer if_data)
+{
+ if_dlg_data_t *if_dlg_data = if_data;
+
+ if (cfile.iface)
+ g_free(cfile.iface);
+
+ cfile.iface = g_strdup(if_dlg_data->device);
+
+ capture_prep_cb(NULL, NULL);
+}
+
+
+/* open a single interface */
+void
+open_if(gchar *name, if_dlg_data_t *if_dlg_data)
+{
+ gchar open_err_str[PCAP_ERRBUF_SIZE];
+
+ if_dlg_data->pch = pcap_open_live(name,
+ WTAP_MAX_PACKET_SIZE,
+ capture_opts.promisc_mode, CAP_READ_TIMEOUT,
+ open_err_str);
+
+ if (if_dlg_data->pch != NULL) {
+ update_if(if_dlg_data);
+ } else {
+ printf("open_if: %s\n", open_err_str);
+ gtk_label_set_text(GTK_LABEL(if_dlg_data->curr_lb), "error");
+ gtk_label_set_text(GTK_LABEL(if_dlg_data->last_lb), "error");
+ }
+}
+
+/* update a single interface */
+void
+update_if(if_dlg_data_t *if_dlg_data)
+{
+ struct pcap_stat stats;
+ gchar *str;
+ guint diff;
+
+
+ /* pcap_stats() stats values differ on libpcap and winpcap!
+ * libpcap: returns the number of packets since pcap_open_live
+ * winpcap: returns the number of packets since the last pcap_stats call
+ */
+ if (if_dlg_data->pch) {
+ if(pcap_stats(if_dlg_data->pch, &stats) >= 0) {
+#if WIN32
+ diff = stats.ps_recv - if_dlg_data->last_packets;
+ if_dlg_data->last_packets = stats.ps_recv;
+#else
+ diff = stats.ps_recv;
+ if_dlg_data->last_packets = stats.ps_recv + if_dlg_data->last_packets;
+#endif
+
+ str = g_strdup_printf("%u", if_dlg_data->last_packets);
+ gtk_label_set_text(GTK_LABEL(if_dlg_data->curr_lb), str);
+ g_free(str);
+ str = g_strdup_printf("%u", diff);
+ gtk_label_set_text(GTK_LABEL(if_dlg_data->last_lb), str);
+ g_free(str);
+
+ gtk_widget_set_sensitive(if_dlg_data->curr_lb, diff);
+ gtk_widget_set_sensitive(if_dlg_data->last_lb, diff);
+ } else {
+ gtk_label_set_text(GTK_LABEL(if_dlg_data->curr_lb), "error");
+ gtk_label_set_text(GTK_LABEL(if_dlg_data->last_lb), "error");
+ }
+ }
+}
+
+
+/* close a single interface */
+void
+close_if(if_dlg_data_t *if_dlg_data)
+{
+ if(if_dlg_data->pch)
+ pcap_close(if_dlg_data->pch);
+}
+
+
+
+/* update all interfaces */
+gboolean
+update_all(gpointer data)
+{
+ GList *curr;
+ int ifs;
+
+
+ if(!cap_if_w) {
+ return FALSE;
+ }
+
+ for(ifs = 0; (curr = g_list_nth(data, ifs)); ifs++) {
+ update_if(curr->data);
+ }
+
+ return TRUE;
+}
+
+
+/* a live capture has started or stopped */
+void
+set_capture_if_dialog_for_capture_in_progress(gboolean capture_in_progress)
+{
+ GList *curr;
+ int ifs;
+
+ if(cap_if_w) {
+ gtk_widget_set_sensitive(stop_bt, capture_in_progress);
+
+ for(ifs = 0; (curr = g_list_nth(if_data, ifs)); ifs++) {
+ if_dlg_data_t *if_dlg_data = curr->data;
+
+ gtk_widget_set_sensitive(if_dlg_data->capture_bt, !capture_in_progress);
+ gtk_widget_set_sensitive(if_dlg_data->prepare_bt, !capture_in_progress);
+ }
+ }
+}
+
+
+/* the window was closed, cleanup things */
+static void
+capture_if_destroy_cb(GtkWidget *win _U_, gpointer user_data _U_)
+{
+ GList *curr;
+ int ifs;
+
+ gtk_timeout_remove(timer_id);
+
+ for(ifs = 0; (curr = g_list_nth(if_data, ifs)); ifs++) {
+ if_dlg_data_t *if_dlg_data = curr->data;
+
+ close_if(if_dlg_data);
+ g_free(curr->data);
+ }
+
+ if_data = NULL;
+
+ free_interface_list(if_list);
+
+ /* Note that we no longer have a "Capture Options" dialog box. */
+ cap_if_w = NULL;
+}
+
+
+/* start getting capture stats from all interfaces */
+void
+capture_if_cb(GtkWidget *w _U_, gpointer d _U_)
+{
+ GtkWidget *main_vb, *bbox, *close_bt;
+
+ GtkWidget *if_tb;
+ GtkWidget *if_lb;
+#if GTK_MAJOR_VERSION < 2
+ GtkAccelGroup *accel_group;
+#endif
+ GtkTooltips *tooltips;
+ int err;
+ char err_str[PCAP_ERRBUF_SIZE];
+ gchar *cant_get_if_list_errstr;
+ int row;
+ if_dlg_data_t *if_dlg_data;
+ int ifs;
+ GList *curr;
+ if_info_t *if_info;
+ GSList *curr_ip;
+ guint32 ip_addr;
+ GString *if_tool_str = g_string_new("");
+ gchar *tmp_str;
+
+
+ if (cap_if_w != NULL) {
+ /* There's already a "Capture Interfaces" dialog box; reactivate it. */
+ reactivate_window(cap_if_w);
+ return;
+ }
+
+#ifdef _WIN32
+ /* Is WPcap loaded? */
+ if (!has_wpcap) {
+ simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
+ "Unable to load WinPcap (wpcap.dll); Ethereal will not be able\n"
+ "to capture packets.\n\n"
+ "In order to capture packets, WinPcap must be installed; see\n"
+ "\n"
+ " http://winpcap.polito.it/\n"
+ "\n"
+ "or the mirror at\n"
+ "\n"
+ " http://winpcap.mirror.ethereal.com/\n"
+ "\n"
+ "or the mirror at\n"
+ "\n"
+ " http://www.mirrors.wiretapped.net/security/packet-capture/winpcap/\n"
+ "\n"
+ "for a downloadable version of WinPcap and for instructions\n"
+ "on how to install WinPcap.");
+ return;
+ }
+#endif
+
+ if_list = get_interface_list(&err, err_str);
+ if (if_list == NULL && err == CANT_GET_INTERFACE_LIST) {
+ cant_get_if_list_errstr = cant_get_if_list_error_message(err_str);
+ simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s",
+ cant_get_if_list_errstr);
+ g_free(cant_get_if_list_errstr);
+ return;
+ }
+
+ cap_if_w = window_new(GTK_WINDOW_TOPLEVEL, "Ethereal: Capture Interfaces");
+
+ tooltips = gtk_tooltips_new();
+
+#if GTK_MAJOR_VERSION < 2
+ /* Accelerator group for the accelerators (or, as they're called in
+ Windows and, I think, in Motif, "mnemonics"; Alt+<key> is a mnemonic,
+ Ctrl+<key> is an accelerator). */
+ accel_group = gtk_accel_group_new();
+ gtk_window_add_accel_group(GTK_WINDOW(cap_if_w), accel_group);
+#endif
+
+ main_vb = gtk_vbox_new(FALSE, 0);
+ gtk_container_border_width(GTK_CONTAINER(main_vb), 5);
+ gtk_container_add(GTK_CONTAINER(cap_if_w), main_vb);
+
+
+ if_tb = gtk_table_new(6,1, FALSE);
+ gtk_table_set_row_spacings(GTK_TABLE(if_tb), 3);
+ gtk_table_set_col_spacings(GTK_TABLE(if_tb), 3);
+ gtk_container_add(GTK_CONTAINER(main_vb), if_tb);
+
+ row = 0;
+
+#ifndef WIN32
+ if_lb = gtk_label_new("Device");
+ gtk_table_attach_defaults(GTK_TABLE(if_tb), if_lb, 0, 1, row, row+1);
+#endif
+
+ if_lb = gtk_label_new("Description");
+ gtk_table_attach_defaults(GTK_TABLE(if_tb), if_lb, 1, 2, row, row+1);
+
+ if_lb = gtk_label_new(" IP ");
+ gtk_table_attach_defaults(GTK_TABLE(if_tb), if_lb, 2, 3, row, row+1);
+
+ if_lb = gtk_label_new("Packets");
+ gtk_table_attach_defaults(GTK_TABLE(if_tb), if_lb, 3, 4, row, row+1);
+
+ if_lb = gtk_label_new(" Packets/s ");
+ gtk_table_attach_defaults(GTK_TABLE(if_tb), if_lb, 4, 5, row, row+1);
+
+ stop_bt = BUTTON_NEW_FROM_STOCK(GTK_STOCK_STOP);
+ gtk_tooltips_set_tip(tooltips, stop_bt,
+ "Stop a running capture.", NULL);
+ gtk_table_attach_defaults(GTK_TABLE(if_tb), stop_bt, 5, 7, row, row+1);
+ SIGNAL_CONNECT(stop_bt, "clicked", capture_stop_cb, NULL);
+
+ row++;
+
+ for(ifs = 0; (curr = g_list_nth(if_list, ifs)); ifs++) {
+ g_string_assign(if_tool_str, "");
+ if_info = curr->data;
+ if_dlg_data = g_malloc0(sizeof(if_dlg_data_t));
+
+ /* device name */
+ if_dlg_data->device_lb = gtk_label_new(if_info->name);
+ if_dlg_data->device = if_info->name;
+#ifndef WIN32
+ gtk_misc_set_alignment(GTK_MISC(if_dlg_data->device_lb), 0.0, 0.5);
+ gtk_table_attach_defaults(GTK_TABLE(if_tb), if_dlg_data->device_lb, 0, 1, row, row+1);
+#endif
+ g_string_append(if_tool_str, "Device: ");
+ g_string_append(if_tool_str, if_info->name);
+ g_string_append(if_tool_str, "\n");
+
+ /* description */
+ if_dlg_data->descr_lb = gtk_label_new(if_info->description);
+ gtk_misc_set_alignment(GTK_MISC(if_dlg_data->descr_lb), 0.0, 0.5);
+ gtk_table_attach_defaults(GTK_TABLE(if_tb), if_dlg_data->descr_lb, 1, 2, row, row+1);
+
+ g_string_append(if_tool_str, "Description: ");
+ g_string_append(if_tool_str, if_info->description);
+ g_string_append(if_tool_str, "\n");
+
+ /* IP address */
+ /* only one IP address will be shown */
+ g_string_append(if_tool_str, "IP: ");
+ curr_ip = g_slist_nth(if_info->ip_addr, 0);
+ if(curr_ip) {
+ ip_addr = *((guint32 *)curr_ip->data);
+ if_dlg_data->ip_lb = gtk_label_new(iptos(ip_addr));
+ g_string_append(if_tool_str, iptos(ip_addr));
+ } else {
+ ip_addr = 0;
+ if_dlg_data->ip_lb = gtk_label_new("unknown");
+ g_string_append(if_tool_str, "unknown");
+ }
+ gtk_widget_set_sensitive(if_dlg_data->ip_lb, ip_addr);
+ gtk_table_attach_defaults(GTK_TABLE(if_tb), if_dlg_data->ip_lb, 2, 3, row, row+1);
+ g_string_append(if_tool_str, "\n");
+
+ /* packets */
+ if_dlg_data->curr_lb = gtk_label_new("-");
+ gtk_table_attach_defaults(GTK_TABLE(if_tb), if_dlg_data->curr_lb, 3, 4, row, row+1);
+
+ /* packets/s */
+ if_dlg_data->last_lb = gtk_label_new("-");
+ gtk_table_attach_defaults(GTK_TABLE(if_tb), if_dlg_data->last_lb, 4, 5, row, row+1);
+
+ /* capture button */
+ if_dlg_data->capture_bt = gtk_button_new_with_label("Capture");
+ SIGNAL_CONNECT(if_dlg_data->capture_bt, "clicked", capture_do_cb, if_dlg_data);
+ tmp_str = g_strdup_printf("Immediately start a capture from this interface:\n\n%s", if_tool_str->str);
+ gtk_tooltips_set_tip(tooltips, if_dlg_data->capture_bt,
+ tmp_str, NULL);
+ g_free(tmp_str);
+ gtk_table_attach_defaults(GTK_TABLE(if_tb), if_dlg_data->capture_bt, 5, 6, row, row+1);
+
+ /* prepare button */
+ if_dlg_data->prepare_bt = gtk_button_new_with_label("Prepare");
+ SIGNAL_CONNECT(if_dlg_data->prepare_bt, "clicked", capture_prepare_cb, if_dlg_data);
+ gtk_tooltips_set_tip(tooltips, if_dlg_data->prepare_bt,
+ "Open the capture options dialog with this interface selected.", NULL);
+ gtk_table_attach_defaults(GTK_TABLE(if_tb), if_dlg_data->prepare_bt, 6, 7, row, row+1);
+
+ open_if(if_info->name, if_dlg_data);
+
+ if_data = g_list_append(if_data, if_dlg_data);
+
+ row++;
+ }
+
+ g_string_free(if_tool_str, TRUE);
+
+ /* Button row: close button */
+ bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL);
+ gtk_box_pack_start(GTK_BOX(main_vb), bbox, FALSE, FALSE, 5);
+
+ close_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_CLOSE);
+ window_set_cancel_button(cap_if_w, close_bt, window_cancel_button_cb);
+ gtk_tooltips_set_tip(tooltips, close_bt, "Close this window.", NULL);
+
+ gtk_widget_grab_default(close_bt);
+
+ SIGNAL_CONNECT(cap_if_w, "delete_event", window_delete_event_cb, NULL);
+ SIGNAL_CONNECT(cap_if_w, "destroy", capture_if_destroy_cb, NULL);
+
+ gtk_widget_show_all(cap_if_w);
+ window_present(cap_if_w);
+
+ set_capture_if_dialog_for_capture_in_progress(is_capture_in_progress());
+
+ /* update the interface list every 1000ms */
+ timer_id = gtk_timeout_add(1000, update_all, if_data);
+}
+
+
+#endif /* HAVE_LIBPCAP */
diff --git a/gtk/menu.c b/gtk/menu.c index 2964519565..b642d02b23 100644 --- a/gtk/menu.c +++ b/gtk/menu.c @@ -1,1824 +1,1828 @@ -/* menu.c - * Menu routines - * - * $Id: menu.c,v 1.208 2004/07/07 16:26:52 ulfl Exp $ - * - * Ethereal - Network traffic analyzer - * By Gerald Combs <gerald@ethereal.com> - * Copyright 1998 Gerald Combs - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include <gtk/gtk.h> - -#include <string.h> - -#include "main.h" -#include "menu.h" -#include "tap_menu.h" -#include <epan/packet.h> -#include <epan/resolv.h> -#include "prefs.h" -#include "about_dlg.h" -#include "capture_dlg.h" -#include "color_dlg.h" -#include "filter_prefs.h" -#include "dlg_utils.h" -#include "file_dlg.h" -#include "find_dlg.h" -#include "goto_dlg.h" -#include "summary_dlg.h" -#include "prefs_dlg.h" -#include "packet_win.h" -#include "print.h" -#include "follow_dlg.h" -#include "decode_as_dlg.h" -#include "help_dlg.h" -#include "supported_protos_dlg.h" -#include "proto_dlg.h" -#include "proto_hier_stats_dlg.h" -#include "keys.h" -#include <epan/plugins.h> -#include <epan/epan_dissect.h> -#include "compat_macros.h" -#include "toolbar.h" -#include "gtkglobals.h" -#include "register.h" -#include "../tap.h" -#include "../menu.h" -#include "../ipproto.h" -#include "packet_list.h" -#include "ethclist.h" -#include "recent.h" -#include "../ui_util.h" -#include "proto_draw.h" -#include "endpoint_talkers_table.h" -#include "hostlist_table.h" -#include "simple_dialog.h" -#include <epan/timestamp.h> - -GtkWidget *popup_menu_object; - -static void -clear_menu_recent_capture_file_cmd_cb(GtkWidget *w, gpointer unused _U_); - -typedef struct _menu_item { - char *name; - gint group; - gboolean enabled; - GtkItemFactoryCallback callback; - gpointer callback_data; - gboolean (*selected_packet_enabled)(frame_data *, epan_dissect_t *); - gboolean (*selected_tree_row_enabled)(field_info *); - GList *children; -} menu_item_t; - -static GList *tap_menu_tree_root = NULL; - -static void -merge_all_tap_menus(GList *node); - -#define GTK_MENU_FUNC(a) ((GtkItemFactoryCallback)(a)) - -static void menus_init(void); -static void set_menu_sensitivity (GtkItemFactory *, const gchar *, gint); -static void main_toolbar_show_cb(GtkWidget *w _U_, gpointer d _U_); -static void filter_toolbar_show_cb(GtkWidget *w _U_, gpointer d _U_); -static void packet_list_show_cb(GtkWidget *w _U_, gpointer d _U_); -static void tree_view_show_cb(GtkWidget *w _U_, gpointer d _U_); -static void byte_view_show_cb(GtkWidget *w _U_, gpointer d _U_); -static void statusbar_show_cb(GtkWidget *w _U_, gpointer d _U_); -static void timestamp_absolute_cb(GtkWidget *w _U_, gpointer d _U_); -static void timestamp_absolute_date_cb(GtkWidget *w _U_, gpointer d _U_); -static void timestamp_relative_cb(GtkWidget *w _U_, gpointer d _U_); -static void timestamp_delta_cb(GtkWidget *w _U_, gpointer d _U_); -static void name_resolution_mac_cb(GtkWidget *w _U_, gpointer d _U_); -static void name_resolution_network_cb(GtkWidget *w _U_, gpointer d _U_); -static void name_resolution_transport_cb(GtkWidget *w _U_, gpointer d _U_); -#ifdef HAVE_LIBPCAP -static void auto_scroll_live_cb(GtkWidget *w _U_, gpointer d _U_); -#endif - -/* This is the GtkItemFactoryEntry structure used to generate new menus. - Item 1: The menu path. The letter after the underscore indicates an - accelerator key once the menu is open. - Item 2: The accelerator key for the entry - Item 3: The callback function. - Item 4: The callback action. This changes the parameters with - which the function is called. The default is 0. - Item 5: The item type, used to define what kind of an item it is. - Here are the possible values: - - NULL -> "<Item>" - "" -> "<Item>" - "<Title>" -> create a title item - "<Item>" -> create a simple item - "<ImageItem>" -> create an item holding an image (gtk2) - "<StockItem>" -> create an item holding a stock image (gtk2) - "<CheckItem>" -> create a check item - "<ToggleItem>" -> create a toggle item - "<RadioItem>" -> create a radio item - <path> -> path of a radio item to link against - "<Separator>" -> create a separator - "<Tearoff>" -> create a tearoff separator (gtk2) - "<Branch>" -> create an item to hold sub items (optional) - "<LastBranch>" -> create a right justified branch - Item 6: extra data needed for ImageItem and StockItem (gtk2) - */ - -/* main menu */ -static GtkItemFactoryEntry menu_items[] = -{ - ITEM_FACTORY_ENTRY("/_File", NULL, NULL, 0, "<Branch>", NULL), - ITEM_FACTORY_STOCK_ENTRY("/File/_Open...", "<control>O", file_open_cmd_cb, - 0, GTK_STOCK_OPEN), - ITEM_FACTORY_ENTRY("/File/Open _Recent", NULL, NULL, 0, "<Branch>", NULL), - ITEM_FACTORY_ENTRY("/File/_Merge...", NULL, file_merge_cmd_cb, 0, NULL, NULL), - ITEM_FACTORY_STOCK_ENTRY("/File/_Close", "<control>W", file_close_cmd_cb, - 0, GTK_STOCK_CLOSE), - ITEM_FACTORY_ENTRY("/File/<separator>", NULL, NULL, 0, "<Separator>", NULL), - ITEM_FACTORY_STOCK_ENTRY("/File/_Save", "<control>S", file_save_cmd_cb, - 0, GTK_STOCK_SAVE), - ITEM_FACTORY_STOCK_ENTRY("/File/Save _As...", "<shift><control>S", file_save_as_cmd_cb, - 0, GTK_STOCK_SAVE_AS), - ITEM_FACTORY_ENTRY("/File/<separator>", NULL, NULL, 0, "<Separator>", NULL), - ITEM_FACTORY_ENTRY("/File/_Export", NULL, NULL, 0, "<Branch>", NULL), - ITEM_FACTORY_ENTRY("/File/Export/as \"Plain _Text\" file...", NULL, export_text_cmd_cb, - 0, NULL, NULL), - ITEM_FACTORY_ENTRY("/File/Export/as \"_PostScript\" file...", NULL, export_ps_cmd_cb, - 0, NULL, NULL), - ITEM_FACTORY_ENTRY("/File/Export/as XML - \"P_SML\" (packet summary) file...", NULL, export_psml_cmd_cb, - 0, NULL, NULL), - ITEM_FACTORY_ENTRY("/File/Export/as XML - \"P_DML\" (packet details) file...", NULL, export_pdml_cmd_cb, - 0, NULL, NULL), - ITEM_FACTORY_ENTRY("/File/Export/<separator>", NULL, NULL, 0, "<Separator>", NULL), - ITEM_FACTORY_ENTRY("/File/Export/Selected Packet _Bytes...", "<control>H", savehex_cb, - 0, NULL, NULL), - ITEM_FACTORY_ENTRY("/File/<separator>", NULL, NULL, 0, "<Separator>", NULL), - ITEM_FACTORY_STOCK_ENTRY("/File/_Print...", "<control>P", file_print_cmd_cb, - 0, GTK_STOCK_PRINT), - ITEM_FACTORY_ENTRY("/File/<separator>", NULL, NULL, 0, "<Separator>", NULL), - ITEM_FACTORY_STOCK_ENTRY("/File/_Quit", "<control>Q", file_quit_cmd_cb, - 0, GTK_STOCK_QUIT), - ITEM_FACTORY_ENTRY("/_Edit", NULL, NULL, 0, "<Branch>", NULL), -#if 0 - /* Un-#if this when we actually implement Cut/Copy/Paste. */ - ITEM_FACTORY_STOCK_ENTRY("/Edit/Cut", "<control>X", NULL, - 0, GTK_STOCK_CUT), - ITEM_FACTORY_STOCK_ENTRY("/Edit/Copy", "<control>C", NULL, - 0, GTK_STOCK_COPY), - ITEM_FACTORY_STOCK_ENTRY("/Edit/Paste", "<control>V", NULL, - 0, GTK_STOCK_PASTE), - ITEM_FACTORY_ENTRY("/Edit/<separator>", NULL, NULL, 0, "<Separator>"), -#endif - ITEM_FACTORY_STOCK_ENTRY("/Edit/_Find Packet...", "<control>F", - find_frame_cb, 0, GTK_STOCK_FIND), - ITEM_FACTORY_STOCK_ENTRY("/Edit/Find Ne_xt", "<control>N", find_next_cb, - 0, GTK_STOCK_GO_FORWARD), - ITEM_FACTORY_STOCK_ENTRY("/Edit/Find Pre_vious", "<control>B", - find_previous_cb, 0, GTK_STOCK_GO_BACK), - ITEM_FACTORY_ENTRY("/Edit/<separator>", NULL, NULL, 0, "<Separator>", NULL), - ITEM_FACTORY_ENTRY("/Edit/_Time Reference", NULL, NULL, 0, "<Branch>", NULL), - ITEM_FACTORY_ENTRY("/Edit/Time Reference/Set Time Reference (toggle)", "<control>T", reftime_frame_cb, REFTIME_TOGGLE, NULL, NULL), - ITEM_FACTORY_ENTRY("/Edit/Time Reference/Find Next", NULL, reftime_frame_cb, REFTIME_FIND_NEXT, NULL, NULL), - ITEM_FACTORY_ENTRY("/Edit/Time Reference/Find Previous", NULL, reftime_frame_cb, REFTIME_FIND_PREV, NULL, NULL), - ITEM_FACTORY_ENTRY("/Edit/_Mark Packet", "<control>M", mark_frame_cb, - 0, NULL, NULL), - ITEM_FACTORY_ENTRY("/Edit/Mark _All Packets", NULL, mark_all_frames_cb, - 0, NULL, NULL), - ITEM_FACTORY_ENTRY("/Edit/_Unmark All Packets", NULL, unmark_all_frames_cb, - 0, NULL, NULL), - ITEM_FACTORY_ENTRY("/Edit/<separator>", NULL, NULL, 0, "<Separator>", NULL), - ITEM_FACTORY_STOCK_ENTRY("/Edit/_Preferences...", "<shift><control>P", prefs_cb, - 0, GTK_STOCK_PREFERENCES), - ITEM_FACTORY_ENTRY("/_View", NULL, NULL, 0, "<Branch>", NULL), - ITEM_FACTORY_ENTRY("/View/_Main Toolbar", NULL, main_toolbar_show_cb, 0, "<CheckItem>", NULL), - ITEM_FACTORY_ENTRY("/View/_Filter Toolbar", NULL, filter_toolbar_show_cb, 0, "<CheckItem>", NULL), - ITEM_FACTORY_ENTRY("/View/_Statusbar", NULL, statusbar_show_cb, 0, "<CheckItem>", NULL), - ITEM_FACTORY_ENTRY("/View/<separator>", NULL, NULL, 0, "<Separator>", NULL), - ITEM_FACTORY_ENTRY("/View/Packet _List", NULL, packet_list_show_cb, 0, "<CheckItem>", NULL), - ITEM_FACTORY_ENTRY("/View/Packet _Details", NULL, tree_view_show_cb, 0, "<CheckItem>", NULL), - ITEM_FACTORY_ENTRY("/View/Packet _Bytes", NULL, byte_view_show_cb, 0, "<CheckItem>", NULL), - ITEM_FACTORY_ENTRY("/View/<separator>", NULL, NULL, 0, "<Separator>", NULL), - ITEM_FACTORY_ENTRY("/View/_Time Display Format", NULL, NULL, 0, "<Branch>", NULL), - ITEM_FACTORY_ENTRY("/View/Time Display Format/Time of Day", NULL, timestamp_absolute_cb, - 0, "<RadioItem>", NULL), - ITEM_FACTORY_ENTRY("/View/Time Display Format/Date and Time of Day", NULL, timestamp_absolute_date_cb, - 0, "/View/Time Display Format/Time of Day", NULL), - ITEM_FACTORY_ENTRY("/View/Time Display Format/Seconds Since Beginning of Capture", NULL, timestamp_relative_cb, - 0, "/View/Time Display Format/Time of Day", NULL), - ITEM_FACTORY_ENTRY("/View/Time Display Format/Seconds Since Previous Packet", NULL, timestamp_delta_cb, - 0, "/View/Time Display Format/Time of Day", NULL), - ITEM_FACTORY_ENTRY("/View/Name Resol_ution", NULL, NULL, 0, "<Branch>", NULL), - ITEM_FACTORY_ENTRY("/View/Name Resolution/_Resolve Name", NULL, resolve_name_cb, 0, NULL, NULL), - ITEM_FACTORY_ENTRY("/View/Name Resolution/<separator>", NULL, NULL, 0, "<Separator>", NULL), - ITEM_FACTORY_ENTRY("/View/Name Resolution/Enable for _MAC Layer", NULL, name_resolution_mac_cb, 0, "<CheckItem>", NULL), - ITEM_FACTORY_ENTRY("/View/Name Resolution/Enable for _Network Layer", NULL, name_resolution_network_cb, 0, "<CheckItem>", NULL), - ITEM_FACTORY_ENTRY("/View/Name Resolution/Enable for _Transport Layer", NULL, name_resolution_transport_cb, 0, "<CheckItem>", NULL), -#ifdef HAVE_LIBPCAP - ITEM_FACTORY_ENTRY("/View/Auto Scroll in Li_ve Capture", NULL, auto_scroll_live_cb, 0, "<CheckItem>", NULL), -#endif - ITEM_FACTORY_ENTRY("/View/<separator>", NULL, NULL, 0, "<Separator>", NULL), - ITEM_FACTORY_STOCK_ENTRY("/View/_Zoom In", "<control>plus", view_zoom_in_cb, - 0, GTK_STOCK_ZOOM_IN), - ITEM_FACTORY_STOCK_ENTRY("/View/Zoom _Out", "<control>minus", view_zoom_out_cb, - 0, GTK_STOCK_ZOOM_OUT), - ITEM_FACTORY_STOCK_ENTRY("/View/_Normal Size", "<control>equal", view_zoom_100_cb, - 0, GTK_STOCK_ZOOM_100), - ITEM_FACTORY_ENTRY("/View/<separator>", NULL, NULL, 0, "<Separator>", NULL), - ITEM_FACTORY_ENTRY("/View/Collapse _All", NULL, collapse_all_cb, - 0, NULL, NULL), - ITEM_FACTORY_ENTRY("/View/_Expand All", NULL, expand_all_cb, - 0, NULL, NULL), - ITEM_FACTORY_ENTRY("/View/Expand Tree", NULL, expand_tree_cb, 0, NULL, NULL), - ITEM_FACTORY_ENTRY("/View/<separator>", NULL, NULL, 0, "<Separator>", NULL), - ITEM_FACTORY_STOCK_ENTRY("/View/_Coloring Rules...", NULL, color_display_cb, - 0, GTK_STOCK_SELECT_COLOR), - ITEM_FACTORY_ENTRY("/View/<separator>", NULL, NULL, 0, "<Separator>", NULL), - ITEM_FACTORY_ENTRY("/View/Show Packet in New _Window", NULL, - new_window_cb, 0, NULL, NULL), - ITEM_FACTORY_STOCK_ENTRY("/View/_Reload", "<control>R", file_reload_cmd_cb, - 0, GTK_STOCK_REFRESH), - ITEM_FACTORY_ENTRY("/_Go", NULL, NULL, 0, "<Branch>", NULL), - ITEM_FACTORY_STOCK_ENTRY("/Go/_Go to Packet...", "<control>G", - goto_frame_cb, 0, GTK_STOCK_JUMP_TO), - ITEM_FACTORY_ENTRY("/Go/Go to _Corresponding Packet", NULL, goto_framenum_cb, - 0, NULL, NULL), - ITEM_FACTORY_ENTRY("/Go/<separator>", NULL, NULL, 0, "<Separator>", NULL), - ITEM_FACTORY_STOCK_ENTRY("/Go/_First Packet", NULL, - goto_top_frame_cb, 0, GTK_STOCK_GOTO_TOP), - ITEM_FACTORY_STOCK_ENTRY("/Go/_Last Packet", NULL, - goto_bottom_frame_cb, 0, GTK_STOCK_GOTO_BOTTOM), -#ifdef HAVE_LIBPCAP - ITEM_FACTORY_ENTRY("/_Capture", NULL, NULL, 0, "<Branch>", NULL), - ITEM_FACTORY_STOCK_ENTRY("/Capture/_Start...", "<control>K", - capture_prep_cb, 0, ETHEREAL_STOCK_CAPTURE_START), - ITEM_FACTORY_STOCK_ENTRY("/Capture/S_top", "<control>E", capture_stop_cb, - 0, GTK_STOCK_STOP), - ITEM_FACTORY_STOCK_ENTRY("/Capture/_Capture Filters...", NULL, cfilter_dialog_cb, - 0, ETHEREAL_STOCK_CAPTURE_FILTER), -#endif /* HAVE_LIBPCAP */ - ITEM_FACTORY_ENTRY("/_Analyze", NULL, NULL, 0, "<Branch>", NULL), - ITEM_FACTORY_STOCK_ENTRY("/Analyze/_Display Filters...", NULL, dfilter_dialog_cb, - 0, ETHEREAL_STOCK_DISPLAY_FILTER), - ITEM_FACTORY_ENTRY("/Analyze/Appl_y as Filter", NULL, NULL, 0, "<Branch>", NULL), - ITEM_FACTORY_ENTRY("/Analyze/Apply as Filter/_Selected", NULL, match_selected_ptree_cb, - MATCH_SELECTED_REPLACE|MATCH_SELECTED_APPLY_NOW, NULL, NULL), - ITEM_FACTORY_ENTRY("/Analyze/Apply as Filter/_Not Selected", NULL, match_selected_ptree_cb, - MATCH_SELECTED_NOT|MATCH_SELECTED_APPLY_NOW, NULL, NULL), - ITEM_FACTORY_ENTRY("/Analyze/Apply as Filter/... _and Selected", NULL, match_selected_ptree_cb, - MATCH_SELECTED_AND|MATCH_SELECTED_APPLY_NOW, NULL, NULL), - ITEM_FACTORY_ENTRY("/Analyze/Apply as Filter/... _or Selected", NULL, match_selected_ptree_cb, - MATCH_SELECTED_OR|MATCH_SELECTED_APPLY_NOW, NULL, NULL), - ITEM_FACTORY_ENTRY("/Analyze/Apply as Filter/... a_nd not Selected", NULL, match_selected_ptree_cb, - MATCH_SELECTED_AND_NOT|MATCH_SELECTED_APPLY_NOW, NULL, NULL), - ITEM_FACTORY_ENTRY("/Analyze/Apply as Filter/... o_r not Selected", NULL, match_selected_ptree_cb, - MATCH_SELECTED_OR_NOT|MATCH_SELECTED_APPLY_NOW, NULL, NULL), - ITEM_FACTORY_ENTRY("/Analyze/_Prepare a Filter", NULL, NULL, 0, "<Branch>", NULL), - ITEM_FACTORY_ENTRY("/Analyze/Prepare a Filter/_Selected", NULL, match_selected_ptree_cb, - MATCH_SELECTED_REPLACE, NULL, NULL), - ITEM_FACTORY_ENTRY("/Analyze/Prepare a Filter/_Not Selected", NULL, match_selected_ptree_cb, - MATCH_SELECTED_NOT, NULL, NULL), - ITEM_FACTORY_ENTRY("/Analyze/Prepare a Filter/... _and Selected", NULL, match_selected_ptree_cb, - MATCH_SELECTED_AND, NULL, NULL), - ITEM_FACTORY_ENTRY("/Analyze/Prepare a Filter/... _or Selected", NULL, match_selected_ptree_cb, - MATCH_SELECTED_OR, NULL, NULL), - ITEM_FACTORY_ENTRY("/Analyze/Prepare a Filter/... a_nd not Selected", NULL, match_selected_ptree_cb, - MATCH_SELECTED_AND_NOT, NULL, NULL), - ITEM_FACTORY_ENTRY("/Analyze/Prepare a Filter/... o_r not Selected", NULL, match_selected_ptree_cb, - MATCH_SELECTED_OR_NOT, NULL, NULL), - ITEM_FACTORY_ENTRY("/Analyze/<separator>", NULL, NULL, 0, "<Separator>", NULL), - ITEM_FACTORY_ENTRY("/Analyze/_Enabled Protocols...", "<shift><control>R", proto_cb, 0, NULL, NULL), - ITEM_FACTORY_ENTRY("/Analyze/Decode _As...", NULL, decode_as_cb, - 0, NULL, NULL), - ITEM_FACTORY_ENTRY("/Analyze/_User Specified Decodes...", NULL, - decode_show_cb, 0, NULL, NULL), - ITEM_FACTORY_ENTRY("/Analyze/<separator>", NULL, NULL, 0, "<Separator>", NULL), - ITEM_FACTORY_ENTRY("/Analyze/_Follow TCP Stream", NULL, - follow_stream_cb, 0, NULL, NULL), - ITEM_FACTORY_ENTRY("/_Statistics", NULL, NULL, 0, "<Branch>", NULL), - ITEM_FACTORY_ENTRY("/Statistics/_Summary", NULL, summary_open_cb, 0, NULL, NULL), - ITEM_FACTORY_ENTRY("/Statistics/_Protocol Hierarchy", NULL, - proto_hier_stats_cb, 0, NULL, NULL), - ITEM_FACTORY_ENTRY("/Statistics/Conversations", NULL, - init_ett_notebook_cb, 0, NULL, NULL), - ITEM_FACTORY_ENTRY("/Statistics/Endpoints", NULL, - init_hostlist_notebook_cb, 0, NULL, NULL), - ITEM_FACTORY_ENTRY("/_Help", NULL, NULL, 0, "<Branch>", NULL), - ITEM_FACTORY_STOCK_ENTRY("/Help/_Contents", "F1", help_cb, 0, GTK_STOCK_HELP), - ITEM_FACTORY_ENTRY("/Help/_Supported Protocols", NULL, supported_cb, 0, NULL, NULL), -#if (GLIB_MAJOR_VERSION >= 2) - /* currently, glib1.x can't start a webbrowser, see webbrowser.c for details */ - ITEM_FACTORY_ENTRY("/Help/Manual Pages", NULL, NULL, 0, "<Branch>", NULL), - ITEM_FACTORY_ENTRY("/Help/Manual Pages/Ethereal", NULL, url_localpage_cb, LOCALPAGE_MAN_ETHEREAL, NULL, NULL), - ITEM_FACTORY_ENTRY("/Help/Manual Pages/Ethereal Filter", NULL, url_localpage_cb, LOCALPAGE_MAN_ETHEREAL_FILTER, NULL, NULL), - ITEM_FACTORY_ENTRY("/Help/Manual Pages/<separator>", NULL, NULL, 0, "<Separator>", NULL), - ITEM_FACTORY_ENTRY("/Help/Manual Pages/Tethereal", NULL, url_localpage_cb, LOCALPAGE_MAN_TETHEREAL, NULL, NULL), - ITEM_FACTORY_ENTRY("/Help/Manual Pages/Mergecap", NULL, url_localpage_cb, LOCALPAGE_MAN_MERGECAP, NULL, NULL), - ITEM_FACTORY_ENTRY("/Help/Manual Pages/Editcap", NULL, url_localpage_cb, LOCALPAGE_MAN_EDITCAP, NULL, NULL), - ITEM_FACTORY_ENTRY("/Help/Manual Pages/Text2pcap", NULL, url_localpage_cb, LOCALPAGE_MAN_TEXT2PCAP, NULL, NULL), - ITEM_FACTORY_ENTRY("/Help/Ethereal Online", NULL, NULL, 0, "<Branch>", NULL), - ITEM_FACTORY_STOCK_ENTRY("/Help/Ethereal Online/Home Page", NULL, url_onlinepage_cb, ONLINEPAGE_HOME, GTK_STOCK_HOME), - ITEM_FACTORY_ENTRY("/Help/Ethereal Online/User's Guide", NULL, url_onlinepage_cb, ONLINEPAGE_USERGUIDE, NULL, NULL), - ITEM_FACTORY_ENTRY("/Help/Ethereal Online/FAQ's", NULL, url_onlinepage_cb, ONLINEPAGE_FAQ, NULL, NULL), - ITEM_FACTORY_ENTRY("/Help/Ethereal Online/Downloads", NULL, url_onlinepage_cb, ONLINEPAGE_DOWNLOAD, NULL, NULL), - ITEM_FACTORY_ENTRY("/Help/Ethereal Online/Example Files", NULL, url_onlinepage_cb, ONLINEPAGE_SAMPLE, NULL, NULL), -#endif - ITEM_FACTORY_ENTRY("/Help/<separator>", NULL, NULL, 0, "<Separator>", NULL), - ITEM_FACTORY_ENTRY("/Help/_About Ethereal", NULL, about_ethereal_cb, - 0, NULL, NULL) -}; - - -/* calculate the number of menu_items */ -static int nmenu_items = sizeof(menu_items) / sizeof(menu_items[0]); - -/* packet list popup */ -static GtkItemFactoryEntry packet_list_menu_items[] = -{ - ITEM_FACTORY_ENTRY("/Follow TCP Stream", NULL, follow_stream_cb, - 0, NULL, NULL), - ITEM_FACTORY_ENTRY("/Decode As...", NULL, decode_as_cb, 0, NULL, NULL), - ITEM_FACTORY_ENTRY("/Display Filters...", NULL, dfilter_dialog_cb, - 0, NULL, NULL), - ITEM_FACTORY_ENTRY("/<separator>", NULL, NULL, 0, "<Separator>", NULL), - ITEM_FACTORY_ENTRY("/Mark Packet", NULL, mark_frame_cb, 0, NULL, NULL), - ITEM_FACTORY_ENTRY("/Time Reference", NULL, NULL, 0, "<Branch>", NULL), - ITEM_FACTORY_ENTRY("/Time Reference/Set Time Reference (toggle)", NULL, reftime_frame_cb, REFTIME_TOGGLE, NULL, NULL), - ITEM_FACTORY_ENTRY("/Time Reference/Find Next", NULL, reftime_frame_cb, REFTIME_FIND_NEXT, NULL, NULL), - ITEM_FACTORY_ENTRY("/Time Reference/Find Previous", NULL, reftime_frame_cb, REFTIME_FIND_PREV, NULL, NULL), - ITEM_FACTORY_ENTRY("/Apply as Filter", NULL, NULL, 0, "<Branch>", NULL), - ITEM_FACTORY_ENTRY("/Apply as Filter/_Selected", NULL, match_selected_plist_cb, - MATCH_SELECTED_REPLACE|MATCH_SELECTED_APPLY_NOW, NULL, NULL), - ITEM_FACTORY_ENTRY("/Apply as Filter/_Not Selected", NULL, match_selected_plist_cb, - MATCH_SELECTED_NOT|MATCH_SELECTED_APPLY_NOW, NULL, NULL), - ITEM_FACTORY_ENTRY("/Apply as Filter/... _and Selected", NULL, match_selected_plist_cb, - MATCH_SELECTED_AND|MATCH_SELECTED_APPLY_NOW, NULL, NULL), - ITEM_FACTORY_ENTRY("/Apply as Filter/... _or Selected", NULL, match_selected_plist_cb, - MATCH_SELECTED_OR|MATCH_SELECTED_APPLY_NOW, NULL, NULL), - ITEM_FACTORY_ENTRY("/Apply as Filter/... a_nd not Selected", NULL, match_selected_plist_cb, - MATCH_SELECTED_AND_NOT|MATCH_SELECTED_APPLY_NOW, NULL, NULL), - ITEM_FACTORY_ENTRY("/Apply as Filter/... o_r not Selected", NULL, match_selected_plist_cb, - MATCH_SELECTED_OR_NOT|MATCH_SELECTED_APPLY_NOW, NULL, NULL), - - ITEM_FACTORY_ENTRY("/Prepare a Filter", NULL, NULL, 0, "<Branch>", NULL), - ITEM_FACTORY_ENTRY("/Prepare a Filter/_Selected", NULL, match_selected_plist_cb, - MATCH_SELECTED_REPLACE, NULL, NULL), - ITEM_FACTORY_ENTRY("/Prepare a Filter/_Not Selected", NULL, match_selected_plist_cb, - MATCH_SELECTED_NOT, NULL, NULL), - ITEM_FACTORY_ENTRY("/Prepare a Filter/... _and Selected", NULL, match_selected_plist_cb, - MATCH_SELECTED_AND, NULL, NULL), - ITEM_FACTORY_ENTRY("/Prepare a Filter/... _or Selected", NULL, match_selected_plist_cb, - MATCH_SELECTED_OR, NULL, NULL), - ITEM_FACTORY_ENTRY("/Prepare a Filter/... a_nd not Selected", NULL, match_selected_plist_cb, - MATCH_SELECTED_AND_NOT, NULL, NULL), - ITEM_FACTORY_ENTRY("/Prepare a Filter/... o_r not Selected", NULL, match_selected_plist_cb, - MATCH_SELECTED_OR_NOT, NULL, NULL), - - ITEM_FACTORY_ENTRY("/<separator>", NULL, NULL, 0, "<Separator>", NULL), - ITEM_FACTORY_ENTRY("/Coloring Rules...", NULL, color_display_cb, - 0, NULL, NULL), - ITEM_FACTORY_ENTRY("/Print...", NULL, file_print_cmd_cb, 0, NULL, NULL), - ITEM_FACTORY_ENTRY("/Show Packet in New Window", NULL, new_window_cb, - 0, NULL, NULL), -}; - -static GtkItemFactoryEntry tree_view_menu_items[] = -{ - ITEM_FACTORY_ENTRY("/Follow TCP Stream", NULL, follow_stream_cb, - 0, NULL, NULL), - ITEM_FACTORY_ENTRY("/Decode As...", NULL, decode_as_cb, 0, NULL, NULL), - ITEM_FACTORY_ENTRY("/Display Filters...", NULL, dfilter_dialog_cb, - 0, NULL, NULL), - ITEM_FACTORY_ENTRY("/<separator>", NULL, NULL, 0, "<Separator>", NULL), - ITEM_FACTORY_ENTRY("/_Resolve Name", NULL, resolve_name_cb, 0, NULL, NULL), - ITEM_FACTORY_ENTRY("/_Go to Corresponding Packet", NULL, goto_framenum_cb, 0, NULL, NULL), - ITEM_FACTORY_ENTRY("/_Export Selected Packet Bytes...", NULL, savehex_cb, - 0, NULL, NULL), - ITEM_FACTORY_ENTRY("/Protocol Preferences...", NULL, properties_cb, - 0, NULL, NULL), - ITEM_FACTORY_ENTRY("/Apply as Filter", NULL, NULL, 0, "<Branch>", NULL), - ITEM_FACTORY_ENTRY("/Apply as Filter/_Selected", NULL, match_selected_ptree_cb, - MATCH_SELECTED_REPLACE|MATCH_SELECTED_APPLY_NOW, NULL, NULL), - ITEM_FACTORY_ENTRY("/Apply as Filter/_Not Selected", NULL, match_selected_ptree_cb, - MATCH_SELECTED_NOT|MATCH_SELECTED_APPLY_NOW, NULL, NULL), - ITEM_FACTORY_ENTRY("/Apply as Filter/... _and Selected", NULL, match_selected_ptree_cb, - MATCH_SELECTED_AND|MATCH_SELECTED_APPLY_NOW, NULL, NULL), - ITEM_FACTORY_ENTRY("/Apply as Filter/... _or Selected", NULL, match_selected_ptree_cb, - MATCH_SELECTED_OR|MATCH_SELECTED_APPLY_NOW, NULL, NULL), - ITEM_FACTORY_ENTRY("/Apply as Filter/... a_nd not Selected", NULL, match_selected_ptree_cb, - MATCH_SELECTED_AND_NOT|MATCH_SELECTED_APPLY_NOW, NULL, NULL), - ITEM_FACTORY_ENTRY("/Apply as Filter/... o_r not Selected", NULL, match_selected_ptree_cb, - MATCH_SELECTED_OR_NOT|MATCH_SELECTED_APPLY_NOW, NULL, NULL), - - ITEM_FACTORY_ENTRY("/Prepare a Filter", NULL, NULL, 0, "<Branch>", NULL), - ITEM_FACTORY_ENTRY("/Prepare a Filter/_Selected", NULL, match_selected_ptree_cb, - MATCH_SELECTED_REPLACE, NULL, NULL), - ITEM_FACTORY_ENTRY("/Prepare a Filter/_Not Selected", NULL, match_selected_ptree_cb, - MATCH_SELECTED_NOT, NULL, NULL), - ITEM_FACTORY_ENTRY("/Prepare a Filter/... _and Selected", NULL, match_selected_ptree_cb, - MATCH_SELECTED_AND, NULL, NULL), - ITEM_FACTORY_ENTRY("/Prepare a Filter/... _or Selected", NULL, match_selected_ptree_cb, - MATCH_SELECTED_OR, NULL, NULL), - ITEM_FACTORY_ENTRY("/Prepare a Filter/... a_nd not Selected", NULL, match_selected_ptree_cb, - MATCH_SELECTED_AND_NOT, NULL, NULL), - ITEM_FACTORY_ENTRY("/Prepare a Filter/... o_r not Selected", NULL, match_selected_ptree_cb, - MATCH_SELECTED_OR_NOT, NULL, NULL), - ITEM_FACTORY_ENTRY("/<separator>", NULL, NULL, 0, "<Separator>", NULL), - ITEM_FACTORY_ENTRY("/Collapse All", NULL, collapse_all_cb, 0, NULL, NULL), - ITEM_FACTORY_ENTRY("/Expand All", NULL, expand_all_cb, 0, NULL, NULL), - ITEM_FACTORY_ENTRY("/Expand Tree", NULL, expand_tree_cb, 0, NULL, NULL) -}; - -static GtkItemFactoryEntry hexdump_menu_items[] = -{ - ITEM_FACTORY_ENTRY("/Follow TCP Stream", NULL, follow_stream_cb, - 0, NULL, NULL), - ITEM_FACTORY_ENTRY("/Decode As...", NULL, decode_as_cb, 0, NULL, NULL), - ITEM_FACTORY_ENTRY("/Display Filters...", NULL, dfilter_dialog_cb, - 0, NULL, NULL), - ITEM_FACTORY_ENTRY("/Export Selected Packet Bytes...", NULL, savehex_cb, - 0, NULL, NULL) -}; - -static int initialize = TRUE; -static GtkItemFactory *main_menu_factory = NULL; -static GtkItemFactory *packet_list_menu_factory = NULL; -static GtkItemFactory *tree_view_menu_factory = NULL; -static GtkItemFactory *hexdump_menu_factory = NULL; - -static GSList *popup_menu_list = NULL; - -static GtkAccelGroup *grp; - -GtkWidget * -main_menu_new(GtkAccelGroup ** table) { - GtkWidget *menubar; - - grp = gtk_accel_group_new(); - - if (initialize) - menus_init(); - - menubar = main_menu_factory->widget; - - if (table) - *table = grp; - - return menubar; -} - -static void -menus_init(void) { - if (initialize) { - initialize = FALSE; - - /* popup */ - packet_list_menu_factory = gtk_item_factory_new(GTK_TYPE_MENU, "<main>", NULL); - popup_menu_object = gtk_menu_new(); - gtk_item_factory_create_items_ac(packet_list_menu_factory, sizeof(packet_list_menu_items)/sizeof(packet_list_menu_items[0]), packet_list_menu_items, popup_menu_object, 2); - OBJECT_SET_DATA(popup_menu_object, PM_PACKET_LIST_KEY, - packet_list_menu_factory->widget); - popup_menu_list = g_slist_append((GSList *)popup_menu_list, packet_list_menu_factory); - - tree_view_menu_factory = gtk_item_factory_new(GTK_TYPE_MENU, "<main>", NULL); - gtk_item_factory_create_items_ac(tree_view_menu_factory, sizeof(tree_view_menu_items)/sizeof(tree_view_menu_items[0]), tree_view_menu_items, popup_menu_object, 2); - OBJECT_SET_DATA(popup_menu_object, PM_TREE_VIEW_KEY, - tree_view_menu_factory->widget); - popup_menu_list = g_slist_append((GSList *)popup_menu_list, tree_view_menu_factory); - - hexdump_menu_factory = gtk_item_factory_new(GTK_TYPE_MENU, "<main>", NULL); - gtk_item_factory_create_items_ac(hexdump_menu_factory, sizeof(hexdump_menu_items)/sizeof(hexdump_menu_items[0]), hexdump_menu_items, popup_menu_object, 2); - OBJECT_SET_DATA(popup_menu_object, PM_HEXDUMP_KEY, - hexdump_menu_factory->widget); - popup_menu_list = g_slist_append((GSList *)popup_menu_list, hexdump_menu_factory); - - /* main */ - main_menu_factory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<main>", grp); - gtk_item_factory_create_items_ac(main_menu_factory, nmenu_items, menu_items, NULL, 2); - - merge_all_tap_menus(tap_menu_tree_root); - - /* Initialize enabled/disabled state of menu items */ - set_menus_for_unsaved_capture_file(FALSE); - set_menus_for_capture_file(FALSE); -#if 0 - /* Un-#if this when we actually implement Cut/Copy/Paste. - Then make sure you enable them when they can be done. */ - set_menu_sensitivity(main_menu_factory, "/Edit/Cut", FALSE); - set_menu_sensitivity(main_menu_factory, "/Edit/Copy", FALSE); - set_menu_sensitivity(main_menu_factory, "/Edit/Paste", FALSE); -#endif - - set_menus_for_captured_packets(FALSE); - set_menus_for_selected_packet(&cfile); - set_menus_for_selected_tree_row(&cfile); - - /* init with an empty recent files list */ - clear_menu_recent_capture_file_cmd_cb(NULL, NULL); - } -} - - -gint tap_menu_item_add_compare(gconstpointer a, gconstpointer b) -{ - return strcmp( - ((const menu_item_t *) a)->name, - ((const menu_item_t *) b)->name); -} - - -/* add a menuitem below the current node */ -GList * tap_menu_item_add( - char *name, - gint group, - GtkItemFactoryCallback callback, - gboolean (*selected_packet_enabled)(frame_data *, epan_dissect_t *), - gboolean (*selected_tree_row_enabled)(field_info *), - gpointer callback_data, - GList *curnode) -{ - menu_item_t *curr; - menu_item_t *child; - - - child = g_malloc(sizeof (menu_item_t)); - child->group = group; - child->name = name; - child->callback = callback; - child->selected_packet_enabled = selected_packet_enabled; - child->selected_tree_row_enabled = selected_tree_row_enabled; - child->callback_data = callback_data; - child->enabled = FALSE; - child->children = NULL; - - /* insert the new child node into the parent */ - curr = curnode->data; - curr->children = g_list_insert_sorted(curr->children, child, tap_menu_item_add_compare); - - /* return the new node */ - /* XXX: improve this */ - return g_list_find(curr->children, child); -} - -/* - * Add a new menu item for a tap. - * This must be called after we've created the main menu, so it can't - * be called from the routine that registers taps - we have to introduce - * another per-tap registration routine. - * - * "callback" gets called when the menu item is selected; it should do - * the work of creating the tap window. - * - * "selected_packet_enabled" gets called by "set_menus_for_selected_packet()"; - * it's passed a Boolean that's TRUE if a packet is selected and FALSE - * otherwise, and should return TRUE if the tap will work now (which - * might depend on whether a packet is selected and, if one is, on the - * packet) and FALSE if not. - * - * "selected_tree_row_enabled" gets called by - * "set_menus_for_selected_tree_row()"; it's passed a Boolean that's TRUE if - * a protocol tree row is selected and FALSE otherwise, and should return - * TRUE if the tap will work now (which might depend on whether a tree row - * is selected and, if one is, on the tree row) and FALSE if not. - */ -void -register_tap_menu_item( - char *name, - REGISTER_TAP_GROUP_E group, - GtkItemFactoryCallback callback, - gboolean (*selected_packet_enabled)(frame_data *, epan_dissect_t *), - gboolean (*selected_tree_row_enabled)(field_info *), - gpointer callback_data) -{ - /*static const char toolspath[] = "/Statistics/";*/ - char *toolspath; - char *p; - char *menupath; - size_t menupathlen; - menu_item_t *child; - GList *curnode; - GList *childnode; - - /* - * The menu path must be relative. - */ - g_assert(*name != '/'); - - switch(group) { - case(REGISTER_TAP_GROUP_GENERIC): toolspath = "/Statistics/"; break; - case(REGISTER_TAP_GROUP_CONVERSATION_LIST): toolspath = "/Statistics/_Conversation List/"; break; - case(REGISTER_TAP_GROUP_ENDPOINT_LIST): toolspath = "/Statistics/_Endpoint List/"; break; - case(REGISTER_TAP_GROUP_RESPONSE_TIME): toolspath = "/Statistics/Service _Response Time/"; break; - case(REGISTER_TAP_GROUP_NONE): toolspath = "/Statistics/"; break; - default: - g_assert(0); - toolspath = NULL; - } - - /* add the (empty) root node, if not already done */ - if(tap_menu_tree_root == NULL) { - child = g_malloc0(sizeof (menu_item_t)); - tap_menu_tree_root = g_list_append(NULL, child); - } - - /* - * Create any submenus required. - */ - curnode = tap_menu_tree_root; - p = name; - while ((p = strchr(p, '/')) != NULL) { - /* - * OK, everything between "name" and "p" is - * a menu relative subtree into which the menu item - * will be placed. - * - * Construct the absolute path name of that subtree. - */ - menupathlen = strlen(toolspath) + 1 + (p - name); - menupath = g_malloc(menupathlen); - strcpy(menupath, toolspath); - strncat(menupath, name, p - name); - - /* - * Does there exist an entry with that path at this - * level of the Analyze menu tree? - */ - child = curnode->data; - for (childnode = child->children; childnode != NULL; childnode = childnode->next) { - child = childnode->data; - if (strcmp(child->name, menupath) == 0) - break; - } - if (childnode == NULL) { - /* - * No. Create such an item as a subtree, and - * add it to the Tools menu tree. - */ - childnode = tap_menu_item_add( - menupath, group, NULL, NULL ,NULL, NULL, curnode); - } else { - /* - * Yes. We don't need this "menupath" any longer. - */ - g_free(menupath); - } - curnode = childnode; - - /* - * Skip over the '/' we found. - */ - p++; - } - - /* - * Construct the main menu path for the menu item. - */ - menupathlen = strlen(toolspath) + 1 + strlen(name); - menupath = g_malloc(menupathlen); - strcpy(menupath, toolspath); - strcat(menupath, name); - - /* - * Construct an item factory entry for the item, and add it to - * the main menu. - */ - tap_menu_item_add( - menupath, group, callback, - selected_packet_enabled, selected_tree_row_enabled, - callback_data, curnode); -} - - -guint merge_tap_menus_layered(GList *node, gint group) { - GtkItemFactoryEntry *entry; - GList *child; - guint added = 0; - menu_item_t *node_data = node->data; - - /* - * Is this a leaf node or an interior node? - */ - if (node_data->children == NULL) { - /* - * It's a leaf node. - */ - - /* - * The root node doesn't correspond to a menu tree item; it - * has a null name pointer. - */ - if (node_data->name != NULL && group == node_data->group) { - entry = g_malloc0(sizeof (GtkItemFactoryEntry)); - entry->path = node_data->name; - entry->callback = node_data->callback; - gtk_item_factory_create_item(main_menu_factory, entry, node_data->callback_data, 2); - set_menu_sensitivity(main_menu_factory, node_data->name, FALSE); /* no capture file yet */ - added++; - } - } else { - /* - * It's an interior node; call - * "merge_tap_menus_layered()" on all its children - */ - - /* - * The root node doesn't correspond to a menu tree item; it - * has a null name pointer. - */ - if (node_data->name != NULL && group == node_data->group) { - entry = g_malloc0(sizeof (GtkItemFactoryEntry)); - entry->path = node_data->name; - entry->item_type = "<Branch>"; - gtk_item_factory_create_item(main_menu_factory, entry, - NULL, 2); - set_menu_sensitivity(main_menu_factory, node_data->name, - FALSE); /* no children yet */ - added++; - } - - for (child = node_data->children; child != NULL; child = - child->next) { - added += merge_tap_menus_layered(child, group); - } - } - - return added; -} - - -void merge_all_tap_menus(GList *node) { - GtkItemFactoryEntry *entry; - - entry = g_malloc0(sizeof (GtkItemFactoryEntry)); - entry->item_type = "<Separator>"; - entry->path = "/Statistics/"; - - /* - * merge only the menu items of the specific group, - * and then append a seperator - */ - if (merge_tap_menus_layered(node, REGISTER_TAP_GROUP_GENERIC)) { - gtk_item_factory_create_item(main_menu_factory, entry, NULL, 2); - } - if (merge_tap_menus_layered(node, REGISTER_TAP_GROUP_CONVERSATION_LIST)) { - /*gtk_item_factory_create_item(main_menu_factory, entry, NULL, 2);*/ - } - if (merge_tap_menus_layered(node, REGISTER_TAP_GROUP_ENDPOINT_LIST)) { - /*gtk_item_factory_create_item(main_menu_factory, entry, NULL, 2);*/ - } - if (merge_tap_menus_layered(node, REGISTER_TAP_GROUP_RESPONSE_TIME)) { - gtk_item_factory_create_item(main_menu_factory, entry, NULL, 2); - } - if (merge_tap_menus_layered(node, REGISTER_TAP_GROUP_NONE)) { - /*gtk_item_factory_create_item(main_menu_factory, entry, NULL, 2);*/ - } -} - - - -/* - * Enable/disable menu sensitivity. - */ -static void -set_menu_sensitivity(GtkItemFactory *ifactory, const gchar *path, gint val) -{ - GSList *menu_list; - GtkWidget *menu_item; - gchar *dup; - gchar *dest; - - - /* the underscore character regularly confuses things, as it will prevent finding - * the menu_item, so it has to be removed first */ - dup = g_strdup(path); - dest = dup; - while(*path) { - if (*path != '_') { - *dest = *path; - dest++; - } - path++; - } - *dest = '\0'; - - if (ifactory == NULL) { - /* - * Do it for all pop-up menus. - */ - for (menu_list = popup_menu_list; menu_list != NULL; - menu_list = g_slist_next(menu_list)) - set_menu_sensitivity(menu_list->data, dup, val); - } else { - /* - * Do it for that particular menu. - */ - if ((menu_item = gtk_item_factory_get_widget(ifactory, dup)) != NULL) { - if (GTK_IS_MENU(menu_item)) { - /* - * "dup" refers to a submenu; "gtk_item_factory_get_widget()" - * gets the menu, not the item that, when selected, pops up - * the submenu. - * - * We have to change the latter item's sensitivity, so that - * it shows up normally if sensitive and grayed-out if - * insensitive. - */ - menu_item = gtk_menu_get_attach_widget(GTK_MENU(menu_item)); - } - gtk_widget_set_sensitive(menu_item, val); - } else{ - /* be sure this menu item *is* existing */ - g_assert_not_reached(); - } - } - - g_free(dup); -} - -void -set_menu_object_data_meat(GtkItemFactory *ifactory, gchar *path, gchar *key, gpointer data) -{ - GtkWidget *menu = NULL; - - if ((menu = gtk_item_factory_get_widget(ifactory, path)) != NULL) - OBJECT_SET_DATA(menu, key, data); -} - -void -set_menu_object_data (gchar *path, gchar *key, gpointer data) { - GSList *menu_list = popup_menu_list; - gchar *shortpath = strrchr(path, '/'); - - set_menu_object_data_meat(main_menu_factory, path, key, data); - while (menu_list != NULL) { - set_menu_object_data_meat(menu_list->data, shortpath, key, data); - menu_list = g_slist_next(menu_list); - } -} - - -/* Recently used capture files submenu: - * Submenu containing the recently used capture files. - * The capture filenames are always kept with the absolute path, to be independant - * of the current path. - * They are only stored inside the labels of the submenu (no separate list). */ - -#define MENU_RECENT_FILES_PATH "/File/Open Recent" -#define MENU_RECENT_FILES_KEY "Recent File Name" - -void -update_menu_recent_capture_file1(GtkWidget *widget, gpointer cnt) { - gchar *widget_cf_name; - - widget_cf_name = OBJECT_GET_DATA(widget, MENU_RECENT_FILES_KEY); - - /* if this menu item is a file, count it */ - if (widget_cf_name) { - (*(guint *)cnt)++; - } -} - - -/* update the menu */ -void -update_menu_recent_capture_file(GtkWidget *submenu_recent_files) { - guint cnt = 0; - - gtk_container_foreach(GTK_CONTAINER(submenu_recent_files), - update_menu_recent_capture_file1, &cnt); - - /* make parent menu item sensitive only, if we have any valid files in the list */ - set_menu_sensitivity(main_menu_factory, MENU_RECENT_FILES_PATH, cnt); -} - - -/* remove the capture filename from the "Recent Files" menu */ -void -remove_menu_recent_capture_file(GtkWidget *widget, gpointer unused _U_) { - GtkWidget *submenu_recent_files; - gchar *widget_cf_name; - - - widget_cf_name = OBJECT_GET_DATA(widget, MENU_RECENT_FILES_KEY); - g_free(widget_cf_name); - - /* get the submenu container item */ - submenu_recent_files = gtk_item_factory_get_widget(main_menu_factory, MENU_RECENT_FILES_PATH); - - /* XXX: is this all we need to do, to free the menu item and its label? - The reference count of widget will go to 0, so it'll be freed; - will that free the label? */ - gtk_container_remove(GTK_CONTAINER(submenu_recent_files), widget); -} - - -/* callback, if the user pushed the <Clear File List> item */ -static void -clear_menu_recent_capture_file_cmd_cb(GtkWidget *w _U_, gpointer unused _U_) { - GtkWidget *submenu_recent_files; - - - submenu_recent_files = gtk_item_factory_get_widget(main_menu_factory, MENU_RECENT_FILES_PATH); - - gtk_container_foreach(GTK_CONTAINER(submenu_recent_files), - remove_menu_recent_capture_file, NULL); - - update_menu_recent_capture_file(submenu_recent_files); -} - - -/* callback, if the user pushed a recent file submenu item */ -void -menu_open_recent_file_cmd(GtkWidget *w) -{ - GtkWidget *submenu_recent_files; - GtkWidget *menu_item_child; - gchar *cf_name; - int err; - - submenu_recent_files = gtk_item_factory_get_widget(main_menu_factory, MENU_RECENT_FILES_PATH); - - /* get capture filename from the menu item label */ - menu_item_child = (GTK_BIN(w))->child; - gtk_label_get(GTK_LABEL(menu_item_child), &cf_name); - - /* open and read the capture file (this will close an existing file) */ - if ((err = cf_open(cf_name, FALSE, &cfile)) == 0) { - cf_read(&cfile); - } else { - /* the capture file isn't existing any longer, remove menu item */ - /* XXX: ask user to remove item, it's maybe only a temporary problem */ - remove_menu_recent_capture_file(w, NULL); - } - - update_menu_recent_capture_file(submenu_recent_files); -} - -static void menu_open_recent_file_answered_cb(gpointer dialog _U_, gint btn, gpointer data _U_) -{ - switch(btn) { - case(ESD_BTN_YES): - /* save file first */ - file_save_as_cmd(after_save_open_recent_file, data); - break; - case(ESD_BTN_NO): - cf_close(&cfile); - menu_open_recent_file_cmd(data); - break; - case(ESD_BTN_CANCEL): - break; - default: - g_assert_not_reached(); - } -} - -void -menu_open_recent_file_cmd_cb(GtkWidget *widget, gpointer data _U_) { - gpointer dialog; - - - if((cfile.state != FILE_CLOSED) && !cfile.user_saved && prefs.gui_ask_unsaved) { - /* user didn't saved his current file, ask him */ - dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_YES_NO_CANCEL, - PRIMARY_TEXT_START "Save capture file before opening a new one?" PRIMARY_TEXT_END "\n\n" - "If you open a new capture file without saving, your current capture data will be discarded."); - simple_dialog_set_cb(dialog, menu_open_recent_file_answered_cb, widget); - } else { - /* unchanged file */ - menu_open_recent_file_cmd(widget); - } -} - -/* add the capture filename (with an absolute path) to the "Recent Files" menu */ -void -add_menu_recent_capture_file_absolute(gchar *cf_name) { - GtkWidget *submenu_recent_files; - GList *menu_item_list; - GList *li; - gchar *widget_cf_name; - gchar *normalized_cf_name; - GtkWidget *menu_item; - guint cnt; - - - - normalized_cf_name = g_strdup(cf_name); -#ifdef WIN32 - /* replace all slashes by backslashes */ - g_strdelimit(normalized_cf_name, "/", '\\'); -#endif - - /* get the submenu container item */ - submenu_recent_files = gtk_item_factory_get_widget(main_menu_factory, MENU_RECENT_FILES_PATH); - - /* convert container to a GList */ - menu_item_list = gtk_container_children(GTK_CONTAINER(submenu_recent_files)); - - /* iterate through list items of menu_item_list, - * removing special items, a maybe duplicate entry and every item above count_max */ - cnt = 1; - for (li = g_list_first(menu_item_list); li; li = li->next, cnt++) { - /* get capture filename */ - menu_item = GTK_WIDGET(li->data); - widget_cf_name = OBJECT_GET_DATA(menu_item, MENU_RECENT_FILES_KEY); - - /* if this element string is one of our special items (seperator, ...) or - * already in the list or - * this element is above maximum count (too old), remove it */ - if (!widget_cf_name || -#ifdef WIN32 - /* do a case insensitive compare on win32 */ -#if GLIB_MAJOR_VERSION < 2 - g_strncasecmp(widget_cf_name, normalized_cf_name, 1000) == 0 || -#else - g_ascii_strncasecmp(widget_cf_name, normalized_cf_name, 1000) == 0 || -#endif -#else /* WIN32 */ - /* do a case sensitive compare on unix */ - strncmp(widget_cf_name, normalized_cf_name, 1000) == 0 || -#endif - cnt >= prefs.gui_recent_files_count_max) { - remove_menu_recent_capture_file(li->data, NULL); - cnt--; - } - } - - g_list_free(menu_item_list); - - /* add new item at latest position */ - menu_item = gtk_menu_item_new_with_label(normalized_cf_name); - OBJECT_SET_DATA(menu_item, MENU_RECENT_FILES_KEY, normalized_cf_name); - gtk_menu_prepend (GTK_MENU(submenu_recent_files), menu_item); - SIGNAL_CONNECT_OBJECT(GTK_OBJECT(menu_item), "activate", - menu_open_recent_file_cmd_cb, (GtkObject *) menu_item); - gtk_widget_show (menu_item); - - /* add seperator at last position */ - menu_item = gtk_menu_item_new(); - gtk_menu_append (GTK_MENU(submenu_recent_files), menu_item); - gtk_widget_show (menu_item); - - /* add new "clear list" item at last position */ -#if GTK_MAJOR_VERSION < 2 - menu_item = gtk_menu_item_new_with_label("<Clear File List>"); -#else - menu_item = gtk_image_menu_item_new_from_stock(GTK_STOCK_CLEAR, NULL); -#endif - gtk_menu_append (GTK_MENU(submenu_recent_files), menu_item); - SIGNAL_CONNECT_OBJECT(GTK_OBJECT(menu_item), "activate", - clear_menu_recent_capture_file_cmd_cb, (GtkObject *) menu_item); - gtk_widget_show (menu_item); - - update_menu_recent_capture_file(submenu_recent_files); -} - - -/* add the capture filename to the "Recent Files" menu */ -/* (will change nothing, if this filename is already in the menu) */ -void -add_menu_recent_capture_file(gchar *cf_name) { - gchar *curr; - gchar *absolute; - - - /* if this filename is an absolute path, we can use it directly */ - if (g_path_is_absolute(cf_name)) { - add_menu_recent_capture_file_absolute(cf_name); - return; - } - - /* this filename is not an absolute path, prepend the current dir */ - curr = g_get_current_dir(); - absolute = g_strdup_printf("%s%s%s", curr, G_DIR_SEPARATOR_S, cf_name); - add_menu_recent_capture_file_absolute(absolute); - g_free(curr); - g_free(absolute); -} - - -/* write all capture filenames of the menu to the user's recent file */ -void -menu_recent_file_write_all(FILE *rf) { - GtkWidget *submenu_recent_files; - GList *children; - GList *child; - gchar *cf_name; - - - submenu_recent_files = gtk_item_factory_get_widget(main_menu_factory, MENU_RECENT_FILES_PATH); - - /* we have to iterate backwards through the children's list, - * so we get the latest item last in the file. - * (don't use gtk_container_foreach() here, it will return the wrong iteration order) */ - children = gtk_container_children(GTK_CONTAINER(submenu_recent_files)); - child = g_list_last(children); - while(child != NULL) { - /* get capture filename from the menu item label */ - cf_name = OBJECT_GET_DATA(child->data, MENU_RECENT_FILES_KEY); - if (cf_name) { - fprintf (rf, RECENT_KEY_CAPTURE_FILE ": %s\n", cf_name); - } - - child = g_list_previous(child); - } - - g_list_free(children); -} - - -static void -main_toolbar_show_cb(GtkWidget *w _U_, gpointer d _U_) -{ - - /* save current setting in recent */ - recent.main_toolbar_show = GTK_CHECK_MENU_ITEM(w)->active; - - main_widgets_show_or_hide(); -} - - -static void -filter_toolbar_show_cb(GtkWidget *w _U_, gpointer d _U_) -{ - - /* save current setting in recent */ - recent.filter_toolbar_show = GTK_CHECK_MENU_ITEM(w)->active; - - main_widgets_show_or_hide(); -} - - -static void -packet_list_show_cb(GtkWidget *w _U_, gpointer d _U_) -{ - - /* save current setting in recent */ - recent.packet_list_show = GTK_CHECK_MENU_ITEM(w)->active; - - main_widgets_show_or_hide(); -} - - -static void -tree_view_show_cb(GtkWidget *w _U_, gpointer d _U_) -{ - - /* save current setting in recent */ - recent.tree_view_show = GTK_CHECK_MENU_ITEM(w)->active; - - main_widgets_show_or_hide(); -} - - -static void -byte_view_show_cb(GtkWidget *w _U_, gpointer d _U_) -{ - - /* save current setting in recent */ - recent.byte_view_show = GTK_CHECK_MENU_ITEM(w)->active; - - main_widgets_show_or_hide(); -} - - -static void -statusbar_show_cb(GtkWidget *w _U_, gpointer d _U_) -{ - - /* save current setting in recent */ - recent.statusbar_show = GTK_CHECK_MENU_ITEM(w)->active; - - main_widgets_show_or_hide(); -} - - -static void -timestamp_absolute_cb(GtkWidget *w _U_, gpointer d _U_) -{ - if (recent.gui_time_format != TS_ABSOLUTE) { - set_timestamp_setting(TS_ABSOLUTE); - recent.gui_time_format = TS_ABSOLUTE; - change_time_formats(&cfile); - } -} - -static void -timestamp_absolute_date_cb(GtkWidget *w _U_, gpointer d _U_) -{ - if (recent.gui_time_format != TS_ABSOLUTE_WITH_DATE) { - set_timestamp_setting(TS_ABSOLUTE_WITH_DATE); - recent.gui_time_format = TS_ABSOLUTE_WITH_DATE; - change_time_formats(&cfile); - } -} - -static void -timestamp_relative_cb(GtkWidget *w _U_, gpointer d _U_) -{ - if (recent.gui_time_format != TS_RELATIVE) { - set_timestamp_setting(TS_RELATIVE); - recent.gui_time_format = TS_RELATIVE; - change_time_formats(&cfile); - } -} - -static void -timestamp_delta_cb(GtkWidget *w _U_, gpointer d _U_) -{ - if (recent.gui_time_format != TS_DELTA) { - set_timestamp_setting(TS_DELTA); - recent.gui_time_format = TS_DELTA; - change_time_formats(&cfile); - } -} - -void -menu_name_resolution_changed(void) -{ - GtkWidget *menu = NULL; - - menu = gtk_item_factory_get_widget(main_menu_factory, "/View/Name Resolution/Enable for MAC Layer"); - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), g_resolv_flags & RESOLV_MAC); - - menu = gtk_item_factory_get_widget(main_menu_factory, "/View/Name Resolution/Enable for Network Layer"); - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), g_resolv_flags & RESOLV_NETWORK); - - menu = gtk_item_factory_get_widget(main_menu_factory, "/View/Name Resolution/Enable for Transport Layer"); - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), g_resolv_flags & RESOLV_TRANSPORT); -} - -static void -name_resolution_mac_cb(GtkWidget *w _U_, gpointer d _U_) -{ - if (GTK_CHECK_MENU_ITEM(w)->active) { - g_resolv_flags |= RESOLV_MAC; - } else { - g_resolv_flags &= ~RESOLV_MAC; - } -} - -static void -name_resolution_network_cb(GtkWidget *w _U_, gpointer d _U_) -{ - if (GTK_CHECK_MENU_ITEM(w)->active) { - g_resolv_flags |= RESOLV_NETWORK; - } else { - g_resolv_flags &= ~RESOLV_NETWORK; - } -} - -static void -name_resolution_transport_cb(GtkWidget *w _U_, gpointer d _U_) -{ - if (GTK_CHECK_MENU_ITEM(w)->active) { - g_resolv_flags |= RESOLV_TRANSPORT; - } else { - g_resolv_flags &= ~RESOLV_TRANSPORT; - } -} - -#ifdef HAVE_LIBPCAP -static void -auto_scroll_live_cb(GtkWidget *w _U_, gpointer d _U_) -{ - auto_scroll_live = GTK_CHECK_MENU_ITEM(w)->active; -} -#endif - -/* the recent file read has finished, update the menu corresponding */ -void -menu_recent_read_finished(void) { - GtkWidget *menu = NULL; - - menu = gtk_item_factory_get_widget(main_menu_factory, "/View/Main Toolbar"); - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), recent.main_toolbar_show); - - menu = gtk_item_factory_get_widget(main_menu_factory, "/View/Filter Toolbar"); - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), recent.filter_toolbar_show); - - menu = gtk_item_factory_get_widget(main_menu_factory, "/View/Statusbar"); - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), recent.statusbar_show); - - menu = gtk_item_factory_get_widget(main_menu_factory, "/View/Packet List"); - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), recent.packet_list_show); - - menu = gtk_item_factory_get_widget(main_menu_factory, "/View/Packet Details"); - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), recent.tree_view_show); - - menu = gtk_item_factory_get_widget(main_menu_factory, "/View/Packet Bytes"); - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), recent.byte_view_show); - - menu_name_resolution_changed(); - -#ifdef HAVE_LIBPCAP - menu = gtk_item_factory_get_widget(main_menu_factory, "/View/Auto Scroll in Live Capture"); - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), auto_scroll_live); -#endif - - main_widgets_rearrange(); - - /* don't change the time format, if we had a command line value */ - if (get_timestamp_setting() != TS_NOT_SET) { - recent.gui_time_format = get_timestamp_setting(); - } - - switch(recent.gui_time_format) { - case(TS_ABSOLUTE): - menu = gtk_item_factory_get_widget(main_menu_factory, - "/View/Time Display Format/Time of Day"); - /* set_active will not trigger the callback when activating an active item! */ - recent.gui_time_format = -1; - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), FALSE); - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), TRUE); - break; - case(TS_ABSOLUTE_WITH_DATE): - menu = gtk_item_factory_get_widget(main_menu_factory, - "/View/Time Display Format/Date and Time of Day"); - recent.gui_time_format = -1; - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), TRUE); - break; - case(TS_RELATIVE): - menu = gtk_item_factory_get_widget(main_menu_factory, - "/View/Time Display Format/Seconds Since Beginning of Capture"); - recent.gui_time_format = -1; - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), TRUE); - break; - case(TS_DELTA): - menu = gtk_item_factory_get_widget(main_menu_factory, - "/View/Time Display Format/Seconds Since Previous Packet"); - recent.gui_time_format = -1; - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), TRUE); - break; - default: - g_assert_not_reached(); - } -} - - -gint -popup_menu_handler(GtkWidget *widget, GdkEvent *event, gpointer data) -{ - GtkWidget *menu = (GtkWidget *)data; - GdkEventButton *event_button = NULL; - gint row, column; - - if(widget == NULL || event == NULL || data == NULL) { - return FALSE; - } - - /* - * If we ever want to make the menu differ based on what row - * and/or column we're above, we'd use "eth_clist_get_selection_info()" - * to find the row and column number for the coordinates; a CTree is, - * I guess, like a CList with one column(?) and the expander widget - * as a pixmap. - */ - /* Check if we are on packet_list object */ - if (widget == OBJECT_GET_DATA(popup_menu_object, E_MPACKET_LIST_KEY)) { - if (packet_list_get_event_row_column(widget, (GdkEventButton *)event, - &row, &column)) { - OBJECT_SET_DATA(popup_menu_object, E_MPACKET_LIST_ROW_KEY, - GINT_TO_POINTER(row)); - OBJECT_SET_DATA(popup_menu_object, E_MPACKET_LIST_COL_KEY, - GINT_TO_POINTER(column)); - packet_list_set_selected_row(row); - } - } - - /* Check if we are on tree_view object */ - if (widget == tree_view) { - tree_view_select(widget, (GdkEventButton *) event); - } - - /* Check if we are on byte_view object */ - if(widget == get_notebook_bv_ptr(byte_nb_ptr)) { - byte_view_select(widget, (GdkEventButton *) event); - } - - /* context menu handler (but the byte view notebook pages have their own handler) */ - if(event->type == GDK_BUTTON_PRESS && widget != byte_nb_ptr) { - event_button = (GdkEventButton *) event; - - /* To qoute the "Gdk Event Structures" doc: - * "Normally button 1 is the left mouse button, 2 is the middle button, and 3 is the right button" */ - if(event_button->button == 3) { - gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, - event_button->button, - event_button->time); - SIGNAL_EMIT_STOP_BY_NAME(widget, "button_press_event"); - return TRUE; - } - } -#if GTK_MAJOR_VERSION >= 2 - /* GDK_2BUTTON_PRESS is a doubleclick -> expand/collapse tree row */ - /* GTK version 1 seems to be doing this automatically */ - if (widget == tree_view && event->type == GDK_2BUTTON_PRESS) { - GtkTreePath *path; - - if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), - (gint) (((GdkEventButton *)event)->x), - (gint) (((GdkEventButton *)event)->y), - &path, NULL, NULL, NULL)) - { - if (gtk_tree_view_row_expanded(GTK_TREE_VIEW(widget), path)) - gtk_tree_view_collapse_row(GTK_TREE_VIEW(widget), path); - else - gtk_tree_view_expand_row(GTK_TREE_VIEW(widget), path, - FALSE); - gtk_tree_path_free(path); - } - } -#endif - return FALSE; -} - -/* Enable or disable menu items based on whether you have a capture file - you've finished reading. */ -void -set_menus_for_capture_file(gboolean have_capture_file) -{ - set_menu_sensitivity(main_menu_factory, "/File/Open...", have_capture_file); - set_menu_sensitivity(main_menu_factory, "/File/Open Recent", have_capture_file); - set_menu_sensitivity(main_menu_factory, "/File/Merge...", have_capture_file); - set_menu_sensitivity(main_menu_factory, "/File/Close", have_capture_file); - set_menu_sensitivity(main_menu_factory, "/File/Save As...", - have_capture_file); - set_menu_sensitivity(main_menu_factory, "/File/Export", have_capture_file); - set_menu_sensitivity(main_menu_factory, "/View/Reload", have_capture_file); - set_toolbar_for_capture_file(have_capture_file); - packets_bar_update(); -} - -/* Enable or disable menu items based on whether you have an unsaved - capture file you've finished reading. */ -void -set_menus_for_unsaved_capture_file(gboolean have_unsaved_capture_file) -{ - set_menu_sensitivity(main_menu_factory, "/File/Save", - have_unsaved_capture_file); - set_toolbar_for_unsaved_capture_file(have_unsaved_capture_file); -} - -/* Enable or disable menu items based on whether there's a capture in - progress. */ -void -set_menus_for_capture_in_progress(gboolean capture_in_progress) -{ - set_menu_sensitivity(main_menu_factory, "/File/Open...", - !capture_in_progress); - set_menu_sensitivity(main_menu_factory, "/File/Open Recent", - !capture_in_progress); -#ifdef HAVE_LIBPCAP - set_menu_sensitivity(main_menu_factory, "/Capture/Start...", - !capture_in_progress); - set_menu_sensitivity(main_menu_factory, "/Capture/Stop", - capture_in_progress); -#endif /* HAVE_LIBPCAP */ - set_toolbar_for_capture_in_progress(capture_in_progress); -} - -/* Enable or disable menu items based on whether you have some captured - packets. */ -static gboolean -walk_menu_tree_for_captured_packets(GList *node, - gboolean have_captured_packets) -{ - gboolean is_enabled; - GList *child; - menu_item_t *node_data = node->data; - - /* - * Is this a leaf node or an interior node? - */ - if (node_data->children == NULL) { - /* - * It's a leaf node. - * - * If it has no "selected_packet_enabled()" or - * "selected_tree_row_enabled()" routines, we enable - * it. This allows tap windows to be popped up even - * if you have no capture file; this is done to let - * the user pop up multiple tap windows before reading - * in a capture file, so that they can be processed in - * parallel while the capture file is being read rather - * than one at at time as you pop up the windows, and to - * let the user pop up tap windows before starting an - * "Update list of packets in real time" capture, so that - * the statistics can be displayed while the capture is - * in progress. - * - * If it has either of those routines, we disable it for - * now - as long as, when a capture is first available, - * we don't get called after a packet or tree row is - * selected, that's OK. - * XXX - that should be done better. - */ - if (node_data->selected_packet_enabled == NULL && - node_data->selected_tree_row_enabled == NULL) - node_data->enabled = TRUE; - else - node_data->enabled = FALSE; - } else { - /* - * It's an interior node; call - * "walk_menu_tree_for_captured_packets()" on all its - * children and, if any of them are enabled, enable - * this node, otherwise disable it. - * - * XXX - should we just leave all interior nodes enabled? - * Which is a better UI choice? - */ - is_enabled = FALSE; - for (child = node_data->children; child != NULL; child = - child->next) { - if (walk_menu_tree_for_captured_packets(child, - have_captured_packets)) - is_enabled = TRUE; - } - node_data->enabled = is_enabled; - } - - /* - * The root node doesn't correspond to a menu tree item; it - * has a null name pointer. - */ - if (node_data->name != NULL) { - set_menu_sensitivity(main_menu_factory, node_data->name, - node_data->enabled); - } - return node_data->enabled; -} - -void -set_menus_for_captured_packets(gboolean have_captured_packets) -{ - set_menu_sensitivity(main_menu_factory, "/File/Print...", - have_captured_packets); - set_menu_sensitivity(packet_list_menu_factory, "/Print...", - have_captured_packets); - set_menu_sensitivity(main_menu_factory, "/Edit/Find Packet...", - have_captured_packets); - set_menu_sensitivity(main_menu_factory, "/Edit/Find Next", - have_captured_packets); - set_menu_sensitivity(main_menu_factory, "/Edit/Find Previous", - have_captured_packets); - set_menu_sensitivity(main_menu_factory, "/View/Zoom In", - have_captured_packets); - set_menu_sensitivity(main_menu_factory, "/View/Zoom Out", - have_captured_packets); - set_menu_sensitivity(main_menu_factory, "/View/Normal Size", - have_captured_packets); - set_menu_sensitivity(packet_list_menu_factory, "/Coloring Rules...", - have_captured_packets); - set_menu_sensitivity(main_menu_factory, "/Go/Go to Packet...", - have_captured_packets); - set_menu_sensitivity(main_menu_factory, "/Go/First Packet", - have_captured_packets); - set_menu_sensitivity(main_menu_factory, "/Go/Last Packet", - have_captured_packets); - set_menu_sensitivity(main_menu_factory, "/Statistics/Summary", - have_captured_packets); - set_menu_sensitivity(main_menu_factory, "/Statistics/Protocol Hierarchy", - have_captured_packets); - - walk_menu_tree_for_captured_packets(tap_menu_tree_root, - have_captured_packets); - set_toolbar_for_captured_packets(have_captured_packets); - packets_bar_update(); -} - -/* Enable or disable menu items based on whether a packet is selected and, - if so, on the properties of the packet. */ -static gboolean -walk_menu_tree_for_selected_packet(GList *node, frame_data *fd, - epan_dissect_t *edt) -{ - gboolean is_enabled; - GList *child; - menu_item_t *node_data = node->data; - - /* - * Is this a leaf node or an interior node? - */ - if (node_data->children == NULL) { - /* - * It's a leaf node. - * - * If it has no "selected_packet_enabled()" routine, - * leave its enabled/disabled status alone - it - * doesn't depend on whether we have a packet selected - * or not or on the selected packet. - * - * If it has a "selected_packet_enabled()" routine, - * call it and set the item's enabled/disabled status - * based on its return value. - */ - if (node_data->selected_packet_enabled != NULL) - node_data->enabled = node_data->selected_packet_enabled(fd, edt); - } else { - /* - * It's an interior node; call - * "walk_menu_tree_for_selected_packet()" on all its - * children and, if any of them are enabled, enable - * this node, otherwise disable it. - * - * XXX - should we just leave all interior nodes enabled? - * Which is a better UI choice? - */ - is_enabled = FALSE; - for (child = node_data->children; child != NULL; child = - child->next) { - if (walk_menu_tree_for_selected_packet(child, fd, edt)) - is_enabled = TRUE; - } - node_data->enabled = is_enabled; - } - - /* - * The root node doesn't correspond to a menu tree item; it - * has a null name pointer. - */ - if (node_data->name != NULL) { - set_menu_sensitivity(main_menu_factory, node_data->name, - node_data->enabled); - } - return node_data->enabled; -} - -void -set_menus_for_selected_packet(capture_file *cf) -{ - set_menu_sensitivity(main_menu_factory, "/Edit/Mark Packet", - cf->current_frame != NULL); - set_menu_sensitivity(packet_list_menu_factory, "/Mark Packet", - cf->current_frame != NULL); - set_menu_sensitivity(main_menu_factory, "/Edit/Time Reference", - cf->current_frame != NULL); - set_menu_sensitivity(packet_list_menu_factory, "/Time Reference", - cf->current_frame != NULL); - set_menu_sensitivity(main_menu_factory, "/Edit/Mark All Packets", - cf->current_frame != NULL); - set_menu_sensitivity(main_menu_factory, "/Edit/Unmark All Packets", - cf->current_frame != NULL); - set_menu_sensitivity(main_menu_factory, "/View/Collapse All", - cf->current_frame != NULL); - set_menu_sensitivity(tree_view_menu_factory, "/Collapse All", - cf->current_frame != NULL); - set_menu_sensitivity(main_menu_factory, "/View/Expand All", - cf->current_frame != NULL); - set_menu_sensitivity(tree_view_menu_factory, "/Expand All", - cf->current_frame != NULL); - set_menu_sensitivity(main_menu_factory, "/View/Show Packet in New Window", - cf->current_frame != NULL); - set_menu_sensitivity(packet_list_menu_factory, "/Show Packet in New Window", - cf->current_frame != NULL); - set_menu_sensitivity(main_menu_factory, "/Analyze/Follow TCP Stream", - cf->current_frame != NULL ? (cf->edt->pi.ipproto == IP_PROTO_TCP) : FALSE); - set_menu_sensitivity(NULL, "/Follow TCP Stream", - cf->current_frame != NULL ? (cf->edt->pi.ipproto == IP_PROTO_TCP) : FALSE); - set_menu_sensitivity(main_menu_factory, "/Analyze/Decode As...", - cf->current_frame != NULL && decode_as_ok()); - set_menu_sensitivity(NULL, "/Decode As...", - cf->current_frame != NULL && decode_as_ok()); - set_menu_sensitivity(main_menu_factory, "/View/Name Resolution/Resolve Name", - cf->current_frame != NULL && (g_resolv_flags & RESOLV_ALL_ADDRS) != RESOLV_ALL_ADDRS); - set_menu_sensitivity(tree_view_menu_factory, "/Resolve Name", - cf->current_frame != NULL && (g_resolv_flags & RESOLV_ALL_ADDRS) != RESOLV_ALL_ADDRS); - set_menu_sensitivity(packet_list_menu_factory, "/Apply as Filter", - cf->current_frame != NULL); - set_menu_sensitivity(packet_list_menu_factory, "/Prepare a Filter", - cf->current_frame != NULL); - - walk_menu_tree_for_selected_packet(tap_menu_tree_root, cf->current_frame, - cf->edt); - packets_bar_update(); -} - -/* Enable or disable menu items based on whether a tree row is selected - and, if so, on the properties of the tree row. */ -static gboolean -walk_menu_tree_for_selected_tree_row(GList *node, field_info *fi) -{ - gboolean is_enabled; - GList *child; - menu_item_t *node_data = node->data; - - /* - * Is this a leaf node or an interior node? - */ - if (node_data->children == NULL) { - /* - * It's a leaf node. - * - * If it has no "selected_tree_row_enabled()" routine, - * leave its enabled/disabled status alone - it - * doesn't depend on whether we have a tree row selected - * or not or on the selected tree row. - * - * If it has a "selected_tree_row_enabled()" routine, - * call it and set the item's enabled/disabled status - * based on its return value. - */ - if (node_data->selected_tree_row_enabled != NULL) - node_data->enabled = node_data->selected_tree_row_enabled(fi); - } else { - /* - * It's an interior node; call - * "walk_menu_tree_for_selected_tree_row()" on all its - * children and, if any of them are enabled, enable - * this node, otherwise disable it. - * - * XXX - should we just leave all interior nodes enabled? - * Which is a better UI choice? - */ - is_enabled = FALSE; - for (child = node_data->children; child != NULL; child = - child->next) { - if (walk_menu_tree_for_selected_tree_row(child, fi)) - is_enabled = TRUE; - } - node_data->enabled = is_enabled; - } - - /* - * The root node doesn't correspond to a menu tree item; it - * has a null name pointer. - */ - if (node_data->name != NULL) { - set_menu_sensitivity(main_menu_factory, node_data->name, - node_data->enabled); - } - return node_data->enabled; -} - -void -set_menus_for_selected_tree_row(capture_file *cf) -{ - gboolean properties; - - - set_menu_sensitivity(main_menu_factory, "/File/Export/Selected Packet Bytes...", - cf->finfo_selected != NULL); - set_menu_sensitivity(tree_view_menu_factory, "/Export Selected Packet Bytes...", - cf->finfo_selected != NULL); - set_menu_sensitivity(hexdump_menu_factory, "/Export Selected Packet Bytes...", - cf->finfo_selected != NULL); - - if (cf->finfo_selected != NULL) { - header_field_info *hfinfo = cf->finfo_selected->hfinfo; - if (hfinfo->parent == -1) { - properties = prefs_is_registered_protocol(hfinfo->abbrev); - } else { - properties = prefs_is_registered_protocol(proto_registrar_get_abbrev(hfinfo->parent)); - } - set_menu_sensitivity(main_menu_factory, - "/Go/Go to Corresponding Packet", hfinfo->type == FT_FRAMENUM); - set_menu_sensitivity(tree_view_menu_factory, - "/Go to Corresponding Packet", hfinfo->type == FT_FRAMENUM); - set_menu_sensitivity(main_menu_factory, "/Analyze/Apply as Filter", - proto_can_match_selected(cf->finfo_selected, cf->edt)); - set_menu_sensitivity(tree_view_menu_factory, "/Apply as Filter", - proto_can_match_selected(cf->finfo_selected, cf->edt)); - set_menu_sensitivity(main_menu_factory, "/Analyze/Prepare a Filter", - proto_can_match_selected(cf->finfo_selected, cf->edt)); - set_menu_sensitivity(tree_view_menu_factory, "/Prepare a Filter", - proto_can_match_selected(cf->finfo_selected, cf->edt)); - set_menu_sensitivity(tree_view_menu_factory, "/Protocol Preferences...", - properties); - set_menu_sensitivity(main_menu_factory, "/View/Expand Tree", cf->finfo_selected->tree_type != -1); - set_menu_sensitivity(tree_view_menu_factory, "/Expand Tree", cf->finfo_selected->tree_type != -1); - } else { - set_menu_sensitivity(main_menu_factory, - "/Go/Go to Corresponding Packet", FALSE); - set_menu_sensitivity(tree_view_menu_factory, - "/Go to Corresponding Packet", FALSE); - set_menu_sensitivity(main_menu_factory, "/Analyze/Apply as Filter", FALSE); - set_menu_sensitivity(tree_view_menu_factory, "/Apply as Filter", FALSE); - set_menu_sensitivity(main_menu_factory, "/Analyze/Prepare a Filter", FALSE); - set_menu_sensitivity(tree_view_menu_factory, "/Prepare a Filter", FALSE); - set_menu_sensitivity(tree_view_menu_factory, "/Protocol Preferences...", - FALSE); - set_menu_sensitivity(main_menu_factory, "/View/Expand Tree", FALSE); - set_menu_sensitivity(tree_view_menu_factory, "/Expand Tree", FALSE); - } - - walk_menu_tree_for_selected_tree_row(tap_menu_tree_root, cf->finfo_selected); -} +/* menu.c
+ * Menu routines
+ *
+ * $Id: menu.c,v 1.208 2004/07/07 16:26:52 ulfl Exp $
+ *
+ * Ethereal - Network traffic analyzer
+ * By Gerald Combs <gerald@ethereal.com>
+ * Copyright 1998 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <gtk/gtk.h>
+
+#include <string.h>
+
+#include "main.h"
+#include "menu.h"
+#include "tap_menu.h"
+#include <epan/packet.h>
+#include <epan/resolv.h>
+#include "prefs.h"
+#include "about_dlg.h"
+#include "capture_dlg.h"
+#include "color_dlg.h"
+#include "filter_prefs.h"
+#include "dlg_utils.h"
+#include "file_dlg.h"
+#include "find_dlg.h"
+#include "goto_dlg.h"
+#include "summary_dlg.h"
+#include "prefs_dlg.h"
+#include "packet_win.h"
+#include "print.h"
+#include "follow_dlg.h"
+#include "decode_as_dlg.h"
+#include "help_dlg.h"
+#include "supported_protos_dlg.h"
+#include "proto_dlg.h"
+#include "proto_hier_stats_dlg.h"
+#include "keys.h"
+#include <epan/plugins.h>
+#include <epan/epan_dissect.h>
+#include "compat_macros.h"
+#include "toolbar.h"
+#include "gtkglobals.h"
+#include "register.h"
+#include "../tap.h"
+#include "../menu.h"
+#include "../ipproto.h"
+#include "packet_list.h"
+#include "ethclist.h"
+#include "recent.h"
+#include "../ui_util.h"
+#include "proto_draw.h"
+#include "endpoint_talkers_table.h"
+#include "hostlist_table.h"
+#include "simple_dialog.h"
+#include <epan/timestamp.h>
+
+GtkWidget *popup_menu_object;
+
+static void
+clear_menu_recent_capture_file_cmd_cb(GtkWidget *w, gpointer unused _U_);
+
+typedef struct _menu_item {
+ char *name;
+ gint group;
+ gboolean enabled;
+ GtkItemFactoryCallback callback;
+ gpointer callback_data;
+ gboolean (*selected_packet_enabled)(frame_data *, epan_dissect_t *);
+ gboolean (*selected_tree_row_enabled)(field_info *);
+ GList *children;
+} menu_item_t;
+
+static GList *tap_menu_tree_root = NULL;
+
+static void
+merge_all_tap_menus(GList *node);
+
+#define GTK_MENU_FUNC(a) ((GtkItemFactoryCallback)(a))
+
+static void menus_init(void);
+static void set_menu_sensitivity (GtkItemFactory *, const gchar *, gint);
+static void main_toolbar_show_cb(GtkWidget *w _U_, gpointer d _U_);
+static void filter_toolbar_show_cb(GtkWidget *w _U_, gpointer d _U_);
+static void packet_list_show_cb(GtkWidget *w _U_, gpointer d _U_);
+static void tree_view_show_cb(GtkWidget *w _U_, gpointer d _U_);
+static void byte_view_show_cb(GtkWidget *w _U_, gpointer d _U_);
+static void statusbar_show_cb(GtkWidget *w _U_, gpointer d _U_);
+static void timestamp_absolute_cb(GtkWidget *w _U_, gpointer d _U_);
+static void timestamp_absolute_date_cb(GtkWidget *w _U_, gpointer d _U_);
+static void timestamp_relative_cb(GtkWidget *w _U_, gpointer d _U_);
+static void timestamp_delta_cb(GtkWidget *w _U_, gpointer d _U_);
+static void name_resolution_mac_cb(GtkWidget *w _U_, gpointer d _U_);
+static void name_resolution_network_cb(GtkWidget *w _U_, gpointer d _U_);
+static void name_resolution_transport_cb(GtkWidget *w _U_, gpointer d _U_);
+#ifdef HAVE_LIBPCAP
+static void auto_scroll_live_cb(GtkWidget *w _U_, gpointer d _U_);
+#endif
+
+/* This is the GtkItemFactoryEntry structure used to generate new menus.
+ Item 1: The menu path. The letter after the underscore indicates an
+ accelerator key once the menu is open.
+ Item 2: The accelerator key for the entry
+ Item 3: The callback function.
+ Item 4: The callback action. This changes the parameters with
+ which the function is called. The default is 0.
+ Item 5: The item type, used to define what kind of an item it is.
+ Here are the possible values:
+
+ NULL -> "<Item>"
+ "" -> "<Item>"
+ "<Title>" -> create a title item
+ "<Item>" -> create a simple item
+ "<ImageItem>" -> create an item holding an image (gtk2)
+ "<StockItem>" -> create an item holding a stock image (gtk2)
+ "<CheckItem>" -> create a check item
+ "<ToggleItem>" -> create a toggle item
+ "<RadioItem>" -> create a radio item
+ <path> -> path of a radio item to link against
+ "<Separator>" -> create a separator
+ "<Tearoff>" -> create a tearoff separator (gtk2)
+ "<Branch>" -> create an item to hold sub items (optional)
+ "<LastBranch>" -> create a right justified branch
+ Item 6: extra data needed for ImageItem and StockItem (gtk2)
+ */
+
+/* main menu */
+static GtkItemFactoryEntry menu_items[] =
+{
+ ITEM_FACTORY_ENTRY("/_File", NULL, NULL, 0, "<Branch>", NULL),
+ ITEM_FACTORY_STOCK_ENTRY("/File/_Open...", "<control>O", file_open_cmd_cb,
+ 0, GTK_STOCK_OPEN),
+ ITEM_FACTORY_ENTRY("/File/Open _Recent", NULL, NULL, 0, "<Branch>", NULL),
+ ITEM_FACTORY_ENTRY("/File/_Merge...", NULL, file_merge_cmd_cb, 0, NULL, NULL),
+ ITEM_FACTORY_STOCK_ENTRY("/File/_Close", "<control>W", file_close_cmd_cb,
+ 0, GTK_STOCK_CLOSE),
+ ITEM_FACTORY_ENTRY("/File/<separator>", NULL, NULL, 0, "<Separator>", NULL),
+ ITEM_FACTORY_STOCK_ENTRY("/File/_Save", "<control>S", file_save_cmd_cb,
+ 0, GTK_STOCK_SAVE),
+ ITEM_FACTORY_STOCK_ENTRY("/File/Save _As...", "<shift><control>S", file_save_as_cmd_cb,
+ 0, GTK_STOCK_SAVE_AS),
+ ITEM_FACTORY_ENTRY("/File/<separator>", NULL, NULL, 0, "<Separator>", NULL),
+ ITEM_FACTORY_ENTRY("/File/_Export", NULL, NULL, 0, "<Branch>", NULL),
+ ITEM_FACTORY_ENTRY("/File/Export/as \"Plain _Text\" file...", NULL, export_text_cmd_cb,
+ 0, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/File/Export/as \"_PostScript\" file...", NULL, export_ps_cmd_cb,
+ 0, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/File/Export/as XML - \"P_SML\" (packet summary) file...", NULL, export_psml_cmd_cb,
+ 0, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/File/Export/as XML - \"P_DML\" (packet details) file...", NULL, export_pdml_cmd_cb,
+ 0, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/File/Export/<separator>", NULL, NULL, 0, "<Separator>", NULL),
+ ITEM_FACTORY_ENTRY("/File/Export/Selected Packet _Bytes...", "<control>H", savehex_cb,
+ 0, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/File/<separator>", NULL, NULL, 0, "<Separator>", NULL),
+ ITEM_FACTORY_STOCK_ENTRY("/File/_Print...", "<control>P", file_print_cmd_cb,
+ 0, GTK_STOCK_PRINT),
+ ITEM_FACTORY_ENTRY("/File/<separator>", NULL, NULL, 0, "<Separator>", NULL),
+ ITEM_FACTORY_STOCK_ENTRY("/File/_Quit", "<control>Q", file_quit_cmd_cb,
+ 0, GTK_STOCK_QUIT),
+ ITEM_FACTORY_ENTRY("/_Edit", NULL, NULL, 0, "<Branch>", NULL),
+#if 0
+ /* Un-#if this when we actually implement Cut/Copy/Paste. */
+ ITEM_FACTORY_STOCK_ENTRY("/Edit/Cut", "<control>X", NULL,
+ 0, GTK_STOCK_CUT),
+ ITEM_FACTORY_STOCK_ENTRY("/Edit/Copy", "<control>C", NULL,
+ 0, GTK_STOCK_COPY),
+ ITEM_FACTORY_STOCK_ENTRY("/Edit/Paste", "<control>V", NULL,
+ 0, GTK_STOCK_PASTE),
+ ITEM_FACTORY_ENTRY("/Edit/<separator>", NULL, NULL, 0, "<Separator>"),
+#endif
+ ITEM_FACTORY_STOCK_ENTRY("/Edit/_Find Packet...", "<control>F",
+ find_frame_cb, 0, GTK_STOCK_FIND),
+ ITEM_FACTORY_STOCK_ENTRY("/Edit/Find Ne_xt", "<control>N", find_next_cb,
+ 0, GTK_STOCK_GO_FORWARD),
+ ITEM_FACTORY_STOCK_ENTRY("/Edit/Find Pre_vious", "<control>B",
+ find_previous_cb, 0, GTK_STOCK_GO_BACK),
+ ITEM_FACTORY_ENTRY("/Edit/<separator>", NULL, NULL, 0, "<Separator>", NULL),
+ ITEM_FACTORY_ENTRY("/Edit/_Time Reference", NULL, NULL, 0, "<Branch>", NULL),
+ ITEM_FACTORY_ENTRY("/Edit/Time Reference/Set Time Reference (toggle)", "<control>T", reftime_frame_cb, REFTIME_TOGGLE, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Edit/Time Reference/Find Next", NULL, reftime_frame_cb, REFTIME_FIND_NEXT, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Edit/Time Reference/Find Previous", NULL, reftime_frame_cb, REFTIME_FIND_PREV, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Edit/_Mark Packet", "<control>M", mark_frame_cb,
+ 0, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Edit/Mark _All Packets", NULL, mark_all_frames_cb,
+ 0, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Edit/_Unmark All Packets", NULL, unmark_all_frames_cb,
+ 0, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Edit/<separator>", NULL, NULL, 0, "<Separator>", NULL),
+ ITEM_FACTORY_STOCK_ENTRY("/Edit/_Preferences...", "<shift><control>P", prefs_cb,
+ 0, GTK_STOCK_PREFERENCES),
+ ITEM_FACTORY_ENTRY("/_View", NULL, NULL, 0, "<Branch>", NULL),
+ ITEM_FACTORY_ENTRY("/View/_Main Toolbar", NULL, main_toolbar_show_cb, 0, "<CheckItem>", NULL),
+ ITEM_FACTORY_ENTRY("/View/_Filter Toolbar", NULL, filter_toolbar_show_cb, 0, "<CheckItem>", NULL),
+ ITEM_FACTORY_ENTRY("/View/_Statusbar", NULL, statusbar_show_cb, 0, "<CheckItem>", NULL),
+ ITEM_FACTORY_ENTRY("/View/<separator>", NULL, NULL, 0, "<Separator>", NULL),
+ ITEM_FACTORY_ENTRY("/View/Packet _List", NULL, packet_list_show_cb, 0, "<CheckItem>", NULL),
+ ITEM_FACTORY_ENTRY("/View/Packet _Details", NULL, tree_view_show_cb, 0, "<CheckItem>", NULL),
+ ITEM_FACTORY_ENTRY("/View/Packet _Bytes", NULL, byte_view_show_cb, 0, "<CheckItem>", NULL),
+ ITEM_FACTORY_ENTRY("/View/<separator>", NULL, NULL, 0, "<Separator>", NULL),
+ ITEM_FACTORY_ENTRY("/View/_Time Display Format", NULL, NULL, 0, "<Branch>", NULL),
+ ITEM_FACTORY_ENTRY("/View/Time Display Format/Time of Day", NULL, timestamp_absolute_cb,
+ 0, "<RadioItem>", NULL),
+ ITEM_FACTORY_ENTRY("/View/Time Display Format/Date and Time of Day", NULL, timestamp_absolute_date_cb,
+ 0, "/View/Time Display Format/Time of Day", NULL),
+ ITEM_FACTORY_ENTRY("/View/Time Display Format/Seconds Since Beginning of Capture", NULL, timestamp_relative_cb,
+ 0, "/View/Time Display Format/Time of Day", NULL),
+ ITEM_FACTORY_ENTRY("/View/Time Display Format/Seconds Since Previous Packet", NULL, timestamp_delta_cb,
+ 0, "/View/Time Display Format/Time of Day", NULL),
+ ITEM_FACTORY_ENTRY("/View/Name Resol_ution", NULL, NULL, 0, "<Branch>", NULL),
+ ITEM_FACTORY_ENTRY("/View/Name Resolution/_Resolve Name", NULL, resolve_name_cb, 0, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/View/Name Resolution/<separator>", NULL, NULL, 0, "<Separator>", NULL),
+ ITEM_FACTORY_ENTRY("/View/Name Resolution/Enable for _MAC Layer", NULL, name_resolution_mac_cb, 0, "<CheckItem>", NULL),
+ ITEM_FACTORY_ENTRY("/View/Name Resolution/Enable for _Network Layer", NULL, name_resolution_network_cb, 0, "<CheckItem>", NULL),
+ ITEM_FACTORY_ENTRY("/View/Name Resolution/Enable for _Transport Layer", NULL, name_resolution_transport_cb, 0, "<CheckItem>", NULL),
+#ifdef HAVE_LIBPCAP
+ ITEM_FACTORY_ENTRY("/View/Auto Scroll in Li_ve Capture", NULL, auto_scroll_live_cb, 0, "<CheckItem>", NULL),
+#endif
+ ITEM_FACTORY_ENTRY("/View/<separator>", NULL, NULL, 0, "<Separator>", NULL),
+ ITEM_FACTORY_STOCK_ENTRY("/View/_Zoom In", "<control>plus", view_zoom_in_cb,
+ 0, GTK_STOCK_ZOOM_IN),
+ ITEM_FACTORY_STOCK_ENTRY("/View/Zoom _Out", "<control>minus", view_zoom_out_cb,
+ 0, GTK_STOCK_ZOOM_OUT),
+ ITEM_FACTORY_STOCK_ENTRY("/View/_Normal Size", "<control>equal", view_zoom_100_cb,
+ 0, GTK_STOCK_ZOOM_100),
+ ITEM_FACTORY_ENTRY("/View/<separator>", NULL, NULL, 0, "<Separator>", NULL),
+ ITEM_FACTORY_ENTRY("/View/Collapse _All", NULL, collapse_all_cb,
+ 0, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/View/_Expand All", NULL, expand_all_cb,
+ 0, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/View/Expand Tree", NULL, expand_tree_cb, 0, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/View/<separator>", NULL, NULL, 0, "<Separator>", NULL),
+ ITEM_FACTORY_STOCK_ENTRY("/View/_Coloring Rules...", NULL, color_display_cb,
+ 0, GTK_STOCK_SELECT_COLOR),
+ ITEM_FACTORY_ENTRY("/View/<separator>", NULL, NULL, 0, "<Separator>", NULL),
+ ITEM_FACTORY_ENTRY("/View/Show Packet in New _Window", NULL,
+ new_window_cb, 0, NULL, NULL),
+ ITEM_FACTORY_STOCK_ENTRY("/View/_Reload", "<control>R", file_reload_cmd_cb,
+ 0, GTK_STOCK_REFRESH),
+ ITEM_FACTORY_ENTRY("/_Go", NULL, NULL, 0, "<Branch>", NULL),
+ ITEM_FACTORY_STOCK_ENTRY("/Go/_Go to Packet...", "<control>G",
+ goto_frame_cb, 0, GTK_STOCK_JUMP_TO),
+ ITEM_FACTORY_ENTRY("/Go/Go to _Corresponding Packet", NULL, goto_framenum_cb,
+ 0, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Go/<separator>", NULL, NULL, 0, "<Separator>", NULL),
+ ITEM_FACTORY_STOCK_ENTRY("/Go/_First Packet", NULL,
+ goto_top_frame_cb, 0, GTK_STOCK_GOTO_TOP),
+ ITEM_FACTORY_STOCK_ENTRY("/Go/_Last Packet", NULL,
+ goto_bottom_frame_cb, 0, GTK_STOCK_GOTO_BOTTOM),
+#ifdef HAVE_LIBPCAP
+ ITEM_FACTORY_ENTRY("/_Capture", NULL, NULL, 0, "<Branch>", NULL),
+ ITEM_FACTORY_STOCK_ENTRY("/Capture/_Start...", "<control>K",
+ capture_prep_cb, 0, ETHEREAL_STOCK_CAPTURE_START),
+ ITEM_FACTORY_STOCK_ENTRY("/Capture/S_top", "<control>E", capture_stop_cb,
+ 0, GTK_STOCK_STOP),
+ ITEM_FACTORY_ENTRY("/Capture/_Interfaces...", NULL,
+ capture_if_cb, 0, NULL, NULL),
+ ITEM_FACTORY_STOCK_ENTRY("/Capture/_Capture Filters...", NULL, cfilter_dialog_cb,
+ 0, ETHEREAL_STOCK_CAPTURE_FILTER),
+#endif /* HAVE_LIBPCAP */
+ ITEM_FACTORY_ENTRY("/_Analyze", NULL, NULL, 0, "<Branch>", NULL),
+ ITEM_FACTORY_STOCK_ENTRY("/Analyze/_Display Filters...", NULL, dfilter_dialog_cb,
+ 0, ETHEREAL_STOCK_DISPLAY_FILTER),
+ ITEM_FACTORY_ENTRY("/Analyze/Appl_y as Filter", NULL, NULL, 0, "<Branch>", NULL),
+ ITEM_FACTORY_ENTRY("/Analyze/Apply as Filter/_Selected", NULL, match_selected_ptree_cb,
+ MATCH_SELECTED_REPLACE|MATCH_SELECTED_APPLY_NOW, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Analyze/Apply as Filter/_Not Selected", NULL, match_selected_ptree_cb,
+ MATCH_SELECTED_NOT|MATCH_SELECTED_APPLY_NOW, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Analyze/Apply as Filter/... _and Selected", NULL, match_selected_ptree_cb,
+ MATCH_SELECTED_AND|MATCH_SELECTED_APPLY_NOW, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Analyze/Apply as Filter/... _or Selected", NULL, match_selected_ptree_cb,
+ MATCH_SELECTED_OR|MATCH_SELECTED_APPLY_NOW, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Analyze/Apply as Filter/... a_nd not Selected", NULL, match_selected_ptree_cb,
+ MATCH_SELECTED_AND_NOT|MATCH_SELECTED_APPLY_NOW, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Analyze/Apply as Filter/... o_r not Selected", NULL, match_selected_ptree_cb,
+ MATCH_SELECTED_OR_NOT|MATCH_SELECTED_APPLY_NOW, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Analyze/_Prepare a Filter", NULL, NULL, 0, "<Branch>", NULL),
+ ITEM_FACTORY_ENTRY("/Analyze/Prepare a Filter/_Selected", NULL, match_selected_ptree_cb,
+ MATCH_SELECTED_REPLACE, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Analyze/Prepare a Filter/_Not Selected", NULL, match_selected_ptree_cb,
+ MATCH_SELECTED_NOT, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Analyze/Prepare a Filter/... _and Selected", NULL, match_selected_ptree_cb,
+ MATCH_SELECTED_AND, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Analyze/Prepare a Filter/... _or Selected", NULL, match_selected_ptree_cb,
+ MATCH_SELECTED_OR, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Analyze/Prepare a Filter/... a_nd not Selected", NULL, match_selected_ptree_cb,
+ MATCH_SELECTED_AND_NOT, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Analyze/Prepare a Filter/... o_r not Selected", NULL, match_selected_ptree_cb,
+ MATCH_SELECTED_OR_NOT, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Analyze/<separator>", NULL, NULL, 0, "<Separator>", NULL),
+ ITEM_FACTORY_ENTRY("/Analyze/_Enabled Protocols...", "<shift><control>R", proto_cb, 0, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Analyze/Decode _As...", NULL, decode_as_cb,
+ 0, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Analyze/_User Specified Decodes...", NULL,
+ decode_show_cb, 0, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Analyze/<separator>", NULL, NULL, 0, "<Separator>", NULL),
+ ITEM_FACTORY_ENTRY("/Analyze/_Follow TCP Stream", NULL,
+ follow_stream_cb, 0, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/_Statistics", NULL, NULL, 0, "<Branch>", NULL),
+ ITEM_FACTORY_ENTRY("/Statistics/_Summary", NULL, summary_open_cb, 0, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Statistics/_Protocol Hierarchy", NULL,
+ proto_hier_stats_cb, 0, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Statistics/Conversations", NULL,
+ init_ett_notebook_cb, 0, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Statistics/Endpoints", NULL,
+ init_hostlist_notebook_cb, 0, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/_Help", NULL, NULL, 0, "<Branch>", NULL),
+ ITEM_FACTORY_STOCK_ENTRY("/Help/_Contents", "F1", help_cb, 0, GTK_STOCK_HELP),
+ ITEM_FACTORY_ENTRY("/Help/_Supported Protocols", NULL, supported_cb, 0, NULL, NULL),
+#if (GLIB_MAJOR_VERSION >= 2)
+ /* currently, glib1.x can't start a webbrowser, see webbrowser.c for details */
+ ITEM_FACTORY_ENTRY("/Help/Manual Pages", NULL, NULL, 0, "<Branch>", NULL),
+ ITEM_FACTORY_ENTRY("/Help/Manual Pages/Ethereal", NULL, url_localpage_cb, LOCALPAGE_MAN_ETHEREAL, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Help/Manual Pages/Ethereal Filter", NULL, url_localpage_cb, LOCALPAGE_MAN_ETHEREAL_FILTER, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Help/Manual Pages/<separator>", NULL, NULL, 0, "<Separator>", NULL),
+ ITEM_FACTORY_ENTRY("/Help/Manual Pages/Tethereal", NULL, url_localpage_cb, LOCALPAGE_MAN_TETHEREAL, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Help/Manual Pages/Mergecap", NULL, url_localpage_cb, LOCALPAGE_MAN_MERGECAP, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Help/Manual Pages/Editcap", NULL, url_localpage_cb, LOCALPAGE_MAN_EDITCAP, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Help/Manual Pages/Text2pcap", NULL, url_localpage_cb, LOCALPAGE_MAN_TEXT2PCAP, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Help/Ethereal Online", NULL, NULL, 0, "<Branch>", NULL),
+ ITEM_FACTORY_STOCK_ENTRY("/Help/Ethereal Online/Home Page", NULL, url_onlinepage_cb, ONLINEPAGE_HOME, GTK_STOCK_HOME),
+ ITEM_FACTORY_ENTRY("/Help/Ethereal Online/User's Guide", NULL, url_onlinepage_cb, ONLINEPAGE_USERGUIDE, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Help/Ethereal Online/FAQ's", NULL, url_onlinepage_cb, ONLINEPAGE_FAQ, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Help/Ethereal Online/Downloads", NULL, url_onlinepage_cb, ONLINEPAGE_DOWNLOAD, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Help/Ethereal Online/Example Files", NULL, url_onlinepage_cb, ONLINEPAGE_SAMPLE, NULL, NULL),
+#endif
+ ITEM_FACTORY_ENTRY("/Help/<separator>", NULL, NULL, 0, "<Separator>", NULL),
+ ITEM_FACTORY_ENTRY("/Help/_About Ethereal", NULL, about_ethereal_cb,
+ 0, NULL, NULL)
+};
+
+
+/* calculate the number of menu_items */
+static int nmenu_items = sizeof(menu_items) / sizeof(menu_items[0]);
+
+/* packet list popup */
+static GtkItemFactoryEntry packet_list_menu_items[] =
+{
+ ITEM_FACTORY_ENTRY("/Follow TCP Stream", NULL, follow_stream_cb,
+ 0, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Decode As...", NULL, decode_as_cb, 0, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Display Filters...", NULL, dfilter_dialog_cb,
+ 0, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/<separator>", NULL, NULL, 0, "<Separator>", NULL),
+ ITEM_FACTORY_ENTRY("/Mark Packet", NULL, mark_frame_cb, 0, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Time Reference", NULL, NULL, 0, "<Branch>", NULL),
+ ITEM_FACTORY_ENTRY("/Time Reference/Set Time Reference (toggle)", NULL, reftime_frame_cb, REFTIME_TOGGLE, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Time Reference/Find Next", NULL, reftime_frame_cb, REFTIME_FIND_NEXT, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Time Reference/Find Previous", NULL, reftime_frame_cb, REFTIME_FIND_PREV, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Apply as Filter", NULL, NULL, 0, "<Branch>", NULL),
+ ITEM_FACTORY_ENTRY("/Apply as Filter/_Selected", NULL, match_selected_plist_cb,
+ MATCH_SELECTED_REPLACE|MATCH_SELECTED_APPLY_NOW, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Apply as Filter/_Not Selected", NULL, match_selected_plist_cb,
+ MATCH_SELECTED_NOT|MATCH_SELECTED_APPLY_NOW, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Apply as Filter/... _and Selected", NULL, match_selected_plist_cb,
+ MATCH_SELECTED_AND|MATCH_SELECTED_APPLY_NOW, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Apply as Filter/... _or Selected", NULL, match_selected_plist_cb,
+ MATCH_SELECTED_OR|MATCH_SELECTED_APPLY_NOW, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Apply as Filter/... a_nd not Selected", NULL, match_selected_plist_cb,
+ MATCH_SELECTED_AND_NOT|MATCH_SELECTED_APPLY_NOW, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Apply as Filter/... o_r not Selected", NULL, match_selected_plist_cb,
+ MATCH_SELECTED_OR_NOT|MATCH_SELECTED_APPLY_NOW, NULL, NULL),
+
+ ITEM_FACTORY_ENTRY("/Prepare a Filter", NULL, NULL, 0, "<Branch>", NULL),
+ ITEM_FACTORY_ENTRY("/Prepare a Filter/_Selected", NULL, match_selected_plist_cb,
+ MATCH_SELECTED_REPLACE, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Prepare a Filter/_Not Selected", NULL, match_selected_plist_cb,
+ MATCH_SELECTED_NOT, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Prepare a Filter/... _and Selected", NULL, match_selected_plist_cb,
+ MATCH_SELECTED_AND, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Prepare a Filter/... _or Selected", NULL, match_selected_plist_cb,
+ MATCH_SELECTED_OR, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Prepare a Filter/... a_nd not Selected", NULL, match_selected_plist_cb,
+ MATCH_SELECTED_AND_NOT, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Prepare a Filter/... o_r not Selected", NULL, match_selected_plist_cb,
+ MATCH_SELECTED_OR_NOT, NULL, NULL),
+
+ ITEM_FACTORY_ENTRY("/<separator>", NULL, NULL, 0, "<Separator>", NULL),
+ ITEM_FACTORY_ENTRY("/Coloring Rules...", NULL, color_display_cb,
+ 0, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Print...", NULL, file_print_cmd_cb, 0, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Show Packet in New Window", NULL, new_window_cb,
+ 0, NULL, NULL),
+};
+
+static GtkItemFactoryEntry tree_view_menu_items[] =
+{
+ ITEM_FACTORY_ENTRY("/Follow TCP Stream", NULL, follow_stream_cb,
+ 0, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Decode As...", NULL, decode_as_cb, 0, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Display Filters...", NULL, dfilter_dialog_cb,
+ 0, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/<separator>", NULL, NULL, 0, "<Separator>", NULL),
+ ITEM_FACTORY_ENTRY("/_Resolve Name", NULL, resolve_name_cb, 0, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/_Go to Corresponding Packet", NULL, goto_framenum_cb, 0, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/_Export Selected Packet Bytes...", NULL, savehex_cb,
+ 0, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Protocol Preferences...", NULL, properties_cb,
+ 0, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Apply as Filter", NULL, NULL, 0, "<Branch>", NULL),
+ ITEM_FACTORY_ENTRY("/Apply as Filter/_Selected", NULL, match_selected_ptree_cb,
+ MATCH_SELECTED_REPLACE|MATCH_SELECTED_APPLY_NOW, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Apply as Filter/_Not Selected", NULL, match_selected_ptree_cb,
+ MATCH_SELECTED_NOT|MATCH_SELECTED_APPLY_NOW, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Apply as Filter/... _and Selected", NULL, match_selected_ptree_cb,
+ MATCH_SELECTED_AND|MATCH_SELECTED_APPLY_NOW, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Apply as Filter/... _or Selected", NULL, match_selected_ptree_cb,
+ MATCH_SELECTED_OR|MATCH_SELECTED_APPLY_NOW, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Apply as Filter/... a_nd not Selected", NULL, match_selected_ptree_cb,
+ MATCH_SELECTED_AND_NOT|MATCH_SELECTED_APPLY_NOW, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Apply as Filter/... o_r not Selected", NULL, match_selected_ptree_cb,
+ MATCH_SELECTED_OR_NOT|MATCH_SELECTED_APPLY_NOW, NULL, NULL),
+
+ ITEM_FACTORY_ENTRY("/Prepare a Filter", NULL, NULL, 0, "<Branch>", NULL),
+ ITEM_FACTORY_ENTRY("/Prepare a Filter/_Selected", NULL, match_selected_ptree_cb,
+ MATCH_SELECTED_REPLACE, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Prepare a Filter/_Not Selected", NULL, match_selected_ptree_cb,
+ MATCH_SELECTED_NOT, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Prepare a Filter/... _and Selected", NULL, match_selected_ptree_cb,
+ MATCH_SELECTED_AND, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Prepare a Filter/... _or Selected", NULL, match_selected_ptree_cb,
+ MATCH_SELECTED_OR, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Prepare a Filter/... a_nd not Selected", NULL, match_selected_ptree_cb,
+ MATCH_SELECTED_AND_NOT, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Prepare a Filter/... o_r not Selected", NULL, match_selected_ptree_cb,
+ MATCH_SELECTED_OR_NOT, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/<separator>", NULL, NULL, 0, "<Separator>", NULL),
+ ITEM_FACTORY_ENTRY("/Collapse All", NULL, collapse_all_cb, 0, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Expand All", NULL, expand_all_cb, 0, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Expand Tree", NULL, expand_tree_cb, 0, NULL, NULL)
+};
+
+static GtkItemFactoryEntry hexdump_menu_items[] =
+{
+ ITEM_FACTORY_ENTRY("/Follow TCP Stream", NULL, follow_stream_cb,
+ 0, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Decode As...", NULL, decode_as_cb, 0, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Display Filters...", NULL, dfilter_dialog_cb,
+ 0, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Export Selected Packet Bytes...", NULL, savehex_cb,
+ 0, NULL, NULL)
+};
+
+static int initialize = TRUE;
+static GtkItemFactory *main_menu_factory = NULL;
+static GtkItemFactory *packet_list_menu_factory = NULL;
+static GtkItemFactory *tree_view_menu_factory = NULL;
+static GtkItemFactory *hexdump_menu_factory = NULL;
+
+static GSList *popup_menu_list = NULL;
+
+static GtkAccelGroup *grp;
+
+GtkWidget *
+main_menu_new(GtkAccelGroup ** table) {
+ GtkWidget *menubar;
+
+ grp = gtk_accel_group_new();
+
+ if (initialize)
+ menus_init();
+
+ menubar = main_menu_factory->widget;
+
+ if (table)
+ *table = grp;
+
+ return menubar;
+}
+
+static void
+menus_init(void) {
+ if (initialize) {
+ initialize = FALSE;
+
+ /* popup */
+ packet_list_menu_factory = gtk_item_factory_new(GTK_TYPE_MENU, "<main>", NULL);
+ popup_menu_object = gtk_menu_new();
+ gtk_item_factory_create_items_ac(packet_list_menu_factory, sizeof(packet_list_menu_items)/sizeof(packet_list_menu_items[0]), packet_list_menu_items, popup_menu_object, 2);
+ OBJECT_SET_DATA(popup_menu_object, PM_PACKET_LIST_KEY,
+ packet_list_menu_factory->widget);
+ popup_menu_list = g_slist_append((GSList *)popup_menu_list, packet_list_menu_factory);
+
+ tree_view_menu_factory = gtk_item_factory_new(GTK_TYPE_MENU, "<main>", NULL);
+ gtk_item_factory_create_items_ac(tree_view_menu_factory, sizeof(tree_view_menu_items)/sizeof(tree_view_menu_items[0]), tree_view_menu_items, popup_menu_object, 2);
+ OBJECT_SET_DATA(popup_menu_object, PM_TREE_VIEW_KEY,
+ tree_view_menu_factory->widget);
+ popup_menu_list = g_slist_append((GSList *)popup_menu_list, tree_view_menu_factory);
+
+ hexdump_menu_factory = gtk_item_factory_new(GTK_TYPE_MENU, "<main>", NULL);
+ gtk_item_factory_create_items_ac(hexdump_menu_factory, sizeof(hexdump_menu_items)/sizeof(hexdump_menu_items[0]), hexdump_menu_items, popup_menu_object, 2);
+ OBJECT_SET_DATA(popup_menu_object, PM_HEXDUMP_KEY,
+ hexdump_menu_factory->widget);
+ popup_menu_list = g_slist_append((GSList *)popup_menu_list, hexdump_menu_factory);
+
+ /* main */
+ main_menu_factory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<main>", grp);
+ gtk_item_factory_create_items_ac(main_menu_factory, nmenu_items, menu_items, NULL, 2);
+
+ merge_all_tap_menus(tap_menu_tree_root);
+
+ /* Initialize enabled/disabled state of menu items */
+ set_menus_for_unsaved_capture_file(FALSE);
+ set_menus_for_capture_file(FALSE);
+#if 0
+ /* Un-#if this when we actually implement Cut/Copy/Paste.
+ Then make sure you enable them when they can be done. */
+ set_menu_sensitivity(main_menu_factory, "/Edit/Cut", FALSE);
+ set_menu_sensitivity(main_menu_factory, "/Edit/Copy", FALSE);
+ set_menu_sensitivity(main_menu_factory, "/Edit/Paste", FALSE);
+#endif
+
+ set_menus_for_captured_packets(FALSE);
+ set_menus_for_selected_packet(&cfile);
+ set_menus_for_selected_tree_row(&cfile);
+
+ /* init with an empty recent files list */
+ clear_menu_recent_capture_file_cmd_cb(NULL, NULL);
+ }
+}
+
+
+gint tap_menu_item_add_compare(gconstpointer a, gconstpointer b)
+{
+ return strcmp(
+ ((const menu_item_t *) a)->name,
+ ((const menu_item_t *) b)->name);
+}
+
+
+/* add a menuitem below the current node */
+GList * tap_menu_item_add(
+ char *name,
+ gint group,
+ GtkItemFactoryCallback callback,
+ gboolean (*selected_packet_enabled)(frame_data *, epan_dissect_t *),
+ gboolean (*selected_tree_row_enabled)(field_info *),
+ gpointer callback_data,
+ GList *curnode)
+{
+ menu_item_t *curr;
+ menu_item_t *child;
+
+
+ child = g_malloc(sizeof (menu_item_t));
+ child->group = group;
+ child->name = name;
+ child->callback = callback;
+ child->selected_packet_enabled = selected_packet_enabled;
+ child->selected_tree_row_enabled = selected_tree_row_enabled;
+ child->callback_data = callback_data;
+ child->enabled = FALSE;
+ child->children = NULL;
+
+ /* insert the new child node into the parent */
+ curr = curnode->data;
+ curr->children = g_list_insert_sorted(curr->children, child, tap_menu_item_add_compare);
+
+ /* return the new node */
+ /* XXX: improve this */
+ return g_list_find(curr->children, child);
+}
+
+/*
+ * Add a new menu item for a tap.
+ * This must be called after we've created the main menu, so it can't
+ * be called from the routine that registers taps - we have to introduce
+ * another per-tap registration routine.
+ *
+ * "callback" gets called when the menu item is selected; it should do
+ * the work of creating the tap window.
+ *
+ * "selected_packet_enabled" gets called by "set_menus_for_selected_packet()";
+ * it's passed a Boolean that's TRUE if a packet is selected and FALSE
+ * otherwise, and should return TRUE if the tap will work now (which
+ * might depend on whether a packet is selected and, if one is, on the
+ * packet) and FALSE if not.
+ *
+ * "selected_tree_row_enabled" gets called by
+ * "set_menus_for_selected_tree_row()"; it's passed a Boolean that's TRUE if
+ * a protocol tree row is selected and FALSE otherwise, and should return
+ * TRUE if the tap will work now (which might depend on whether a tree row
+ * is selected and, if one is, on the tree row) and FALSE if not.
+ */
+void
+register_tap_menu_item(
+ char *name,
+ REGISTER_TAP_GROUP_E group,
+ GtkItemFactoryCallback callback,
+ gboolean (*selected_packet_enabled)(frame_data *, epan_dissect_t *),
+ gboolean (*selected_tree_row_enabled)(field_info *),
+ gpointer callback_data)
+{
+ /*static const char toolspath[] = "/Statistics/";*/
+ char *toolspath;
+ char *p;
+ char *menupath;
+ size_t menupathlen;
+ menu_item_t *child;
+ GList *curnode;
+ GList *childnode;
+
+ /*
+ * The menu path must be relative.
+ */
+ g_assert(*name != '/');
+
+ switch(group) {
+ case(REGISTER_TAP_GROUP_GENERIC): toolspath = "/Statistics/"; break;
+ case(REGISTER_TAP_GROUP_CONVERSATION_LIST): toolspath = "/Statistics/_Conversation List/"; break;
+ case(REGISTER_TAP_GROUP_ENDPOINT_LIST): toolspath = "/Statistics/_Endpoint List/"; break;
+ case(REGISTER_TAP_GROUP_RESPONSE_TIME): toolspath = "/Statistics/Service _Response Time/"; break;
+ case(REGISTER_TAP_GROUP_NONE): toolspath = "/Statistics/"; break;
+ default:
+ g_assert(0);
+ toolspath = NULL;
+ }
+
+ /* add the (empty) root node, if not already done */
+ if(tap_menu_tree_root == NULL) {
+ child = g_malloc0(sizeof (menu_item_t));
+ tap_menu_tree_root = g_list_append(NULL, child);
+ }
+
+ /*
+ * Create any submenus required.
+ */
+ curnode = tap_menu_tree_root;
+ p = name;
+ while ((p = strchr(p, '/')) != NULL) {
+ /*
+ * OK, everything between "name" and "p" is
+ * a menu relative subtree into which the menu item
+ * will be placed.
+ *
+ * Construct the absolute path name of that subtree.
+ */
+ menupathlen = strlen(toolspath) + 1 + (p - name);
+ menupath = g_malloc(menupathlen);
+ strcpy(menupath, toolspath);
+ strncat(menupath, name, p - name);
+
+ /*
+ * Does there exist an entry with that path at this
+ * level of the Analyze menu tree?
+ */
+ child = curnode->data;
+ for (childnode = child->children; childnode != NULL; childnode = childnode->next) {
+ child = childnode->data;
+ if (strcmp(child->name, menupath) == 0)
+ break;
+ }
+ if (childnode == NULL) {
+ /*
+ * No. Create such an item as a subtree, and
+ * add it to the Tools menu tree.
+ */
+ childnode = tap_menu_item_add(
+ menupath, group, NULL, NULL ,NULL, NULL, curnode);
+ } else {
+ /*
+ * Yes. We don't need this "menupath" any longer.
+ */
+ g_free(menupath);
+ }
+ curnode = childnode;
+
+ /*
+ * Skip over the '/' we found.
+ */
+ p++;
+ }
+
+ /*
+ * Construct the main menu path for the menu item.
+ */
+ menupathlen = strlen(toolspath) + 1 + strlen(name);
+ menupath = g_malloc(menupathlen);
+ strcpy(menupath, toolspath);
+ strcat(menupath, name);
+
+ /*
+ * Construct an item factory entry for the item, and add it to
+ * the main menu.
+ */
+ tap_menu_item_add(
+ menupath, group, callback,
+ selected_packet_enabled, selected_tree_row_enabled,
+ callback_data, curnode);
+}
+
+
+guint merge_tap_menus_layered(GList *node, gint group) {
+ GtkItemFactoryEntry *entry;
+ GList *child;
+ guint added = 0;
+ menu_item_t *node_data = node->data;
+
+ /*
+ * Is this a leaf node or an interior node?
+ */
+ if (node_data->children == NULL) {
+ /*
+ * It's a leaf node.
+ */
+
+ /*
+ * The root node doesn't correspond to a menu tree item; it
+ * has a null name pointer.
+ */
+ if (node_data->name != NULL && group == node_data->group) {
+ entry = g_malloc0(sizeof (GtkItemFactoryEntry));
+ entry->path = node_data->name;
+ entry->callback = node_data->callback;
+ gtk_item_factory_create_item(main_menu_factory, entry, node_data->callback_data, 2);
+ set_menu_sensitivity(main_menu_factory, node_data->name, FALSE); /* no capture file yet */
+ added++;
+ }
+ } else {
+ /*
+ * It's an interior node; call
+ * "merge_tap_menus_layered()" on all its children
+ */
+
+ /*
+ * The root node doesn't correspond to a menu tree item; it
+ * has a null name pointer.
+ */
+ if (node_data->name != NULL && group == node_data->group) {
+ entry = g_malloc0(sizeof (GtkItemFactoryEntry));
+ entry->path = node_data->name;
+ entry->item_type = "<Branch>";
+ gtk_item_factory_create_item(main_menu_factory, entry,
+ NULL, 2);
+ set_menu_sensitivity(main_menu_factory, node_data->name,
+ FALSE); /* no children yet */
+ added++;
+ }
+
+ for (child = node_data->children; child != NULL; child =
+ child->next) {
+ added += merge_tap_menus_layered(child, group);
+ }
+ }
+
+ return added;
+}
+
+
+void merge_all_tap_menus(GList *node) {
+ GtkItemFactoryEntry *entry;
+
+ entry = g_malloc0(sizeof (GtkItemFactoryEntry));
+ entry->item_type = "<Separator>";
+ entry->path = "/Statistics/";
+
+ /*
+ * merge only the menu items of the specific group,
+ * and then append a seperator
+ */
+ if (merge_tap_menus_layered(node, REGISTER_TAP_GROUP_GENERIC)) {
+ gtk_item_factory_create_item(main_menu_factory, entry, NULL, 2);
+ }
+ if (merge_tap_menus_layered(node, REGISTER_TAP_GROUP_CONVERSATION_LIST)) {
+ /*gtk_item_factory_create_item(main_menu_factory, entry, NULL, 2);*/
+ }
+ if (merge_tap_menus_layered(node, REGISTER_TAP_GROUP_ENDPOINT_LIST)) {
+ /*gtk_item_factory_create_item(main_menu_factory, entry, NULL, 2);*/
+ }
+ if (merge_tap_menus_layered(node, REGISTER_TAP_GROUP_RESPONSE_TIME)) {
+ gtk_item_factory_create_item(main_menu_factory, entry, NULL, 2);
+ }
+ if (merge_tap_menus_layered(node, REGISTER_TAP_GROUP_NONE)) {
+ /*gtk_item_factory_create_item(main_menu_factory, entry, NULL, 2);*/
+ }
+}
+
+
+
+/*
+ * Enable/disable menu sensitivity.
+ */
+static void
+set_menu_sensitivity(GtkItemFactory *ifactory, const gchar *path, gint val)
+{
+ GSList *menu_list;
+ GtkWidget *menu_item;
+ gchar *dup;
+ gchar *dest;
+
+
+ /* the underscore character regularly confuses things, as it will prevent finding
+ * the menu_item, so it has to be removed first */
+ dup = g_strdup(path);
+ dest = dup;
+ while(*path) {
+ if (*path != '_') {
+ *dest = *path;
+ dest++;
+ }
+ path++;
+ }
+ *dest = '\0';
+
+ if (ifactory == NULL) {
+ /*
+ * Do it for all pop-up menus.
+ */
+ for (menu_list = popup_menu_list; menu_list != NULL;
+ menu_list = g_slist_next(menu_list))
+ set_menu_sensitivity(menu_list->data, dup, val);
+ } else {
+ /*
+ * Do it for that particular menu.
+ */
+ if ((menu_item = gtk_item_factory_get_widget(ifactory, dup)) != NULL) {
+ if (GTK_IS_MENU(menu_item)) {
+ /*
+ * "dup" refers to a submenu; "gtk_item_factory_get_widget()"
+ * gets the menu, not the item that, when selected, pops up
+ * the submenu.
+ *
+ * We have to change the latter item's sensitivity, so that
+ * it shows up normally if sensitive and grayed-out if
+ * insensitive.
+ */
+ menu_item = gtk_menu_get_attach_widget(GTK_MENU(menu_item));
+ }
+ gtk_widget_set_sensitive(menu_item, val);
+ } else{
+ /* be sure this menu item *is* existing */
+ g_assert_not_reached();
+ }
+ }
+
+ g_free(dup);
+}
+
+void
+set_menu_object_data_meat(GtkItemFactory *ifactory, gchar *path, gchar *key, gpointer data)
+{
+ GtkWidget *menu = NULL;
+
+ if ((menu = gtk_item_factory_get_widget(ifactory, path)) != NULL)
+ OBJECT_SET_DATA(menu, key, data);
+}
+
+void
+set_menu_object_data (gchar *path, gchar *key, gpointer data) {
+ GSList *menu_list = popup_menu_list;
+ gchar *shortpath = strrchr(path, '/');
+
+ set_menu_object_data_meat(main_menu_factory, path, key, data);
+ while (menu_list != NULL) {
+ set_menu_object_data_meat(menu_list->data, shortpath, key, data);
+ menu_list = g_slist_next(menu_list);
+ }
+}
+
+
+/* Recently used capture files submenu:
+ * Submenu containing the recently used capture files.
+ * The capture filenames are always kept with the absolute path, to be independant
+ * of the current path.
+ * They are only stored inside the labels of the submenu (no separate list). */
+
+#define MENU_RECENT_FILES_PATH "/File/Open Recent"
+#define MENU_RECENT_FILES_KEY "Recent File Name"
+
+void
+update_menu_recent_capture_file1(GtkWidget *widget, gpointer cnt) {
+ gchar *widget_cf_name;
+
+ widget_cf_name = OBJECT_GET_DATA(widget, MENU_RECENT_FILES_KEY);
+
+ /* if this menu item is a file, count it */
+ if (widget_cf_name) {
+ (*(guint *)cnt)++;
+ }
+}
+
+
+/* update the menu */
+void
+update_menu_recent_capture_file(GtkWidget *submenu_recent_files) {
+ guint cnt = 0;
+
+ gtk_container_foreach(GTK_CONTAINER(submenu_recent_files),
+ update_menu_recent_capture_file1, &cnt);
+
+ /* make parent menu item sensitive only, if we have any valid files in the list */
+ set_menu_sensitivity(main_menu_factory, MENU_RECENT_FILES_PATH, cnt);
+}
+
+
+/* remove the capture filename from the "Recent Files" menu */
+void
+remove_menu_recent_capture_file(GtkWidget *widget, gpointer unused _U_) {
+ GtkWidget *submenu_recent_files;
+ gchar *widget_cf_name;
+
+
+ widget_cf_name = OBJECT_GET_DATA(widget, MENU_RECENT_FILES_KEY);
+ g_free(widget_cf_name);
+
+ /* get the submenu container item */
+ submenu_recent_files = gtk_item_factory_get_widget(main_menu_factory, MENU_RECENT_FILES_PATH);
+
+ /* XXX: is this all we need to do, to free the menu item and its label?
+ The reference count of widget will go to 0, so it'll be freed;
+ will that free the label? */
+ gtk_container_remove(GTK_CONTAINER(submenu_recent_files), widget);
+}
+
+
+/* callback, if the user pushed the <Clear File List> item */
+static void
+clear_menu_recent_capture_file_cmd_cb(GtkWidget *w _U_, gpointer unused _U_) {
+ GtkWidget *submenu_recent_files;
+
+
+ submenu_recent_files = gtk_item_factory_get_widget(main_menu_factory, MENU_RECENT_FILES_PATH);
+
+ gtk_container_foreach(GTK_CONTAINER(submenu_recent_files),
+ remove_menu_recent_capture_file, NULL);
+
+ update_menu_recent_capture_file(submenu_recent_files);
+}
+
+
+/* callback, if the user pushed a recent file submenu item */
+void
+menu_open_recent_file_cmd(GtkWidget *w)
+{
+ GtkWidget *submenu_recent_files;
+ GtkWidget *menu_item_child;
+ gchar *cf_name;
+ int err;
+
+ submenu_recent_files = gtk_item_factory_get_widget(main_menu_factory, MENU_RECENT_FILES_PATH);
+
+ /* get capture filename from the menu item label */
+ menu_item_child = (GTK_BIN(w))->child;
+ gtk_label_get(GTK_LABEL(menu_item_child), &cf_name);
+
+ /* open and read the capture file (this will close an existing file) */
+ if ((err = cf_open(cf_name, FALSE, &cfile)) == 0) {
+ cf_read(&cfile);
+ } else {
+ /* the capture file isn't existing any longer, remove menu item */
+ /* XXX: ask user to remove item, it's maybe only a temporary problem */
+ remove_menu_recent_capture_file(w, NULL);
+ }
+
+ update_menu_recent_capture_file(submenu_recent_files);
+}
+
+static void menu_open_recent_file_answered_cb(gpointer dialog _U_, gint btn, gpointer data _U_)
+{
+ switch(btn) {
+ case(ESD_BTN_YES):
+ /* save file first */
+ file_save_as_cmd(after_save_open_recent_file, data);
+ break;
+ case(ESD_BTN_NO):
+ cf_close(&cfile);
+ menu_open_recent_file_cmd(data);
+ break;
+ case(ESD_BTN_CANCEL):
+ break;
+ default:
+ g_assert_not_reached();
+ }
+}
+
+void
+menu_open_recent_file_cmd_cb(GtkWidget *widget, gpointer data _U_) {
+ gpointer dialog;
+
+
+ if((cfile.state != FILE_CLOSED) && !cfile.user_saved && prefs.gui_ask_unsaved) {
+ /* user didn't saved his current file, ask him */
+ dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_YES_NO_CANCEL,
+ PRIMARY_TEXT_START "Save capture file before opening a new one?" PRIMARY_TEXT_END "\n\n"
+ "If you open a new capture file without saving, your current capture data will be discarded.");
+ simple_dialog_set_cb(dialog, menu_open_recent_file_answered_cb, widget);
+ } else {
+ /* unchanged file */
+ menu_open_recent_file_cmd(widget);
+ }
+}
+
+/* add the capture filename (with an absolute path) to the "Recent Files" menu */
+void
+add_menu_recent_capture_file_absolute(gchar *cf_name) {
+ GtkWidget *submenu_recent_files;
+ GList *menu_item_list;
+ GList *li;
+ gchar *widget_cf_name;
+ gchar *normalized_cf_name;
+ GtkWidget *menu_item;
+ guint cnt;
+
+
+
+ normalized_cf_name = g_strdup(cf_name);
+#ifdef WIN32
+ /* replace all slashes by backslashes */
+ g_strdelimit(normalized_cf_name, "/", '\\');
+#endif
+
+ /* get the submenu container item */
+ submenu_recent_files = gtk_item_factory_get_widget(main_menu_factory, MENU_RECENT_FILES_PATH);
+
+ /* convert container to a GList */
+ menu_item_list = gtk_container_children(GTK_CONTAINER(submenu_recent_files));
+
+ /* iterate through list items of menu_item_list,
+ * removing special items, a maybe duplicate entry and every item above count_max */
+ cnt = 1;
+ for (li = g_list_first(menu_item_list); li; li = li->next, cnt++) {
+ /* get capture filename */
+ menu_item = GTK_WIDGET(li->data);
+ widget_cf_name = OBJECT_GET_DATA(menu_item, MENU_RECENT_FILES_KEY);
+
+ /* if this element string is one of our special items (seperator, ...) or
+ * already in the list or
+ * this element is above maximum count (too old), remove it */
+ if (!widget_cf_name ||
+#ifdef WIN32
+ /* do a case insensitive compare on win32 */
+#if GLIB_MAJOR_VERSION < 2
+ g_strncasecmp(widget_cf_name, normalized_cf_name, 1000) == 0 ||
+#else
+ g_ascii_strncasecmp(widget_cf_name, normalized_cf_name, 1000) == 0 ||
+#endif
+#else /* WIN32 */
+ /* do a case sensitive compare on unix */
+ strncmp(widget_cf_name, normalized_cf_name, 1000) == 0 ||
+#endif
+ cnt >= prefs.gui_recent_files_count_max) {
+ remove_menu_recent_capture_file(li->data, NULL);
+ cnt--;
+ }
+ }
+
+ g_list_free(menu_item_list);
+
+ /* add new item at latest position */
+ menu_item = gtk_menu_item_new_with_label(normalized_cf_name);
+ OBJECT_SET_DATA(menu_item, MENU_RECENT_FILES_KEY, normalized_cf_name);
+ gtk_menu_prepend (GTK_MENU(submenu_recent_files), menu_item);
+ SIGNAL_CONNECT_OBJECT(GTK_OBJECT(menu_item), "activate",
+ menu_open_recent_file_cmd_cb, (GtkObject *) menu_item);
+ gtk_widget_show (menu_item);
+
+ /* add seperator at last position */
+ menu_item = gtk_menu_item_new();
+ gtk_menu_append (GTK_MENU(submenu_recent_files), menu_item);
+ gtk_widget_show (menu_item);
+
+ /* add new "clear list" item at last position */
+#if GTK_MAJOR_VERSION < 2
+ menu_item = gtk_menu_item_new_with_label("<Clear File List>");
+#else
+ menu_item = gtk_image_menu_item_new_from_stock(GTK_STOCK_CLEAR, NULL);
+#endif
+ gtk_menu_append (GTK_MENU(submenu_recent_files), menu_item);
+ SIGNAL_CONNECT_OBJECT(GTK_OBJECT(menu_item), "activate",
+ clear_menu_recent_capture_file_cmd_cb, (GtkObject *) menu_item);
+ gtk_widget_show (menu_item);
+
+ update_menu_recent_capture_file(submenu_recent_files);
+}
+
+
+/* add the capture filename to the "Recent Files" menu */
+/* (will change nothing, if this filename is already in the menu) */
+void
+add_menu_recent_capture_file(gchar *cf_name) {
+ gchar *curr;
+ gchar *absolute;
+
+
+ /* if this filename is an absolute path, we can use it directly */
+ if (g_path_is_absolute(cf_name)) {
+ add_menu_recent_capture_file_absolute(cf_name);
+ return;
+ }
+
+ /* this filename is not an absolute path, prepend the current dir */
+ curr = g_get_current_dir();
+ absolute = g_strdup_printf("%s%s%s", curr, G_DIR_SEPARATOR_S, cf_name);
+ add_menu_recent_capture_file_absolute(absolute);
+ g_free(curr);
+ g_free(absolute);
+}
+
+
+/* write all capture filenames of the menu to the user's recent file */
+void
+menu_recent_file_write_all(FILE *rf) {
+ GtkWidget *submenu_recent_files;
+ GList *children;
+ GList *child;
+ gchar *cf_name;
+
+
+ submenu_recent_files = gtk_item_factory_get_widget(main_menu_factory, MENU_RECENT_FILES_PATH);
+
+ /* we have to iterate backwards through the children's list,
+ * so we get the latest item last in the file.
+ * (don't use gtk_container_foreach() here, it will return the wrong iteration order) */
+ children = gtk_container_children(GTK_CONTAINER(submenu_recent_files));
+ child = g_list_last(children);
+ while(child != NULL) {
+ /* get capture filename from the menu item label */
+ cf_name = OBJECT_GET_DATA(child->data, MENU_RECENT_FILES_KEY);
+ if (cf_name) {
+ fprintf (rf, RECENT_KEY_CAPTURE_FILE ": %s\n", cf_name);
+ }
+
+ child = g_list_previous(child);
+ }
+
+ g_list_free(children);
+}
+
+
+static void
+main_toolbar_show_cb(GtkWidget *w _U_, gpointer d _U_)
+{
+
+ /* save current setting in recent */
+ recent.main_toolbar_show = GTK_CHECK_MENU_ITEM(w)->active;
+
+ main_widgets_show_or_hide();
+}
+
+
+static void
+filter_toolbar_show_cb(GtkWidget *w _U_, gpointer d _U_)
+{
+
+ /* save current setting in recent */
+ recent.filter_toolbar_show = GTK_CHECK_MENU_ITEM(w)->active;
+
+ main_widgets_show_or_hide();
+}
+
+
+static void
+packet_list_show_cb(GtkWidget *w _U_, gpointer d _U_)
+{
+
+ /* save current setting in recent */
+ recent.packet_list_show = GTK_CHECK_MENU_ITEM(w)->active;
+
+ main_widgets_show_or_hide();
+}
+
+
+static void
+tree_view_show_cb(GtkWidget *w _U_, gpointer d _U_)
+{
+
+ /* save current setting in recent */
+ recent.tree_view_show = GTK_CHECK_MENU_ITEM(w)->active;
+
+ main_widgets_show_or_hide();
+}
+
+
+static void
+byte_view_show_cb(GtkWidget *w _U_, gpointer d _U_)
+{
+
+ /* save current setting in recent */
+ recent.byte_view_show = GTK_CHECK_MENU_ITEM(w)->active;
+
+ main_widgets_show_or_hide();
+}
+
+
+static void
+statusbar_show_cb(GtkWidget *w _U_, gpointer d _U_)
+{
+
+ /* save current setting in recent */
+ recent.statusbar_show = GTK_CHECK_MENU_ITEM(w)->active;
+
+ main_widgets_show_or_hide();
+}
+
+
+static void
+timestamp_absolute_cb(GtkWidget *w _U_, gpointer d _U_)
+{
+ if (recent.gui_time_format != TS_ABSOLUTE) {
+ set_timestamp_setting(TS_ABSOLUTE);
+ recent.gui_time_format = TS_ABSOLUTE;
+ change_time_formats(&cfile);
+ }
+}
+
+static void
+timestamp_absolute_date_cb(GtkWidget *w _U_, gpointer d _U_)
+{
+ if (recent.gui_time_format != TS_ABSOLUTE_WITH_DATE) {
+ set_timestamp_setting(TS_ABSOLUTE_WITH_DATE);
+ recent.gui_time_format = TS_ABSOLUTE_WITH_DATE;
+ change_time_formats(&cfile);
+ }
+}
+
+static void
+timestamp_relative_cb(GtkWidget *w _U_, gpointer d _U_)
+{
+ if (recent.gui_time_format != TS_RELATIVE) {
+ set_timestamp_setting(TS_RELATIVE);
+ recent.gui_time_format = TS_RELATIVE;
+ change_time_formats(&cfile);
+ }
+}
+
+static void
+timestamp_delta_cb(GtkWidget *w _U_, gpointer d _U_)
+{
+ if (recent.gui_time_format != TS_DELTA) {
+ set_timestamp_setting(TS_DELTA);
+ recent.gui_time_format = TS_DELTA;
+ change_time_formats(&cfile);
+ }
+}
+
+void
+menu_name_resolution_changed(void)
+{
+ GtkWidget *menu = NULL;
+
+ menu = gtk_item_factory_get_widget(main_menu_factory, "/View/Name Resolution/Enable for MAC Layer");
+ gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), g_resolv_flags & RESOLV_MAC);
+
+ menu = gtk_item_factory_get_widget(main_menu_factory, "/View/Name Resolution/Enable for Network Layer");
+ gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), g_resolv_flags & RESOLV_NETWORK);
+
+ menu = gtk_item_factory_get_widget(main_menu_factory, "/View/Name Resolution/Enable for Transport Layer");
+ gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), g_resolv_flags & RESOLV_TRANSPORT);
+}
+
+static void
+name_resolution_mac_cb(GtkWidget *w _U_, gpointer d _U_)
+{
+ if (GTK_CHECK_MENU_ITEM(w)->active) {
+ g_resolv_flags |= RESOLV_MAC;
+ } else {
+ g_resolv_flags &= ~RESOLV_MAC;
+ }
+}
+
+static void
+name_resolution_network_cb(GtkWidget *w _U_, gpointer d _U_)
+{
+ if (GTK_CHECK_MENU_ITEM(w)->active) {
+ g_resolv_flags |= RESOLV_NETWORK;
+ } else {
+ g_resolv_flags &= ~RESOLV_NETWORK;
+ }
+}
+
+static void
+name_resolution_transport_cb(GtkWidget *w _U_, gpointer d _U_)
+{
+ if (GTK_CHECK_MENU_ITEM(w)->active) {
+ g_resolv_flags |= RESOLV_TRANSPORT;
+ } else {
+ g_resolv_flags &= ~RESOLV_TRANSPORT;
+ }
+}
+
+#ifdef HAVE_LIBPCAP
+static void
+auto_scroll_live_cb(GtkWidget *w _U_, gpointer d _U_)
+{
+ auto_scroll_live = GTK_CHECK_MENU_ITEM(w)->active;
+}
+#endif
+
+/* the recent file read has finished, update the menu corresponding */
+void
+menu_recent_read_finished(void) {
+ GtkWidget *menu = NULL;
+
+ menu = gtk_item_factory_get_widget(main_menu_factory, "/View/Main Toolbar");
+ gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), recent.main_toolbar_show);
+
+ menu = gtk_item_factory_get_widget(main_menu_factory, "/View/Filter Toolbar");
+ gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), recent.filter_toolbar_show);
+
+ menu = gtk_item_factory_get_widget(main_menu_factory, "/View/Statusbar");
+ gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), recent.statusbar_show);
+
+ menu = gtk_item_factory_get_widget(main_menu_factory, "/View/Packet List");
+ gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), recent.packet_list_show);
+
+ menu = gtk_item_factory_get_widget(main_menu_factory, "/View/Packet Details");
+ gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), recent.tree_view_show);
+
+ menu = gtk_item_factory_get_widget(main_menu_factory, "/View/Packet Bytes");
+ gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), recent.byte_view_show);
+
+ menu_name_resolution_changed();
+
+#ifdef HAVE_LIBPCAP
+ menu = gtk_item_factory_get_widget(main_menu_factory, "/View/Auto Scroll in Live Capture");
+ gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), auto_scroll_live);
+#endif
+
+ main_widgets_rearrange();
+
+ /* don't change the time format, if we had a command line value */
+ if (get_timestamp_setting() != TS_NOT_SET) {
+ recent.gui_time_format = get_timestamp_setting();
+ }
+
+ switch(recent.gui_time_format) {
+ case(TS_ABSOLUTE):
+ menu = gtk_item_factory_get_widget(main_menu_factory,
+ "/View/Time Display Format/Time of Day");
+ /* set_active will not trigger the callback when activating an active item! */
+ recent.gui_time_format = -1;
+ gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), FALSE);
+ gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), TRUE);
+ break;
+ case(TS_ABSOLUTE_WITH_DATE):
+ menu = gtk_item_factory_get_widget(main_menu_factory,
+ "/View/Time Display Format/Date and Time of Day");
+ recent.gui_time_format = -1;
+ gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), TRUE);
+ break;
+ case(TS_RELATIVE):
+ menu = gtk_item_factory_get_widget(main_menu_factory,
+ "/View/Time Display Format/Seconds Since Beginning of Capture");
+ recent.gui_time_format = -1;
+ gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), TRUE);
+ break;
+ case(TS_DELTA):
+ menu = gtk_item_factory_get_widget(main_menu_factory,
+ "/View/Time Display Format/Seconds Since Previous Packet");
+ recent.gui_time_format = -1;
+ gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), TRUE);
+ break;
+ default:
+ g_assert_not_reached();
+ }
+}
+
+
+gint
+popup_menu_handler(GtkWidget *widget, GdkEvent *event, gpointer data)
+{
+ GtkWidget *menu = (GtkWidget *)data;
+ GdkEventButton *event_button = NULL;
+ gint row, column;
+
+ if(widget == NULL || event == NULL || data == NULL) {
+ return FALSE;
+ }
+
+ /*
+ * If we ever want to make the menu differ based on what row
+ * and/or column we're above, we'd use "eth_clist_get_selection_info()"
+ * to find the row and column number for the coordinates; a CTree is,
+ * I guess, like a CList with one column(?) and the expander widget
+ * as a pixmap.
+ */
+ /* Check if we are on packet_list object */
+ if (widget == OBJECT_GET_DATA(popup_menu_object, E_MPACKET_LIST_KEY)) {
+ if (packet_list_get_event_row_column(widget, (GdkEventButton *)event,
+ &row, &column)) {
+ OBJECT_SET_DATA(popup_menu_object, E_MPACKET_LIST_ROW_KEY,
+ GINT_TO_POINTER(row));
+ OBJECT_SET_DATA(popup_menu_object, E_MPACKET_LIST_COL_KEY,
+ GINT_TO_POINTER(column));
+ packet_list_set_selected_row(row);
+ }
+ }
+
+ /* Check if we are on tree_view object */
+ if (widget == tree_view) {
+ tree_view_select(widget, (GdkEventButton *) event);
+ }
+
+ /* Check if we are on byte_view object */
+ if(widget == get_notebook_bv_ptr(byte_nb_ptr)) {
+ byte_view_select(widget, (GdkEventButton *) event);
+ }
+
+ /* context menu handler (but the byte view notebook pages have their own handler) */
+ if(event->type == GDK_BUTTON_PRESS && widget != byte_nb_ptr) {
+ event_button = (GdkEventButton *) event;
+
+ /* To qoute the "Gdk Event Structures" doc:
+ * "Normally button 1 is the left mouse button, 2 is the middle button, and 3 is the right button" */
+ if(event_button->button == 3) {
+ gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL,
+ event_button->button,
+ event_button->time);
+ SIGNAL_EMIT_STOP_BY_NAME(widget, "button_press_event");
+ return TRUE;
+ }
+ }
+#if GTK_MAJOR_VERSION >= 2
+ /* GDK_2BUTTON_PRESS is a doubleclick -> expand/collapse tree row */
+ /* GTK version 1 seems to be doing this automatically */
+ if (widget == tree_view && event->type == GDK_2BUTTON_PRESS) {
+ GtkTreePath *path;
+
+ if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget),
+ (gint) (((GdkEventButton *)event)->x),
+ (gint) (((GdkEventButton *)event)->y),
+ &path, NULL, NULL, NULL))
+ {
+ if (gtk_tree_view_row_expanded(GTK_TREE_VIEW(widget), path))
+ gtk_tree_view_collapse_row(GTK_TREE_VIEW(widget), path);
+ else
+ gtk_tree_view_expand_row(GTK_TREE_VIEW(widget), path,
+ FALSE);
+ gtk_tree_path_free(path);
+ }
+ }
+#endif
+ return FALSE;
+}
+
+/* Enable or disable menu items based on whether you have a capture file
+ you've finished reading. */
+void
+set_menus_for_capture_file(gboolean have_capture_file)
+{
+ set_menu_sensitivity(main_menu_factory, "/File/Open...", have_capture_file);
+ set_menu_sensitivity(main_menu_factory, "/File/Open Recent", have_capture_file);
+ set_menu_sensitivity(main_menu_factory, "/File/Merge...", have_capture_file);
+ set_menu_sensitivity(main_menu_factory, "/File/Close", have_capture_file);
+ set_menu_sensitivity(main_menu_factory, "/File/Save As...",
+ have_capture_file);
+ set_menu_sensitivity(main_menu_factory, "/File/Export", have_capture_file);
+ set_menu_sensitivity(main_menu_factory, "/View/Reload", have_capture_file);
+ set_toolbar_for_capture_file(have_capture_file);
+ packets_bar_update();
+}
+
+/* Enable or disable menu items based on whether you have an unsaved
+ capture file you've finished reading. */
+void
+set_menus_for_unsaved_capture_file(gboolean have_unsaved_capture_file)
+{
+ set_menu_sensitivity(main_menu_factory, "/File/Save",
+ have_unsaved_capture_file);
+ set_toolbar_for_unsaved_capture_file(have_unsaved_capture_file);
+}
+
+/* Enable or disable menu items based on whether there's a capture in
+ progress. */
+void
+set_menus_for_capture_in_progress(gboolean capture_in_progress)
+{
+ set_menu_sensitivity(main_menu_factory, "/File/Open...",
+ !capture_in_progress);
+ set_menu_sensitivity(main_menu_factory, "/File/Open Recent",
+ !capture_in_progress);
+#ifdef HAVE_LIBPCAP
+ set_menu_sensitivity(main_menu_factory, "/Capture/Start...",
+ !capture_in_progress);
+ set_menu_sensitivity(main_menu_factory, "/Capture/Stop",
+ capture_in_progress);
+#endif /* HAVE_LIBPCAP */
+ set_toolbar_for_capture_in_progress(capture_in_progress);
+
+ set_capture_if_dialog_for_capture_in_progress(capture_in_progress);
+}
+
+/* Enable or disable menu items based on whether you have some captured
+ packets. */
+static gboolean
+walk_menu_tree_for_captured_packets(GList *node,
+ gboolean have_captured_packets)
+{
+ gboolean is_enabled;
+ GList *child;
+ menu_item_t *node_data = node->data;
+
+ /*
+ * Is this a leaf node or an interior node?
+ */
+ if (node_data->children == NULL) {
+ /*
+ * It's a leaf node.
+ *
+ * If it has no "selected_packet_enabled()" or
+ * "selected_tree_row_enabled()" routines, we enable
+ * it. This allows tap windows to be popped up even
+ * if you have no capture file; this is done to let
+ * the user pop up multiple tap windows before reading
+ * in a capture file, so that they can be processed in
+ * parallel while the capture file is being read rather
+ * than one at at time as you pop up the windows, and to
+ * let the user pop up tap windows before starting an
+ * "Update list of packets in real time" capture, so that
+ * the statistics can be displayed while the capture is
+ * in progress.
+ *
+ * If it has either of those routines, we disable it for
+ * now - as long as, when a capture is first available,
+ * we don't get called after a packet or tree row is
+ * selected, that's OK.
+ * XXX - that should be done better.
+ */
+ if (node_data->selected_packet_enabled == NULL &&
+ node_data->selected_tree_row_enabled == NULL)
+ node_data->enabled = TRUE;
+ else
+ node_data->enabled = FALSE;
+ } else {
+ /*
+ * It's an interior node; call
+ * "walk_menu_tree_for_captured_packets()" on all its
+ * children and, if any of them are enabled, enable
+ * this node, otherwise disable it.
+ *
+ * XXX - should we just leave all interior nodes enabled?
+ * Which is a better UI choice?
+ */
+ is_enabled = FALSE;
+ for (child = node_data->children; child != NULL; child =
+ child->next) {
+ if (walk_menu_tree_for_captured_packets(child,
+ have_captured_packets))
+ is_enabled = TRUE;
+ }
+ node_data->enabled = is_enabled;
+ }
+
+ /*
+ * The root node doesn't correspond to a menu tree item; it
+ * has a null name pointer.
+ */
+ if (node_data->name != NULL) {
+ set_menu_sensitivity(main_menu_factory, node_data->name,
+ node_data->enabled);
+ }
+ return node_data->enabled;
+}
+
+void
+set_menus_for_captured_packets(gboolean have_captured_packets)
+{
+ set_menu_sensitivity(main_menu_factory, "/File/Print...",
+ have_captured_packets);
+ set_menu_sensitivity(packet_list_menu_factory, "/Print...",
+ have_captured_packets);
+ set_menu_sensitivity(main_menu_factory, "/Edit/Find Packet...",
+ have_captured_packets);
+ set_menu_sensitivity(main_menu_factory, "/Edit/Find Next",
+ have_captured_packets);
+ set_menu_sensitivity(main_menu_factory, "/Edit/Find Previous",
+ have_captured_packets);
+ set_menu_sensitivity(main_menu_factory, "/View/Zoom In",
+ have_captured_packets);
+ set_menu_sensitivity(main_menu_factory, "/View/Zoom Out",
+ have_captured_packets);
+ set_menu_sensitivity(main_menu_factory, "/View/Normal Size",
+ have_captured_packets);
+ set_menu_sensitivity(packet_list_menu_factory, "/Coloring Rules...",
+ have_captured_packets);
+ set_menu_sensitivity(main_menu_factory, "/Go/Go to Packet...",
+ have_captured_packets);
+ set_menu_sensitivity(main_menu_factory, "/Go/First Packet",
+ have_captured_packets);
+ set_menu_sensitivity(main_menu_factory, "/Go/Last Packet",
+ have_captured_packets);
+ set_menu_sensitivity(main_menu_factory, "/Statistics/Summary",
+ have_captured_packets);
+ set_menu_sensitivity(main_menu_factory, "/Statistics/Protocol Hierarchy",
+ have_captured_packets);
+
+ walk_menu_tree_for_captured_packets(tap_menu_tree_root,
+ have_captured_packets);
+ set_toolbar_for_captured_packets(have_captured_packets);
+ packets_bar_update();
+}
+
+/* Enable or disable menu items based on whether a packet is selected and,
+ if so, on the properties of the packet. */
+static gboolean
+walk_menu_tree_for_selected_packet(GList *node, frame_data *fd,
+ epan_dissect_t *edt)
+{
+ gboolean is_enabled;
+ GList *child;
+ menu_item_t *node_data = node->data;
+
+ /*
+ * Is this a leaf node or an interior node?
+ */
+ if (node_data->children == NULL) {
+ /*
+ * It's a leaf node.
+ *
+ * If it has no "selected_packet_enabled()" routine,
+ * leave its enabled/disabled status alone - it
+ * doesn't depend on whether we have a packet selected
+ * or not or on the selected packet.
+ *
+ * If it has a "selected_packet_enabled()" routine,
+ * call it and set the item's enabled/disabled status
+ * based on its return value.
+ */
+ if (node_data->selected_packet_enabled != NULL)
+ node_data->enabled = node_data->selected_packet_enabled(fd, edt);
+ } else {
+ /*
+ * It's an interior node; call
+ * "walk_menu_tree_for_selected_packet()" on all its
+ * children and, if any of them are enabled, enable
+ * this node, otherwise disable it.
+ *
+ * XXX - should we just leave all interior nodes enabled?
+ * Which is a better UI choice?
+ */
+ is_enabled = FALSE;
+ for (child = node_data->children; child != NULL; child =
+ child->next) {
+ if (walk_menu_tree_for_selected_packet(child, fd, edt))
+ is_enabled = TRUE;
+ }
+ node_data->enabled = is_enabled;
+ }
+
+ /*
+ * The root node doesn't correspond to a menu tree item; it
+ * has a null name pointer.
+ */
+ if (node_data->name != NULL) {
+ set_menu_sensitivity(main_menu_factory, node_data->name,
+ node_data->enabled);
+ }
+ return node_data->enabled;
+}
+
+void
+set_menus_for_selected_packet(capture_file *cf)
+{
+ set_menu_sensitivity(main_menu_factory, "/Edit/Mark Packet",
+ cf->current_frame != NULL);
+ set_menu_sensitivity(packet_list_menu_factory, "/Mark Packet",
+ cf->current_frame != NULL);
+ set_menu_sensitivity(main_menu_factory, "/Edit/Time Reference",
+ cf->current_frame != NULL);
+ set_menu_sensitivity(packet_list_menu_factory, "/Time Reference",
+ cf->current_frame != NULL);
+ set_menu_sensitivity(main_menu_factory, "/Edit/Mark All Packets",
+ cf->current_frame != NULL);
+ set_menu_sensitivity(main_menu_factory, "/Edit/Unmark All Packets",
+ cf->current_frame != NULL);
+ set_menu_sensitivity(main_menu_factory, "/View/Collapse All",
+ cf->current_frame != NULL);
+ set_menu_sensitivity(tree_view_menu_factory, "/Collapse All",
+ cf->current_frame != NULL);
+ set_menu_sensitivity(main_menu_factory, "/View/Expand All",
+ cf->current_frame != NULL);
+ set_menu_sensitivity(tree_view_menu_factory, "/Expand All",
+ cf->current_frame != NULL);
+ set_menu_sensitivity(main_menu_factory, "/View/Show Packet in New Window",
+ cf->current_frame != NULL);
+ set_menu_sensitivity(packet_list_menu_factory, "/Show Packet in New Window",
+ cf->current_frame != NULL);
+ set_menu_sensitivity(main_menu_factory, "/Analyze/Follow TCP Stream",
+ cf->current_frame != NULL ? (cf->edt->pi.ipproto == IP_PROTO_TCP) : FALSE);
+ set_menu_sensitivity(NULL, "/Follow TCP Stream",
+ cf->current_frame != NULL ? (cf->edt->pi.ipproto == IP_PROTO_TCP) : FALSE);
+ set_menu_sensitivity(main_menu_factory, "/Analyze/Decode As...",
+ cf->current_frame != NULL && decode_as_ok());
+ set_menu_sensitivity(NULL, "/Decode As...",
+ cf->current_frame != NULL && decode_as_ok());
+ set_menu_sensitivity(main_menu_factory, "/View/Name Resolution/Resolve Name",
+ cf->current_frame != NULL && (g_resolv_flags & RESOLV_ALL_ADDRS) != RESOLV_ALL_ADDRS);
+ set_menu_sensitivity(tree_view_menu_factory, "/Resolve Name",
+ cf->current_frame != NULL && (g_resolv_flags & RESOLV_ALL_ADDRS) != RESOLV_ALL_ADDRS);
+ set_menu_sensitivity(packet_list_menu_factory, "/Apply as Filter",
+ cf->current_frame != NULL);
+ set_menu_sensitivity(packet_list_menu_factory, "/Prepare a Filter",
+ cf->current_frame != NULL);
+
+ walk_menu_tree_for_selected_packet(tap_menu_tree_root, cf->current_frame,
+ cf->edt);
+ packets_bar_update();
+}
+
+/* Enable or disable menu items based on whether a tree row is selected
+ and, if so, on the properties of the tree row. */
+static gboolean
+walk_menu_tree_for_selected_tree_row(GList *node, field_info *fi)
+{
+ gboolean is_enabled;
+ GList *child;
+ menu_item_t *node_data = node->data;
+
+ /*
+ * Is this a leaf node or an interior node?
+ */
+ if (node_data->children == NULL) {
+ /*
+ * It's a leaf node.
+ *
+ * If it has no "selected_tree_row_enabled()" routine,
+ * leave its enabled/disabled status alone - it
+ * doesn't depend on whether we have a tree row selected
+ * or not or on the selected tree row.
+ *
+ * If it has a "selected_tree_row_enabled()" routine,
+ * call it and set the item's enabled/disabled status
+ * based on its return value.
+ */
+ if (node_data->selected_tree_row_enabled != NULL)
+ node_data->enabled = node_data->selected_tree_row_enabled(fi);
+ } else {
+ /*
+ * It's an interior node; call
+ * "walk_menu_tree_for_selected_tree_row()" on all its
+ * children and, if any of them are enabled, enable
+ * this node, otherwise disable it.
+ *
+ * XXX - should we just leave all interior nodes enabled?
+ * Which is a better UI choice?
+ */
+ is_enabled = FALSE;
+ for (child = node_data->children; child != NULL; child =
+ child->next) {
+ if (walk_menu_tree_for_selected_tree_row(child, fi))
+ is_enabled = TRUE;
+ }
+ node_data->enabled = is_enabled;
+ }
+
+ /*
+ * The root node doesn't correspond to a menu tree item; it
+ * has a null name pointer.
+ */
+ if (node_data->name != NULL) {
+ set_menu_sensitivity(main_menu_factory, node_data->name,
+ node_data->enabled);
+ }
+ return node_data->enabled;
+}
+
+void
+set_menus_for_selected_tree_row(capture_file *cf)
+{
+ gboolean properties;
+
+
+ set_menu_sensitivity(main_menu_factory, "/File/Export/Selected Packet Bytes...",
+ cf->finfo_selected != NULL);
+ set_menu_sensitivity(tree_view_menu_factory, "/Export Selected Packet Bytes...",
+ cf->finfo_selected != NULL);
+ set_menu_sensitivity(hexdump_menu_factory, "/Export Selected Packet Bytes...",
+ cf->finfo_selected != NULL);
+
+ if (cf->finfo_selected != NULL) {
+ header_field_info *hfinfo = cf->finfo_selected->hfinfo;
+ if (hfinfo->parent == -1) {
+ properties = prefs_is_registered_protocol(hfinfo->abbrev);
+ } else {
+ properties = prefs_is_registered_protocol(proto_registrar_get_abbrev(hfinfo->parent));
+ }
+ set_menu_sensitivity(main_menu_factory,
+ "/Go/Go to Corresponding Packet", hfinfo->type == FT_FRAMENUM);
+ set_menu_sensitivity(tree_view_menu_factory,
+ "/Go to Corresponding Packet", hfinfo->type == FT_FRAMENUM);
+ set_menu_sensitivity(main_menu_factory, "/Analyze/Apply as Filter",
+ proto_can_match_selected(cf->finfo_selected, cf->edt));
+ set_menu_sensitivity(tree_view_menu_factory, "/Apply as Filter",
+ proto_can_match_selected(cf->finfo_selected, cf->edt));
+ set_menu_sensitivity(main_menu_factory, "/Analyze/Prepare a Filter",
+ proto_can_match_selected(cf->finfo_selected, cf->edt));
+ set_menu_sensitivity(tree_view_menu_factory, "/Prepare a Filter",
+ proto_can_match_selected(cf->finfo_selected, cf->edt));
+ set_menu_sensitivity(tree_view_menu_factory, "/Protocol Preferences...",
+ properties);
+ set_menu_sensitivity(main_menu_factory, "/View/Expand Tree", cf->finfo_selected->tree_type != -1);
+ set_menu_sensitivity(tree_view_menu_factory, "/Expand Tree", cf->finfo_selected->tree_type != -1);
+ } else {
+ set_menu_sensitivity(main_menu_factory,
+ "/Go/Go to Corresponding Packet", FALSE);
+ set_menu_sensitivity(tree_view_menu_factory,
+ "/Go to Corresponding Packet", FALSE);
+ set_menu_sensitivity(main_menu_factory, "/Analyze/Apply as Filter", FALSE);
+ set_menu_sensitivity(tree_view_menu_factory, "/Apply as Filter", FALSE);
+ set_menu_sensitivity(main_menu_factory, "/Analyze/Prepare a Filter", FALSE);
+ set_menu_sensitivity(tree_view_menu_factory, "/Prepare a Filter", FALSE);
+ set_menu_sensitivity(tree_view_menu_factory, "/Protocol Preferences...",
+ FALSE);
+ set_menu_sensitivity(main_menu_factory, "/View/Expand Tree", FALSE);
+ set_menu_sensitivity(tree_view_menu_factory, "/Expand Tree", FALSE);
+ }
+
+ walk_menu_tree_for_selected_tree_row(tap_menu_tree_root, cf->finfo_selected);
+}
diff --git a/gtk/toolbar.c b/gtk/toolbar.c index 4716961991..209de0af68 100644 --- a/gtk/toolbar.c +++ b/gtk/toolbar.c @@ -252,9 +252,22 @@ void set_toolbar_for_unsaved_capture_file(gboolean have_unsaved_capture_file) { } } + +/* XXX - this is a quick and dirty hack to get the current state of capturing. + * this has to be improved, and should be reside somewhere in the capture engine. */ +gboolean g_is_capture_in_progress = FALSE; + +gboolean +is_capture_in_progress(void) +{ + return g_is_capture_in_progress; +} + /* set toolbar state "have a capture in progress" */ void set_toolbar_for_capture_in_progress(gboolean capture_in_progress) { + g_is_capture_in_progress = capture_in_progress; + if (toolbar_init) { #ifdef HAVE_LIBPCAP gtk_widget_set_sensitive(new_button, !capture_in_progress); |