Add a preferences page for the name resolution flags.

Separate the preferences value for those flags and the name resolution
code's value into separate variables; this means that the resolution
code no longer depends on the preferences code, and may let us
eventually have the current setting and the preference setting differ
(so that a user can temporarily override the preference setting without
causing subsequent saves of the preferences to save the temporary
value).

Add routines to create various types of widgets for preferences, and to
fetch the values for "enumerated" preferences, and use them both in the
code to handle hardwired preference pages and table-driven preference
pages.

svn path=/trunk/; revision=4536
This commit is contained in:
Guy Harris 2002-01-13 20:35:12 +00:00
parent 649cc279d6
commit 0a03b0f73e
20 changed files with 596 additions and 392 deletions

View File

@ -1,7 +1,7 @@
/* resolv.c
* Routines for network object lookup
*
* $Id: resolv.c,v 1.19 2001/12/20 19:19:41 guy Exp $
* $Id: resolv.c,v 1.20 2002/01/13 20:35:10 guy Exp $
*
* Laurent Deniel <deniel@worldnet.fr>
*
@ -81,8 +81,6 @@
#include "resolv.h"
#include "filesystem.h"
#include "prefs.h"
#define ENAME_ETHERS "ethers"
#define ENAME_IPXNETS "ipxnets"
#define ENAME_MANUF "manuf"
@ -163,6 +161,11 @@ static hashipxnet_t *ipxnet_table[HASHIPXNETSIZE];
static int eth_resolution_initialized = 0;
static int ipxnet_resolution_initialized = 0;
/*
* Flag controlling what names to resolve.
*/
guint32 g_resolv_flags;
/*
* Global variables (can be changed in GUI sections)
* XXX - they could be changed in GUI code, but there's currently no
@ -230,7 +233,7 @@ static guchar *serv_name_lookup(guint port, port_type proto)
tp->addr = port;
tp->next = NULL;
if (!(prefs.name_resolve & PREFS_RESOLV_TRANSPORT) ||
if (!(g_resolv_flags & RESOLV_TRANSPORT) ||
(servp = getservbyport(htons(port), serv_proto)) == NULL) {
/* unknown port */
sprintf(tp->name, "%d", port);
@ -295,7 +298,7 @@ static guchar *host_name_lookup(guint addr, gboolean *found)
* botch, we don't try to translate an all-zero IP address to a host
* name.
*/
if (addr != 0 && (prefs.name_resolve & PREFS_RESOLV_NETWORK)) {
if (addr != 0 && (g_resolv_flags & RESOLV_NETWORK)) {
#ifdef AVOID_DNS_TIMEOUT
/* Quick hack to avoid DNS/YP timeout */
@ -335,7 +338,7 @@ static guchar *host_name_lookup6(struct e_in6_addr *addr, gboolean *found)
#ifdef INET6
struct hostent *hostp;
if (prefs.name_resolve & PREFS_RESOLV_NETWORK) {
if (g_resolv_flags & RESOLV_NETWORK) {
#ifdef AVOID_DNS_TIMEOUT
/* Quick hack to avoid DNS/YP timeout */
@ -1070,7 +1073,7 @@ extern guchar *get_hostname(guint addr)
{
gboolean found;
if (!(prefs.name_resolve & PREFS_RESOLV_NETWORK))
if (!(g_resolv_flags & RESOLV_NETWORK))
return ip_to_str((guint8 *)&addr);
return host_name_lookup(addr, &found);
@ -1081,7 +1084,7 @@ extern const guchar *get_hostname6(struct e_in6_addr *addr)
gboolean found;
#ifdef INET6
if (!(prefs.name_resolve & PREFS_RESOLV_NETWORK))
if (!(g_resolv_flags & RESOLV_NETWORK))
return ip6_to_str(addr);
if (IN6_IS_ADDR_LINKLOCAL(addr) || IN6_IS_ADDR_MULTICAST(addr))
return ip6_to_str(addr);
@ -1134,7 +1137,7 @@ extern guchar *get_udp_port(guint port)
static gchar str[3][MAXNAMELEN];
static gchar *cur;
if (!(prefs.name_resolve & PREFS_RESOLV_TRANSPORT)) {
if (!(g_resolv_flags & RESOLV_TRANSPORT)) {
if (cur == &str[0][0]) {
cur = &str[1][0];
} else if (cur == &str[1][0]) {
@ -1155,7 +1158,7 @@ extern guchar *get_tcp_port(guint port)
static gchar str[3][MAXNAMELEN];
static gchar *cur;
if (!(prefs.name_resolve & PREFS_RESOLV_TRANSPORT)) {
if (!(g_resolv_flags & RESOLV_TRANSPORT)) {
if (cur == &str[0][0]) {
cur = &str[1][0];
} else if (cur == &str[1][0]) {
@ -1176,7 +1179,7 @@ extern guchar *get_sctp_port(guint port)
static gchar str[3][MAXNAMELEN];
static gchar *cur;
if (!(prefs.name_resolve & PREFS_RESOLV_TRANSPORT)) {
if (!(g_resolv_flags & RESOLV_TRANSPORT)) {
if (cur == &str[0][0]) {
cur = &str[1][0];
} else if (cur == &str[1][0]) {
@ -1194,7 +1197,7 @@ extern guchar *get_sctp_port(guint port)
extern guchar *get_ether_name(const guint8 *addr)
{
if (!(prefs.name_resolve & PREFS_RESOLV_MAC))
if (!(g_resolv_flags & RESOLV_MAC))
return ether_to_str((guint8 *)addr);
if (!eth_resolution_initialized) {
@ -1217,7 +1220,7 @@ guchar *get_ether_name_if_known(const guint8 *addr)
/* Initialize ether structs if we're the first
* ether-related function called */
if (!(prefs.name_resolve & PREFS_RESOLV_MAC))
if (!(g_resolv_flags & RESOLV_MAC))
return NULL;
if (!eth_resolution_initialized) {
@ -1268,7 +1271,7 @@ guchar *get_ether_name_if_known(const guint8 *addr)
extern guint8 *get_ether_addr(const guchar *name)
{
/* force resolution (do not check prefs.name_resolve) */
/* force resolution (do not check g_resolv_flags) */
if (!eth_resolution_initialized) {
initialize_ethers();
@ -1300,7 +1303,7 @@ extern void add_ether_byip(guint ip, const guint8 *eth)
extern const guchar *get_ipxnet_name(const guint32 addr)
{
if (!(prefs.name_resolve & PREFS_RESOLV_NETWORK)) {
if (!(g_resolv_flags & RESOLV_NETWORK)) {
return ipxnet_to_str_punct(addr, '\0');
}
@ -1318,7 +1321,7 @@ extern guint32 get_ipxnet_addr(const guchar *name, gboolean *known)
guint32 addr;
gboolean success;
/* force resolution (do not check prefs.name_resolve) */
/* force resolution (do not check g_resolv_flags) */
if (!ipxnet_resolution_initialized) {
initialize_ipxnets();
@ -1338,12 +1341,12 @@ extern const guchar *get_manuf_name(const guint8 *addr)
static gchar *cur;
hashmanuf_t *manufp;
if ((prefs.name_resolve & PREFS_RESOLV_MAC) && !eth_resolution_initialized) {
if ((g_resolv_flags & RESOLV_MAC) && !eth_resolution_initialized) {
initialize_ethers();
eth_resolution_initialized = 1;
}
if (!(prefs.name_resolve & PREFS_RESOLV_MAC) || ((manufp = manuf_name_lookup(addr)) == NULL)) {
if (!(g_resolv_flags & RESOLV_MAC) || ((manufp = manuf_name_lookup(addr)) == NULL)) {
if (cur == &str[0][0]) {
cur = &str[1][0];
} else if (cur == &str[1][0]) {

View File

@ -1,14 +1,13 @@
/* resolv.h
* Definitions for network object lookup
*
* $Id: resolv.h,v 1.7 2001/08/21 06:39:17 guy Exp $
* $Id: resolv.h,v 1.8 2002/01/13 20:35:10 guy Exp $
*
* Laurent Deniel <deniel@worldnet.fr>
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
* 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
@ -32,6 +31,20 @@
#define MAXNAMELEN 64 /* max name length (hostname and port name) */
#endif
/*
* Flag controlling what names to resolve.
*/
extern guint32 g_resolv_flags;
/* 32 types are sufficient (as are 640k of RAM) */
/* FIXME: Maybe MANUF/m, IP/i, IP6/6, IPX/x, UDP+TCP/t etc would be
more useful/consistent */
#define RESOLV_NONE 0x0
#define RESOLV_MAC 0x1
#define RESOLV_NETWORK 0x2
#define RESOLV_TRANSPORT 0x4
#define RESOLV_ALL 0xFFFFFFFF
/* global variables */
extern gchar *g_ethers_path;
@ -41,6 +54,9 @@ extern gchar *g_pipxnets_path;
/* Functions in resolv.c */
/* Set the flags controlling what names to resolve */
extern void resolv_set_flags(guint32 flags);
/* get_tcp_port returns the UDP port name or "%u" if not found */
extern guchar *get_udp_port(guint port);

View File

@ -1,7 +1,7 @@
# Makefile.am
# Automake file for the GTK interface routines for Ethereal
#
# $Id: Makefile.am,v 1.37 2002/01/10 07:43:39 guy Exp $
# $Id: Makefile.am,v 1.38 2002/01/13 20:35:11 guy Exp $
#
# Ethereal - Network traffic analyzer
# By Gerald Combs <gerald@zing.org>
@ -71,6 +71,8 @@ libui_a_SOURCES = \
main.h \
menu.c \
menu.h \
nameres_prefs.c \
nameres_prefs.h \
packet_win.c \
packet_win.h \
plugins_dlg.c \

View File

@ -37,6 +37,7 @@ OBJECTS=capture_dlg.obj \
help_dlg.obj \
main.obj \
menu.obj \
nameres_prefs.obj \
packet_win.obj \
plugins_dlg.obj \
prefs_dlg.obj \

View File

@ -1,7 +1,7 @@
/* capture_dlg.c
* Routines for packet capture windows
*
* $Id: capture_dlg.c,v 1.55 2002/01/11 08:55:02 guy Exp $
* $Id: capture_dlg.c,v 1.56 2002/01/13 20:35:11 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -386,21 +386,21 @@ capture_prep_cb(GtkWidget *w, gpointer d)
m_resolv_cb = dlg_check_button_new_with_label_with_mnemonic(
"Enable _MAC name resolution", accel_group);
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(m_resolv_cb),
prefs.name_resolve & PREFS_RESOLV_MAC);
g_resolv_flags & RESOLV_MAC);
gtk_container_add(GTK_CONTAINER(main_vb), m_resolv_cb);
gtk_widget_show(m_resolv_cb);
n_resolv_cb = dlg_check_button_new_with_label_with_mnemonic(
"Enable _network name resolution", accel_group);
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(n_resolv_cb),
prefs.name_resolve & PREFS_RESOLV_NETWORK);
g_resolv_flags & RESOLV_NETWORK);
gtk_container_add(GTK_CONTAINER(main_vb), n_resolv_cb);
gtk_widget_show(n_resolv_cb);
t_resolv_cb = dlg_check_button_new_with_label_with_mnemonic(
"Enable _transport name resolution", accel_group);
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(t_resolv_cb),
prefs.name_resolve & PREFS_RESOLV_TRANSPORT);
g_resolv_flags & RESOLV_TRANSPORT);
gtk_container_add(GTK_CONTAINER(main_vb), t_resolv_cb);
gtk_widget_show(t_resolv_cb);
@ -688,10 +688,10 @@ capture_prep_ok_cb(GtkWidget *ok_bt, gpointer parent_w) {
auto_scroll_live = GTK_TOGGLE_BUTTON (auto_scroll_cb)->active;
prefs.name_resolve = PREFS_RESOLV_NONE;
prefs.name_resolve |= (GTK_TOGGLE_BUTTON (m_resolv_cb)->active ? PREFS_RESOLV_MAC : PREFS_RESOLV_NONE);
prefs.name_resolve |= (GTK_TOGGLE_BUTTON (n_resolv_cb)->active ? PREFS_RESOLV_NETWORK : PREFS_RESOLV_NONE);
prefs.name_resolve |= (GTK_TOGGLE_BUTTON (t_resolv_cb)->active ? PREFS_RESOLV_TRANSPORT : PREFS_RESOLV_NONE);
g_resolv_flags = RESOLV_NONE;
g_resolv_flags |= (GTK_TOGGLE_BUTTON (m_resolv_cb)->active ? RESOLV_MAC : RESOLV_NONE);
g_resolv_flags |= (GTK_TOGGLE_BUTTON (n_resolv_cb)->active ? RESOLV_NETWORK : RESOLV_NONE);
g_resolv_flags |= (GTK_TOGGLE_BUTTON (t_resolv_cb)->active ? RESOLV_TRANSPORT : RESOLV_NONE);
cfile.ringbuffer_on = GTK_TOGGLE_BUTTON (ringbuffer_on_tb)->active && !(sync_mode);
if (cfile.ringbuffer_on == TRUE) {

View File

@ -1,7 +1,7 @@
/* capture_prefs.c
* Dialog box for capture preferences
*
* $Id: capture_prefs.c,v 1.6 2002/01/12 11:02:47 guy Exp $
* $Id: capture_prefs.c,v 1.7 2002/01/13 20:35:11 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -38,17 +38,13 @@
#include "capture_prefs.h"
#include "gtkglobals.h"
#include "prefs.h"
#include "prefs-int.h"
#include "prefs_dlg.h"
#include "ui_util.h"
#include "pcap-util.h"
#include "main.h"
#ifdef HAVE_LIBPCAP
static void create_option_check_button(GtkWidget *main_vb, const gchar *key,
GtkWidget *main_tb, int table_position, const gchar *label_text,
gboolean active);
#define DEVICE_KEY "device"
#define PROM_MODE_KEY "prom_mode"
#define CAPTURE_REAL_TIME_KEY "capture_real_time"
@ -59,7 +55,7 @@ GtkWidget*
capture_prefs_show(void)
{
GtkWidget *main_tb, *main_vb;
GtkWidget *if_cb, *if_lb;
GtkWidget *if_cb, *if_lb, *promisc_cb, *sync_cb, *auto_scroll_cb;
GList *if_list;
int err;
char err_str[PCAP_ERRBUF_SIZE];
@ -98,16 +94,21 @@ capture_prefs_show(void)
free_interface_list(if_list);
/* Promiscuous mode */
create_option_check_button(main_vb, PROM_MODE_KEY, main_tb, 1,
promisc_cb = create_preference_check_button(main_tb, 1,
"Capture packets in promiscuous mode:", prefs.capture_prom_mode);
gtk_object_set_data(GTK_OBJECT(main_vb), PROM_MODE_KEY, promisc_cb);
/* Real-time capture */
create_option_check_button(main_vb, CAPTURE_REAL_TIME_KEY, main_tb, 2,
sync_cb = create_preference_check_button(main_tb, 2,
"Update list of packets in real time:", prefs.capture_real_time);
gtk_object_set_data(GTK_OBJECT(main_vb), CAPTURE_REAL_TIME_KEY,
sync_cb);
/* Auto-scroll real-time capture */
create_option_check_button(main_vb, AUTO_SCROLL_KEY, main_tb, 3,
auto_scroll_cb = create_preference_check_button(main_tb, 3,
"Automatic scrolling in live capture:", prefs.capture_auto_scroll);
gtk_object_set_data(GTK_OBJECT(main_vb), AUTO_SCROLL_KEY,
auto_scroll_cb);
/* Show 'em what we got */
gtk_widget_show_all(main_vb);
@ -115,26 +116,6 @@ capture_prefs_show(void)
return(main_vb);
}
static void
create_option_check_button(GtkWidget *main_vb, const gchar *key,
GtkWidget *main_tb, int table_position, const gchar *label_text,
gboolean active)
{
GtkWidget *label, *check_box;
label = gtk_label_new(label_text);
gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);
gtk_table_attach_defaults(GTK_TABLE(main_tb), label, 0, 1,
table_position, table_position + 1);
check_box = gtk_check_button_new();
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_box), active);
gtk_table_attach_defaults(GTK_TABLE(main_tb), check_box, 1, 2,
table_position, table_position + 1);
gtk_object_set_data(GTK_OBJECT(main_vb), key, check_box);
}
void
capture_prefs_fetch(GtkWidget *w)
{

View File

@ -1,7 +1,7 @@
/* display_opts.c
* Routines for packet display windows
*
* $Id: display_opts.c,v 1.23 2002/01/10 11:05:50 guy Exp $
* $Id: display_opts.c,v 1.24 2002/01/13 20:35:11 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -22,7 +22,6 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
@ -59,7 +58,6 @@
#include "display_opts.h"
#include "ui_util.h"
#include "dlg_utils.h"
#include "prefs.h"
extern capture_file cfile;
@ -184,7 +182,7 @@ display_opt_cb(GtkWidget *w, gpointer d) {
button = dlg_check_button_new_with_label_with_mnemonic(
"Enable _MAC name resolution", accel_group);
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button),
prefs.name_resolve & PREFS_RESOLV_MAC);
g_resolv_flags & RESOLV_MAC);
gtk_object_set_data(GTK_OBJECT(display_opt_w), E_DISPLAY_M_NAME_RESOLUTION_KEY,
button);
gtk_box_pack_start(GTK_BOX(main_vb), button, TRUE, TRUE, 0);
@ -193,7 +191,7 @@ display_opt_cb(GtkWidget *w, gpointer d) {
button = dlg_check_button_new_with_label_with_mnemonic(
"Enable _network name resolution", accel_group);
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button),
prefs.name_resolve & PREFS_RESOLV_NETWORK);
g_resolv_flags & RESOLV_NETWORK);
gtk_object_set_data(GTK_OBJECT(display_opt_w), E_DISPLAY_N_NAME_RESOLUTION_KEY,
button);
gtk_box_pack_start(GTK_BOX(main_vb), button, TRUE, TRUE, 0);
@ -202,7 +200,7 @@ display_opt_cb(GtkWidget *w, gpointer d) {
button = dlg_check_button_new_with_label_with_mnemonic(
"Enable _transport name resolution", accel_group);
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button),
prefs.name_resolve & PREFS_RESOLV_TRANSPORT);
g_resolv_flags & RESOLV_TRANSPORT);
gtk_object_set_data(GTK_OBJECT(display_opt_w), E_DISPLAY_T_NAME_RESOLUTION_KEY,
button);
gtk_box_pack_start(GTK_BOX(main_vb), button, TRUE, TRUE, 0);
@ -292,16 +290,16 @@ get_display_options(GtkWidget *parent_w)
auto_scroll_live = (GTK_TOGGLE_BUTTON (button)->active);
#endif
prefs.name_resolve = PREFS_RESOLV_NONE;
g_resolv_flags = RESOLV_NONE;
button = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(parent_w),
E_DISPLAY_M_NAME_RESOLUTION_KEY);
prefs.name_resolve |= (GTK_TOGGLE_BUTTON (button)->active ? PREFS_RESOLV_MAC : PREFS_RESOLV_NONE);
g_resolv_flags |= (GTK_TOGGLE_BUTTON (button)->active ? RESOLV_MAC : RESOLV_NONE);
button = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(parent_w),
E_DISPLAY_N_NAME_RESOLUTION_KEY);
prefs.name_resolve |= (GTK_TOGGLE_BUTTON (button)->active ? PREFS_RESOLV_NETWORK : PREFS_RESOLV_NONE);
g_resolv_flags |= (GTK_TOGGLE_BUTTON (button)->active ? RESOLV_NETWORK : RESOLV_NONE);
button = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(parent_w),
E_DISPLAY_T_NAME_RESOLUTION_KEY);
prefs.name_resolve |= (GTK_TOGGLE_BUTTON (button)->active ? PREFS_RESOLV_TRANSPORT : PREFS_RESOLV_NONE);
g_resolv_flags |= (GTK_TOGGLE_BUTTON (button)->active ? RESOLV_TRANSPORT : RESOLV_NONE);
}

View File

@ -1,7 +1,7 @@
/* file_dlg.c
* Dialog boxes for handling files
*
* $Id: file_dlg.c,v 1.46 2001/12/06 03:09:28 guy Exp $
* $Id: file_dlg.c,v 1.47 2002/01/13 20:35:11 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -42,7 +42,6 @@
#include "globals.h"
#include "gtkglobals.h"
#include "prefs.h"
#include "resolv.h"
#include "keys.h"
#include "filter_prefs.h"
@ -136,7 +135,7 @@ file_open_cmd_cb(GtkWidget *w, gpointer data)
m_resolv_cb = dlg_check_button_new_with_label_with_mnemonic(
"Enable _MAC name resolution", accel_group);
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(m_resolv_cb),
prefs.name_resolve & PREFS_RESOLV_MAC);
g_resolv_flags & RESOLV_MAC);
gtk_box_pack_start(GTK_BOX(main_vb), m_resolv_cb, FALSE, FALSE, 0);
gtk_widget_show(m_resolv_cb);
gtk_object_set_data(GTK_OBJECT(GTK_FILE_SELECTION(file_open_w)->ok_button),
@ -145,7 +144,7 @@ file_open_cmd_cb(GtkWidget *w, gpointer data)
n_resolv_cb = dlg_check_button_new_with_label_with_mnemonic(
"Enable _network name resolution", accel_group);
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(n_resolv_cb),
prefs.name_resolve & PREFS_RESOLV_NETWORK);
g_resolv_flags & RESOLV_NETWORK);
gtk_box_pack_start(GTK_BOX(main_vb), n_resolv_cb, FALSE, FALSE, 0);
gtk_widget_show(n_resolv_cb);
gtk_object_set_data(GTK_OBJECT(GTK_FILE_SELECTION(file_open_w)->ok_button),
@ -154,7 +153,7 @@ file_open_cmd_cb(GtkWidget *w, gpointer data)
t_resolv_cb = dlg_check_button_new_with_label_with_mnemonic(
"Enable _transport name resolution", accel_group);
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(t_resolv_cb),
prefs.name_resolve & PREFS_RESOLV_TRANSPORT);
g_resolv_flags & RESOLV_TRANSPORT);
gtk_box_pack_start(GTK_BOX(main_vb), t_resolv_cb, FALSE, FALSE, 0);
gtk_widget_show(t_resolv_cb);
gtk_object_set_data(GTK_OBJECT(GTK_FILE_SELECTION(file_open_w)->ok_button),
@ -224,13 +223,13 @@ file_open_ok_cb(GtkWidget *w, GtkFileSelection *fs) {
cfile.rfcode = rfcode;
/* Set the global resolving variable */
prefs.name_resolve = 0;
g_resolv_flags = 0;
m_resolv_cb = gtk_object_get_data(GTK_OBJECT(w), E_FILE_M_RESOLVE_KEY);
prefs.name_resolve |= GTK_TOGGLE_BUTTON (m_resolv_cb)->active ? PREFS_RESOLV_MAC : PREFS_RESOLV_NONE;
g_resolv_flags |= GTK_TOGGLE_BUTTON (m_resolv_cb)->active ? RESOLV_MAC : RESOLV_NONE;
n_resolv_cb = gtk_object_get_data(GTK_OBJECT(w), E_FILE_N_RESOLVE_KEY);
prefs.name_resolve |= GTK_TOGGLE_BUTTON (n_resolv_cb)->active ? PREFS_RESOLV_NETWORK : PREFS_RESOLV_NONE;
g_resolv_flags |= GTK_TOGGLE_BUTTON (n_resolv_cb)->active ? RESOLV_NETWORK : RESOLV_NONE;
t_resolv_cb = gtk_object_get_data(GTK_OBJECT(w), E_FILE_T_RESOLVE_KEY);
prefs.name_resolve |= GTK_TOGGLE_BUTTON (t_resolv_cb)->active ? PREFS_RESOLV_TRANSPORT : PREFS_RESOLV_NONE;
g_resolv_flags |= GTK_TOGGLE_BUTTON (t_resolv_cb)->active ? RESOLV_TRANSPORT : RESOLV_NONE;
/* We've crossed the Rubicon; get rid of the file selection box. */
gtk_widget_hide(GTK_WIDGET (fs));

View File

@ -1,7 +1,7 @@
/* gui_prefs.c
* Dialog box for GUI preferences
*
* $Id: gui_prefs.c,v 1.31 2002/01/12 11:09:09 guy Exp $
* $Id: gui_prefs.c,v 1.32 2002/01/13 20:35:11 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -37,19 +37,13 @@
#include "follow_dlg.h"
#include "help_dlg.h"
#include "prefs.h"
#include "prefs-int.h"
#include "prefs_dlg.h"
#include "ui_util.h"
#include "simple_dialog.h"
#include "dlg_utils.h"
#include "proto_draw.h"
#include "main.h"
static void create_option_menu(GtkWidget *main_vb, const gchar *key,
GtkWidget *main_tb, int table_position,
const gchar *label_text, const enum_val_t *enumvals, gint current_val);
static void create_option_check_button(GtkWidget *main_vb, const gchar *key,
GtkWidget *main_tb, int table_position, const gchar *label_text,
gboolean active);
static void font_browse_cb(GtkWidget *w, gpointer data);
static void font_browse_ok_cb(GtkWidget *w, GtkFontSelectionDialog *fs);
static void font_browse_destroy(GtkWidget *win, gpointer data);
@ -134,7 +128,10 @@ GtkWidget*
gui_prefs_show(void)
{
GtkWidget *main_tb, *main_vb, *hbox, *font_bt, *color_bt;
GtkWidget *geom_cb;
GtkWidget *scrollbar_om, *plist_browse_om;
GtkWidget *ptree_browse_om, *line_style_om;
GtkWidget *expander_style_om, *highlight_style_om;
GtkWidget *save_position_cb, *save_size_cb;
/* The colors or font haven't been changed yet. */
colors_changed = FALSE;
@ -157,42 +154,58 @@ gui_prefs_show(void)
gtk_table_set_col_spacing( GTK_TABLE(main_tb), 1, 50 );
/* Scrollbar placement */
create_option_menu(main_vb, SCROLLBAR_PLACEMENT_KEY, main_tb, 0,
scrollbar_om = create_preference_option_menu(main_tb, 0,
"Vertical scrollbar placement:", scrollbar_placement_vals,
prefs.gui_scrollbar_on_right);
gtk_object_set_data(GTK_OBJECT(main_vb), SCROLLBAR_PLACEMENT_KEY,
scrollbar_om);
/* Packet list selection browseable */
create_option_menu(main_vb, PLIST_SEL_BROWSE_KEY, main_tb, 1,
plist_browse_om = create_preference_option_menu(main_tb, 1,
"Packet list mouse behavior:", selection_mode_vals,
prefs.gui_plist_sel_browse);
gtk_object_set_data(GTK_OBJECT(main_vb), PLIST_SEL_BROWSE_KEY,
plist_browse_om);
/* Proto tree selection browseable */
create_option_menu(main_vb, PTREE_SEL_BROWSE_KEY, main_tb, 2,
ptree_browse_om = create_preference_option_menu(main_tb, 2,
"Protocol tree mouse behavior:", selection_mode_vals,
prefs.gui_ptree_sel_browse);
gtk_object_set_data(GTK_OBJECT(main_vb), PTREE_SEL_BROWSE_KEY,
ptree_browse_om);
/* Tree line style */
create_option_menu(main_vb, PTREE_LINE_STYLE_KEY, main_tb, 3,
line_style_om = create_preference_option_menu(main_tb, 3,
"Tree line style:", line_style_vals,
prefs.gui_ptree_line_style);
gtk_object_set_data(GTK_OBJECT(main_vb), PTREE_LINE_STYLE_KEY,
line_style_om);
/* Tree expander style */
create_option_menu(main_vb, PTREE_EXPANDER_STYLE_KEY, main_tb, 4,
expander_style_om = create_preference_option_menu(main_tb, 4,
"Tree expander style:", expander_style_vals,
prefs.gui_ptree_expander_style);
gtk_object_set_data(GTK_OBJECT(main_vb), PTREE_EXPANDER_STYLE_KEY,
expander_style_om);
/* Hex Dump highlight style */
create_option_menu(main_vb, HEX_DUMP_HIGHLIGHT_STYLE_KEY, main_tb, 5,
highlight_style_om = create_preference_option_menu(main_tb, 5,
"Hex display highlight style:", highlight_style_vals,
prefs.gui_hex_dump_highlight_style);
gtk_object_set_data(GTK_OBJECT(main_vb), HEX_DUMP_HIGHLIGHT_STYLE_KEY,
highlight_style_om);
/* Geometry prefs */
create_option_check_button(main_vb, GEOMETRY_POSITION_KEY, main_tb,
save_position_cb = create_preference_check_button(main_tb,
6, "Save window position:", prefs.gui_geometry_save_position);
gtk_object_set_data(GTK_OBJECT(main_vb), GEOMETRY_POSITION_KEY,
save_position_cb);
create_option_check_button(main_vb, GEOMETRY_SIZE_KEY, main_tb,
save_size_cb = create_preference_check_button(main_tb,
7, "Save window size:", prefs.gui_geometry_save_size);
gtk_object_set_data(GTK_OBJECT(main_vb), GEOMETRY_SIZE_KEY,
save_size_cb);
/* "Font..." button - click to open a font selection dialog box. */
font_bt = gtk_button_new_with_label("Font...");
gtk_signal_connect(GTK_OBJECT(font_bt), "clicked",
@ -211,68 +224,6 @@ gui_prefs_show(void)
return(main_vb);
}
static void
create_option_menu(GtkWidget *main_vb, const gchar *key,
GtkWidget *main_tb, int table_position,
const gchar *label_text, const enum_val_t *enumvals, gint current_val)
{
GtkWidget *label, *menu_box, *menu, *menu_item, *option_menu;
int menu_index, index;
const enum_val_t *enum_valp;
label = gtk_label_new(label_text);
gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);
gtk_table_attach_defaults(GTK_TABLE(main_tb), label, 0, 1,
table_position, table_position + 1);
menu_box = gtk_hbox_new(FALSE, 0);
gtk_table_attach_defaults(GTK_TABLE(main_tb), menu_box,
1, 2, table_position, table_position + 1);
/* Create a menu from the enumvals */
menu = gtk_menu_new();
menu_index = -1;
for (enum_valp = enumvals, index = 0;
enum_valp->name != NULL; enum_valp++, index++) {
menu_item = gtk_menu_item_new_with_label(enum_valp->name);
gtk_menu_append(GTK_MENU(menu), menu_item);
if (enum_valp->value == current_val)
menu_index = index;
gtk_widget_show(menu_item);
}
/* Create the option menu from the menu */
option_menu = gtk_option_menu_new();
gtk_option_menu_set_menu(GTK_OPTION_MENU(option_menu), menu);
/* Set its current value to the variable's current value */
if (menu_index != -1)
gtk_option_menu_set_history(GTK_OPTION_MENU(option_menu),
menu_index);
gtk_box_pack_start(GTK_BOX(menu_box), option_menu, FALSE, FALSE, 0);
gtk_object_set_data(GTK_OBJECT(main_vb), key, option_menu);
}
static void
create_option_check_button(GtkWidget *main_vb, const gchar *key,
GtkWidget *main_tb, int table_position, const gchar *label_text,
gboolean active)
{
GtkWidget *label, *check_box;
label = gtk_label_new(label_text);
gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);
gtk_table_attach_defaults(GTK_TABLE(main_tb), label, 0, 1,
table_position, table_position + 1);
check_box = gtk_check_button_new();
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_box), active);
gtk_table_attach_defaults(GTK_TABLE(main_tb), check_box, 1, 2,
table_position, table_position + 1);
gtk_object_set_data(GTK_OBJECT(main_vb), key, check_box);
}
/* Create a font dialog for browsing. */
static void
font_browse_cb(GtkWidget *w, gpointer data)
@ -432,16 +383,7 @@ font_browse_destroy(GtkWidget *win, gpointer data)
static gint
fetch_enum_value(gpointer control, const enum_val_t *enumvals)
{
GtkWidget *label;
char *label_string;
/* Get the label for the currently active entry in the option menu.
Yes, this is how you do it. See FAQ 6.8 in the GTK+ FAQ. */
label = GTK_BIN(control)->child;
/* Get the label string, and translate it to a value. */
gtk_label_get(GTK_LABEL(label), &label_string);
return find_val_for_string(label_string, enumvals, 1);
return fetch_preference_option_menu_val(GTK_WIDGET(control), enumvals);
}
void
@ -479,7 +421,7 @@ gui_prefs_fetch(GtkWidget *w)
}
if (colors_changed)
fetch_colors();
fetch_colors();
}
void

View File

@ -1,6 +1,6 @@
/* main.c
*
* $Id: main.c,v 1.228 2002/01/11 08:21:02 guy Exp $
* $Id: main.c,v 1.229 2002/01/13 20:35:11 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -854,11 +854,11 @@ void expand_all_cb(GtkWidget *widget, gpointer data) {
void resolve_name_cb(GtkWidget *widget, gpointer data) {
if (cfile.edt->tree) {
gint tmp = prefs.name_resolve;
prefs.name_resolve = PREFS_RESOLV_ALL;
guint32 tmp = g_resolv_flags;
g_resolv_flags = RESOLV_ALL;
gtk_clist_clear ( GTK_CLIST(tree_view) );
proto_tree_draw(cfile.edt->tree, tree_view);
prefs.name_resolve = tmp;
g_resolv_flags = tmp;
}
}
@ -1309,6 +1309,9 @@ main(int argc, char *argv[])
auto_scroll_live = prefs->capture_auto_scroll;
#endif
/* Set the name resolution code's flags from the preferences. */
g_resolv_flags = prefs->name_resolve;
/* Read the capture filter file. */
read_filter_list(CFILTER_LIST, &cf_path, &cf_open_errno);
@ -1481,12 +1484,12 @@ main(int argc, char *argv[])
prefs->gui_font_name = g_strdup(optarg);
break;
case 'n': /* No name resolution */
prefs->name_resolve = PREFS_RESOLV_NONE;
g_resolv_flags = RESOLV_NONE;
break;
case 'N': /* Select what types of addresses/port #s to resolve */
if (prefs->name_resolve == PREFS_RESOLV_ALL)
prefs->name_resolve = PREFS_RESOLV_NONE;
badopt = string_to_name_resolve(optarg, &prefs->name_resolve);
if (g_resolv_flags == RESOLV_ALL)
g_resolv_flags = RESOLV_NONE;
badopt = string_to_name_resolve(optarg, &g_resolv_flags);
if (badopt != '\0') {
fprintf(stderr, "ethereal: -N specifies unknown resolving option '%c'; valid options are 'm', 'n', and 't'\n",
badopt);

View File

@ -1,7 +1,7 @@
/* menu.c
* Menu routines
*
* $Id: menu.c,v 1.60 2002/01/11 08:21:02 guy Exp $
* $Id: menu.c,v 1.61 2002/01/13 20:35:12 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -489,7 +489,7 @@ set_menus_for_selected_packet(gboolean have_selected_packet)
set_menu_sensitivity("/Tools/Decode As...",
have_selected_packet && decode_as_ok());
set_menu_sensitivity("/Resolve Name",
have_selected_packet && !prefs.name_resolve);
have_selected_packet && g_resolv_flags == 0);
set_menu_sensitivity("/Tools/TCP Stream Analysis",
have_selected_packet ? (cfile.edt->pi.ipproto == 6) : FALSE);
}

129
gtk/nameres_prefs.c Normal file
View File

@ -0,0 +1,129 @@
/* nameres_prefs.c
* Dialog box for name resolution preferences
*
* $Id: nameres_prefs.c,v 1.1 2002/01/13 20:35:12 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
#include <string.h>
#include <errno.h>
#include <gtk/gtk.h>
#include "globals.h"
#include "nameres_prefs.h"
#include "gtkglobals.h"
#include "resolv.h"
#include "prefs.h"
#include "prefs_dlg.h"
#include "ui_util.h"
#include "main.h"
#define M_RESOLVE_KEY "m_resolve"
#define N_RESOLVE_KEY "n_resolve"
#define T_RESOLVE_KEY "t_resolve"
#define RESOLV_TABLE_ROWS 3
GtkWidget*
nameres_prefs_show(void)
{
GtkWidget *main_tb, *main_vb;
GtkWidget *m_resolv_cb, *n_resolv_cb, *t_resolv_cb;
/*
* XXX - it would be nice if the current setting of the resolver
* flags could be different from the preference flags, so that
* the preference flags would represent what the user *typically*
* wants, but they could override them for particular captures
* without a subsequent editing of the preferences recording the
* temporary settings as permanent preferences.
*/
prefs.name_resolve = g_resolv_flags;
/* Main vertical box */
main_vb = gtk_vbox_new(FALSE, 7);
gtk_container_border_width(GTK_CONTAINER(main_vb), 5);
/* Main table */
main_tb = gtk_table_new(RESOLV_TABLE_ROWS, 3, FALSE);
gtk_box_pack_start(GTK_BOX(main_vb), main_tb, FALSE, FALSE, 0);
gtk_table_set_row_spacings(GTK_TABLE(main_tb), 10);
gtk_table_set_col_spacings(GTK_TABLE(main_tb), 15);
gtk_widget_show(main_tb);
/* Resolve MAC addresses */
m_resolv_cb = create_preference_check_button(main_tb, 0,
"Enable MAC name resolution:",
prefs.name_resolve & RESOLV_MAC);
gtk_object_set_data(GTK_OBJECT(main_vb), M_RESOLVE_KEY, m_resolv_cb);
/* Resolve network addresses */
n_resolv_cb = create_preference_check_button(main_tb, 1,
"Enable network name resolution:",
prefs.name_resolve & RESOLV_NETWORK);
gtk_object_set_data(GTK_OBJECT(main_vb), N_RESOLVE_KEY, n_resolv_cb);
/* Resolve transport addresses */
t_resolv_cb = create_preference_check_button(main_tb, 2,
"Enable transport name resolution:",
prefs.name_resolve & RESOLV_TRANSPORT);
gtk_object_set_data(GTK_OBJECT(main_vb), T_RESOLVE_KEY, t_resolv_cb);
/* Show 'em what we got */
gtk_widget_show_all(main_vb);
return(main_vb);
}
void
nameres_prefs_fetch(GtkWidget *w)
{
GtkWidget *m_resolv_cb, *n_resolv_cb, *t_resolv_cb;
m_resolv_cb = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(w),
M_RESOLVE_KEY);
n_resolv_cb = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(w),
N_RESOLVE_KEY);
t_resolv_cb = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(w),
T_RESOLVE_KEY);
prefs.name_resolve = RESOLV_NONE;
prefs.name_resolve |= (GTK_TOGGLE_BUTTON (m_resolv_cb)->active ? RESOLV_MAC : RESOLV_NONE);
prefs.name_resolve |= (GTK_TOGGLE_BUTTON (n_resolv_cb)->active ? RESOLV_NETWORK : RESOLV_NONE);
prefs.name_resolve |= (GTK_TOGGLE_BUTTON (t_resolv_cb)->active ? RESOLV_TRANSPORT : RESOLV_NONE);
}
void
nameres_prefs_apply(GtkWidget *w)
{
/*
* XXX - force a regeneration of the protocol list if this has
* changed?
*/
g_resolv_flags = prefs.name_resolve;
}
void
nameres_prefs_destroy(GtkWidget *w)
{
}

33
gtk/nameres_prefs.h Normal file
View File

@ -0,0 +1,33 @@
/* nameres_prefs.h
* Definitions for name resolution preferences window
*
* $Id: nameres_prefs.h,v 1.1 2002/01/13 20:35:12 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.
*/
#ifndef __NAMERES_PREFS_H__
#define __NAMERES_PREFS_H__
GtkWidget *nameres_prefs_show(void);
void nameres_prefs_fetch(GtkWidget *w);
void nameres_prefs_apply(GtkWidget *w);
void nameres_prefs_destroy(GtkWidget *w);
#endif

View File

@ -1,7 +1,7 @@
/* prefs_dlg.c
* Routines for handling preferences
*
* $Id: prefs_dlg.c,v 1.37 2002/01/11 07:40:31 guy Exp $
* $Id: prefs_dlg.c,v 1.38 2002/01/13 20:35:12 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -58,6 +58,7 @@
#include "stream_prefs.h"
#include "gui_prefs.h"
#include "capture_prefs.h"
#include "nameres_prefs.h"
#include "ui_util.h"
#include "dlg_utils.h"
#include "simple_dialog.h"
@ -77,6 +78,7 @@ static void prefs_tree_select_cb(GtkCTree *, GtkCTreeNode *, gint, gpointer);
#define E_STREAM_PAGE_KEY "tcp_stream_options_page"
#define E_GUI_PAGE_KEY "gui_options_page"
#define E_CAPTURE_PAGE_KEY "capture_options_page"
#define E_NAMERES_PAGE_KEY "nameres_options_page"
#define FIRST_PROTO_PREFS_PAGE 4
@ -114,11 +116,7 @@ pref_show(pref_t *pref, gpointer user_data)
GtkWidget *main_tb = user_data;
const char *title;
char *label_string;
GtkWidget *label, *menu, *menu_item, *widget, *button;
GSList *rb_group;
char uint_str[10+1];
const enum_val_t *enum_valp;
int menu_index, index;
/* Give this preference a label which is its title, followed by a colon,
and left-align it. */
@ -126,18 +124,10 @@ pref_show(pref_t *pref, gpointer user_data)
label_string = g_malloc(strlen(title) + 2);
strcpy(label_string, title);
strcat(label_string, ":");
label = gtk_label_new(label_string);
g_free(label_string);
gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);
/* Attach it to the table. */
gtk_table_attach_defaults(GTK_TABLE(main_tb), label, 0, 1, pref->ordinal,
pref->ordinal+1);
/* Save the current value of the preference, so that we can revert it if
the user does "Apply" and then "Cancel", and create the control for
editing the preference. */
widget = NULL; /* squelch GCC complaints */
switch (pref->type) {
case PREF_UINT:
@ -147,7 +137,6 @@ pref_show(pref_t *pref, gpointer user_data)
Even more annoyingly, even if there were, GLib doesn't define
G_MAXUINT - but I think ANSI C may define UINT_MAX, so we could
use that. */
widget = gtk_entry_new();
switch (pref->info.base) {
case 10:
@ -162,74 +151,47 @@ pref_show(pref_t *pref, gpointer user_data)
sprintf(uint_str, "%x", pref->saved_val.uint);
break;
}
gtk_entry_set_text(GTK_ENTRY(widget), uint_str);
pref->control = widget;
pref->control = create_preference_entry(main_tb, pref->ordinal,
label_string, uint_str);
break;
case PREF_BOOL:
pref->saved_val.bool = *pref->varp.bool;
widget = gtk_check_button_new();
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(widget), pref->saved_val.bool);
pref->control = widget;
pref->control = create_preference_check_button(main_tb, pref->ordinal,
label_string,
pref->saved_val.bool);
break;
case PREF_ENUM:
pref->saved_val.enumval = *pref->varp.enump;
if (pref->info.enum_info.radio_buttons) {
/* Show it as radio buttons. */
widget = gtk_hbox_new(FALSE, 0);
rb_group = NULL;
for (enum_valp = pref->info.enum_info.enumvals, index = 0;
enum_valp->name != NULL; enum_valp++, index++) {
button = gtk_radio_button_new_with_label(rb_group, enum_valp->name);
if (rb_group == NULL)
rb_group = gtk_radio_button_group(GTK_RADIO_BUTTON(button));
gtk_box_pack_start(GTK_BOX(widget), button, FALSE, FALSE, 10);
if (enum_valp->value == pref->saved_val.enumval)
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button), TRUE);
pref->control = button;
}
pref->control = create_preference_radio_buttons(main_tb, pref->ordinal,
label_string,
pref->info.enum_info.enumvals,
pref->saved_val.enumval);
} else {
/* Show it as an option menu. */
menu = gtk_menu_new();
menu_index = -1;
for (enum_valp = pref->info.enum_info.enumvals, index = 0;
enum_valp->name != NULL; enum_valp++, index++) {
menu_item = gtk_menu_item_new_with_label(enum_valp->name);
gtk_menu_append(GTK_MENU(menu), menu_item);
if (enum_valp->value == pref->saved_val.enumval)
menu_index = index;
gtk_widget_show(menu_item);
}
/* Create the option menu from the option */
widget = gtk_option_menu_new();
gtk_option_menu_set_menu(GTK_OPTION_MENU(widget), menu);
/* Set its current value to the variable's current value */
if (menu_index != -1)
gtk_option_menu_set_history(GTK_OPTION_MENU(widget), menu_index);
pref->control = widget;
pref->control = create_preference_option_menu(main_tb, pref->ordinal,
label_string,
pref->info.enum_info.enumvals,
pref->saved_val.enumval);
}
break;
case PREF_STRING:
widget = gtk_entry_new();
if (pref->saved_val.string != NULL)
g_free(pref->saved_val.string);
pref->saved_val.string = g_strdup(*pref->varp.string);
gtk_entry_set_text(GTK_ENTRY(widget), pref->saved_val.string);
pref->control = widget;
pref->control = create_preference_entry(main_tb, pref->ordinal,
label_string,
pref->saved_val.string);
break;
case PREF_OBSOLETE:
g_assert_not_reached();
widget = NULL;
break;
}
gtk_table_attach_defaults(GTK_TABLE(main_tb), widget, 1, 2, pref->ordinal,
pref->ordinal+1);
g_free(label_string);
}
#define MAX_TREE_NODE_NAME_LEN 64
@ -276,6 +238,7 @@ prefs_cb(GtkWidget *w, gpointer dummy) {
GtkWidget *main_vb, *top_hb, *bbox, *prefs_nb, *ct_sb, *frame,
*ok_bt, *apply_bt, *save_bt, *cancel_bt;
GtkWidget *print_pg, *column_pg, *stream_pg, *gui_pg, *capture_pg;
GtkWidget *nameres_pg;
gchar label_str[MAX_TREE_NODE_NAME_LEN], *label_ptr = label_str;
GtkCTreeNode *ct_node;
struct ct_struct cts;
@ -403,6 +366,20 @@ prefs_cb(GtkWidget *w, gpointer dummy) {
cts.page++;
#endif
/* Name resolution prefs */
frame = gtk_frame_new("Name resolution");
gtk_widget_show(GTK_WIDGET(frame));
nameres_pg = nameres_prefs_show();
gtk_container_add(GTK_CONTAINER(frame), nameres_pg);
gtk_object_set_data(GTK_OBJECT(prefs_w), E_NAMERES_PAGE_KEY, nameres_pg);
gtk_notebook_append_page (GTK_NOTEBOOK(prefs_nb), frame, NULL);
strcpy(label_str, "Name resolution");
ct_node = gtk_ctree_insert_node(GTK_CTREE(cts.ctree), NULL, NULL,
&label_ptr, 5, NULL, NULL, NULL, NULL, TRUE, TRUE);
gtk_ctree_node_set_row_data(GTK_CTREE(cts.ctree), ct_node,
GINT_TO_POINTER(cts.page));
cts.page++;
/* Registered prefs */
cts.notebook = prefs_nb;
strcpy(label_str, "Protocols");
@ -459,6 +436,185 @@ prefs_cb(GtkWidget *w, gpointer dummy) {
gtk_widget_show(prefs_w);
}
static void
set_option_label(GtkWidget *main_tb, int table_position,
const gchar *label_text)
{
GtkWidget *label;
label = gtk_label_new(label_text);
gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);
gtk_table_attach_defaults(GTK_TABLE(main_tb), label, 0, 1,
table_position, table_position + 1);
gtk_widget_show(label);
}
GtkWidget *
create_preference_check_button(GtkWidget *main_tb, int table_position,
const gchar *label_text, gboolean active)
{
GtkWidget *check_box;
set_option_label(main_tb, table_position, label_text);
check_box = gtk_check_button_new();
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_box), active);
gtk_table_attach_defaults(GTK_TABLE(main_tb), check_box, 1, 2,
table_position, table_position + 1);
return check_box;
}
GtkWidget *
create_preference_radio_buttons(GtkWidget *main_tb, int table_position,
const gchar *label_text, const enum_val_t *enumvals, gint current_val)
{
GtkWidget *radio_button_hbox, *button = NULL;
GSList *rb_group;
int index;
const enum_val_t *enum_valp;
set_option_label(main_tb, table_position, label_text);
radio_button_hbox = gtk_hbox_new(FALSE, 0);
rb_group = NULL;
for (enum_valp = enumvals, index = 0; enum_valp->name != NULL;
enum_valp++, index++) {
button = gtk_radio_button_new_with_label(rb_group,
enum_valp->name);
gtk_widget_show(button);
if (rb_group == NULL)
rb_group = gtk_radio_button_group(GTK_RADIO_BUTTON(button));
gtk_box_pack_start(GTK_BOX(radio_button_hbox), button, FALSE,
FALSE, 10);
if (enum_valp->value == current_val) {
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button),
TRUE);
}
}
gtk_widget_show(radio_button_hbox);
gtk_table_attach_defaults(GTK_TABLE(main_tb), radio_button_hbox, 1, 2,
table_position, table_position+1);
/*
* It doesn't matter which of the buttons we return - we fetch
* the value by looking at the entire radio button group to
* which it belongs, and we can get that from any button.
*/
return button;
}
static gint
label_to_enum_val(GtkWidget *label, const enum_val_t *enumvals)
{
char *label_string;
gint enumval;
/* Get the label's text, and translate it to a value. */
gtk_label_get(GTK_LABEL(label), &label_string);
enumval = find_val_for_string(label_string, enumvals, 1);
return enumval;
}
gint
fetch_preference_radio_buttons_val(GtkWidget *button,
const enum_val_t *enumvals)
{
GSList *rb_group;
GSList *rb_entry;
/*
* Go through the list of of radio buttons in the button's group,
* and find the first one that's active.
*/
rb_group = gtk_radio_button_group(GTK_RADIO_BUTTON(button));
button = NULL;
for (rb_entry = rb_group; rb_entry != NULL;
rb_entry = g_slist_next(rb_entry)) {
button = rb_entry->data;
if (GTK_TOGGLE_BUTTON(button)->active)
break;
}
/* OK, now return the value corresponding to that button's label. */
return label_to_enum_val(GTK_BIN(button)->child, enumvals);
}
GtkWidget *
create_preference_option_menu(GtkWidget *main_tb, int table_position,
const gchar *label_text, const enum_val_t *enumvals, gint current_val)
{
GtkWidget *label, *menu_box, *menu, *menu_item, *option_menu;
int menu_index, index;
const enum_val_t *enum_valp;
set_option_label(main_tb, table_position, label_text);
/* Create a menu from the enumvals */
menu = gtk_menu_new();
menu_index = -1;
for (enum_valp = enumvals, index = 0; enum_valp->name != NULL;
enum_valp++, index++) {
menu_item = gtk_menu_item_new_with_label(enum_valp->name);
gtk_menu_append(GTK_MENU(menu), menu_item);
if (enum_valp->value == current_val)
menu_index = index;
gtk_widget_show(menu_item);
}
/* Create the option menu from the menu */
option_menu = gtk_option_menu_new();
gtk_option_menu_set_menu(GTK_OPTION_MENU(option_menu), menu);
/* Set its current value to the variable's current value */
if (menu_index != -1)
gtk_option_menu_set_history(GTK_OPTION_MENU(option_menu),
menu_index);
/*
* Put the option menu in an hbox, so that it's only as wide
* as the widest entry, rather than being as wide as the table
* space.
*/
menu_box = gtk_hbox_new(FALSE, 0);
gtk_table_attach_defaults(GTK_TABLE(main_tb), menu_box,
1, 2, table_position, table_position + 1);
gtk_box_pack_start(GTK_BOX(menu_box), option_menu, FALSE, FALSE, 0);
return option_menu;
}
gint
fetch_preference_option_menu_val(GtkWidget *optmenu, const enum_val_t *enumvals)
{
/*
* OK, now return the value corresponding to the label for the
* currently active entry in the option menu.
*
* Yes, this is how you get the label for that entry. See FAQ
* 6.8 in the GTK+ FAQ.
*/
return label_to_enum_val(GTK_BIN(optmenu)->child, enumvals);
}
GtkWidget *
create_preference_entry(GtkWidget *main_tb, int table_position,
const gchar *label_text, char *value)
{
GtkWidget *entry;
set_option_label(main_tb, table_position, label_text);
entry = gtk_entry_new();
if (value != NULL)
gtk_entry_set_text(GTK_ENTRY(entry), value);
gtk_table_attach_defaults(GTK_TABLE(main_tb), entry, 1, 2,
table_position, table_position + 1);
gtk_widget_show(entry);
return entry;
}
static void
pref_fetch(pref_t *pref, gpointer user_data)
{
@ -500,28 +656,13 @@ pref_fetch(pref_t *pref, gpointer user_data)
case PREF_ENUM:
if (pref->info.enum_info.radio_buttons) {
/* Go through the list of of radio buttons in the group, and find
the first one that's active. */
button = NULL;
for (rb_entry = gtk_radio_button_group(GTK_RADIO_BUTTON(pref->control));
rb_entry != NULL;
rb_entry = g_slist_next(rb_entry)) {
button = rb_entry->data;
if (GTK_TOGGLE_BUTTON(button)->active)
break;
}
/* OK, now find that button's label. */
label = GTK_BIN(button)->child;
enumval = fetch_preference_radio_buttons_val(pref->control,
pref->info.enum_info.enumvals);
} else {
/* Get the label for the currently active entry in the option menu.
Yes, this is how you do it. See FAQ 6.8 in the GTK+ FAQ. */
label = GTK_BIN(pref->control)->child;
enumval = fetch_preference_option_menu_val(pref->control,
pref->info.enum_info.enumvals);
}
/* Get the label, and translate it to a value. */
gtk_label_get(GTK_LABEL(label), &label_string);
enumval = find_val_for_string(label_string,
pref->info.enum_info.enumvals, 1);
if (*pref->varp.enump != enumval) {
*pref_changed_p = TRUE;
*pref->varp.enump = enumval;
@ -609,6 +750,7 @@ prefs_main_ok_cb(GtkWidget *ok_bt, gpointer parent_w)
stream_prefs_fetch(gtk_object_get_data(GTK_OBJECT(parent_w), E_STREAM_PAGE_KEY));
gui_prefs_fetch(gtk_object_get_data(GTK_OBJECT(parent_w), E_GUI_PAGE_KEY));
capture_prefs_fetch(gtk_object_get_data(GTK_OBJECT(parent_w), E_CAPTURE_PAGE_KEY));
nameres_prefs_fetch(gtk_object_get_data(GTK_OBJECT(parent_w), E_NAMERES_PAGE_KEY));
prefs_module_foreach(module_prefs_fetch, &must_redissect);
/* Now apply those preferences. */
@ -617,6 +759,7 @@ prefs_main_ok_cb(GtkWidget *ok_bt, gpointer parent_w)
stream_prefs_apply(gtk_object_get_data(GTK_OBJECT(parent_w), E_STREAM_PAGE_KEY));
gui_prefs_apply(gtk_object_get_data(GTK_OBJECT(parent_w), E_GUI_PAGE_KEY));
capture_prefs_apply(gtk_object_get_data(GTK_OBJECT(parent_w), E_CAPTURE_PAGE_KEY));
nameres_prefs_apply(gtk_object_get_data(GTK_OBJECT(parent_w), E_NAMERES_PAGE_KEY));
prefs_apply_all();
/* Now destroy the "Preferences" dialog. */
@ -641,6 +784,7 @@ prefs_main_apply_cb(GtkWidget *apply_bt, gpointer parent_w)
stream_prefs_fetch(gtk_object_get_data(GTK_OBJECT(parent_w), E_STREAM_PAGE_KEY));
gui_prefs_fetch(gtk_object_get_data(GTK_OBJECT(parent_w), E_GUI_PAGE_KEY));
capture_prefs_fetch(gtk_object_get_data(GTK_OBJECT(parent_w), E_CAPTURE_PAGE_KEY));
nameres_prefs_fetch(gtk_object_get_data(GTK_OBJECT(parent_w), E_NAMERES_PAGE_KEY));
prefs_module_foreach(module_prefs_fetch, &must_redissect);
/* Now apply those preferences. */
@ -649,6 +793,7 @@ prefs_main_apply_cb(GtkWidget *apply_bt, gpointer parent_w)
stream_prefs_apply(gtk_object_get_data(GTK_OBJECT(parent_w), E_STREAM_PAGE_KEY));
gui_prefs_apply(gtk_object_get_data(GTK_OBJECT(parent_w), E_GUI_PAGE_KEY));
capture_prefs_apply(gtk_object_get_data(GTK_OBJECT(parent_w), E_CAPTURE_PAGE_KEY));
nameres_prefs_apply(gtk_object_get_data(GTK_OBJECT(parent_w), E_NAMERES_PAGE_KEY));
prefs_apply_all();
if (must_redissect) {
@ -673,6 +818,7 @@ prefs_main_save_cb(GtkWidget *save_bt, gpointer parent_w)
stream_prefs_fetch(gtk_object_get_data(GTK_OBJECT(parent_w), E_STREAM_PAGE_KEY));
gui_prefs_fetch(gtk_object_get_data(GTK_OBJECT(parent_w), E_GUI_PAGE_KEY));
capture_prefs_fetch(gtk_object_get_data(GTK_OBJECT(parent_w), E_CAPTURE_PAGE_KEY));
nameres_prefs_fetch(gtk_object_get_data(GTK_OBJECT(parent_w), E_NAMERES_PAGE_KEY));
prefs_module_foreach(module_prefs_fetch, &must_redissect);
/* Create the directory that holds personal configuration files, if
@ -711,6 +857,7 @@ prefs_main_save_cb(GtkWidget *save_bt, gpointer parent_w)
stream_prefs_apply(gtk_object_get_data(GTK_OBJECT(parent_w), E_STREAM_PAGE_KEY));
gui_prefs_apply(gtk_object_get_data(GTK_OBJECT(parent_w), E_GUI_PAGE_KEY));
capture_prefs_apply(gtk_object_get_data(GTK_OBJECT(parent_w), E_CAPTURE_PAGE_KEY));
nameres_prefs_apply(gtk_object_get_data(GTK_OBJECT(parent_w), E_NAMERES_PAGE_KEY));
prefs_apply_all();
if (must_redissect) {
@ -802,7 +949,7 @@ prefs_main_cancel_cb(GtkWidget *cancel_bt, gpointer parent_w)
column_prefs_apply(gtk_object_get_data(GTK_OBJECT(parent_w), E_COLUMN_PAGE_KEY));
stream_prefs_apply(gtk_object_get_data(GTK_OBJECT(parent_w), E_STREAM_PAGE_KEY));
gui_prefs_apply(gtk_object_get_data(GTK_OBJECT(parent_w), E_GUI_PAGE_KEY));
capture_prefs_apply(gtk_object_get_data(GTK_OBJECT(parent_w), E_CAPTURE_PAGE_KEY));
nameres_prefs_apply(gtk_object_get_data(GTK_OBJECT(parent_w), E_NAMERES_PAGE_KEY));
prefs_apply_all();
gtk_widget_destroy(GTK_WIDGET(parent_w));
@ -833,6 +980,7 @@ prefs_main_destroy_cb(GtkWidget *win, gpointer user_data)
stream_prefs_destroy(gtk_object_get_data(GTK_OBJECT(prefs_w), E_STREAM_PAGE_KEY));
gui_prefs_destroy(gtk_object_get_data(GTK_OBJECT(prefs_w), E_GUI_PAGE_KEY));
capture_prefs_destroy(gtk_object_get_data(GTK_OBJECT(prefs_w), E_CAPTURE_PAGE_KEY));
nameres_prefs_destroy(gtk_object_get_data(GTK_OBJECT(prefs_w), E_NAMERES_PAGE_KEY));
/* Free up the saved preferences (both for "prefs" and for registered
preferences). */
@ -909,4 +1057,3 @@ prefs_tree_select_cb(GtkCTree *ct, GtkCTreeNode *node, gint col, gpointer dummy)
if (page >= 0)
gtk_notebook_set_page(GTK_NOTEBOOK(notebook), page);
}

View File

@ -1,7 +1,7 @@
/* prefs_dlg.h
* Definitions for preference handling routines
*
* $Id: prefs_dlg.h,v 1.6 2002/01/11 07:40:31 guy Exp $
* $Id: prefs_dlg.h,v 1.7 2002/01/13 20:35:12 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -25,7 +25,17 @@
#ifndef __PREFS_DLG_H__
#define __PREFS_DLG_H__
void prefs_cb(GtkWidget *, gpointer);
void properties_cb(GtkWidget *, gpointer);
void prefs_cb(GtkWidget *, gpointer);
void properties_cb(GtkWidget *, gpointer);
GtkWidget *create_preference_check_button(GtkWidget *, int, const gchar *,
gboolean);
GtkWidget *create_preference_radio_buttons(GtkWidget *, int, const gchar *,
const enum_val_t *, gint);
gint fetch_preference_radio_buttons_val(GtkWidget *, const enum_val_t *);
GtkWidget *create_preference_option_menu(GtkWidget *, int, const gchar *,
const enum_val_t *, gint);
gint fetch_preference_option_menu_val(GtkWidget *, const enum_val_t *);
GtkWidget *create_preference_entry(GtkWidget *, int, const gchar *, char *);
#endif

View File

@ -1,7 +1,7 @@
/* print_prefs.c
* Dialog boxes for preferences for printing
*
* $Id: print_prefs.c,v 1.9 2002/01/11 07:40:31 guy Exp $
* $Id: print_prefs.c,v 1.10 2002/01/13 20:35:12 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -34,6 +34,7 @@
#include "keys.h"
#include "print.h"
#include "prefs.h"
#include "prefs_dlg.h"
#include "util.h"
#include "ui_util.h"
#include "dlg_utils.h"
@ -42,20 +43,29 @@ static void printer_opts_file_cb(GtkWidget *w, gpointer te);
static void printer_opts_fs_ok_cb(GtkWidget *w, gpointer data);
static void printer_opts_fs_cancel_cb(GtkWidget *w, gpointer data);
static void printer_opts_fs_destroy_cb(GtkWidget *win, gpointer data);
static void printer_opts_toggle_format(GtkWidget *widget, gpointer data);
static void printer_opts_toggle_dest(GtkWidget *widget, gpointer data);
#define E_FS_CALLER_PTR_KEY "fs_caller_ptr"
#define E_FILE_SEL_DIALOG_PTR_KEY "file_sel_dialog_ptr"
#define E_PRINT_FORMAT_KEY "print_format"
#define E_PRINT_DESTINATION_KEY "print_destination"
static const enum_val_t print_format_vals[] = {
{ "Plain Text", PR_FMT_TEXT },
{ "Postscript", PR_FMT_PS },
{ NULL, 0 }
};
static const enum_val_t print_dest_vals[] = {
{ "Command", PR_DEST_CMD },
{ "File", PR_DEST_FILE },
{ NULL, 0 }
};
GtkWidget * printer_prefs_show(void)
{
GtkWidget *main_vb, *main_tb, *button;
GtkWidget *format_hb, *format_lb;
GtkWidget *dest_hb, *dest_lb;
GtkWidget *cmd_lb, *cmd_te;
GtkWidget *cmd_te;
GtkWidget *file_bt_hb, *file_bt, *file_te;
GSList *format_grp, *dest_grp;
/* Enclosing containers for each row of widgets */
main_vb = gtk_vbox_new(FALSE, 5);
@ -68,70 +78,19 @@ GtkWidget * printer_prefs_show(void)
gtk_widget_show(main_tb);
/* Output format */
format_lb = gtk_label_new("Format:");
gtk_misc_set_alignment(GTK_MISC(format_lb), 1.0, 0.5);
gtk_table_attach_defaults(GTK_TABLE(main_tb), format_lb, 0, 1, 0, 1);
gtk_widget_show(format_lb);
format_hb = gtk_hbox_new(FALSE, 0);
gtk_table_attach_defaults(GTK_TABLE(main_tb), format_hb, 1, 2, 0, 1);
gtk_widget_show(format_hb);
button = gtk_radio_button_new_with_label(NULL, "Plain Text");
if (prefs.pr_format == PR_FMT_TEXT) {
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button), TRUE);
}
format_grp = gtk_radio_button_group(GTK_RADIO_BUTTON(button));
gtk_box_pack_start(GTK_BOX(format_hb), button, FALSE, FALSE, 10);
gtk_widget_show(button);
button = gtk_radio_button_new_with_label(format_grp, "PostScript");
if (prefs.pr_format == PR_FMT_PS) {
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button), TRUE);
}
gtk_signal_connect(GTK_OBJECT(button), "toggled",
GTK_SIGNAL_FUNC(printer_opts_toggle_format), NULL);
gtk_box_pack_start(GTK_BOX(format_hb), button, FALSE, FALSE, 10);
gtk_widget_show(button);
button = create_preference_radio_buttons(main_tb, 0, "Format:",
print_format_vals, prefs.pr_format);
gtk_object_set_data(GTK_OBJECT(main_vb), E_PRINT_FORMAT_KEY, button);
/* Output destination */
dest_lb = gtk_label_new("Print to:");
gtk_misc_set_alignment(GTK_MISC(dest_lb), 1.0, 0.5);
gtk_table_attach_defaults(GTK_TABLE(main_tb), dest_lb, 0, 1, 1, 2);
gtk_widget_show(dest_lb);
dest_hb = gtk_hbox_new(FALSE, 0);
gtk_table_attach_defaults(GTK_TABLE(main_tb), dest_hb, 1, 2, 1, 2);
gtk_widget_show(dest_hb);
button = gtk_radio_button_new_with_label(NULL, "Command");
if (prefs.pr_dest == PR_DEST_CMD) {
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button), TRUE);
}
dest_grp = gtk_radio_button_group(GTK_RADIO_BUTTON(button));
gtk_box_pack_start(GTK_BOX(dest_hb), button, FALSE, FALSE, 10);
gtk_widget_show(button);
button = gtk_radio_button_new_with_label(dest_grp, "File");
if (prefs.pr_dest == PR_DEST_FILE) {
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button), TRUE);
}
gtk_signal_connect(GTK_OBJECT(button), "toggled",
GTK_SIGNAL_FUNC(printer_opts_toggle_dest), NULL);
gtk_box_pack_start(GTK_BOX(dest_hb), button, FALSE, FALSE, 10);
gtk_widget_show(button);
button = create_preference_radio_buttons(main_tb, 1, "Print to:",
print_dest_vals, prefs.pr_dest);
gtk_object_set_data(GTK_OBJECT(main_vb), E_PRINT_DESTINATION_KEY,
button);
/* Command text entry */
cmd_lb = gtk_label_new("Command:");
gtk_misc_set_alignment(GTK_MISC(cmd_lb), 1.0, 0.5);
gtk_table_attach_defaults(GTK_TABLE(main_tb), cmd_lb, 0, 1, 2, 3);
gtk_widget_show(cmd_lb);
cmd_te = gtk_entry_new();
cmd_te = create_preference_entry(main_tb, 2, "Command:", prefs.pr_cmd);
gtk_object_set_data(GTK_OBJECT(main_vb), PRINT_CMD_TE_KEY, cmd_te);
if (prefs.pr_cmd) gtk_entry_set_text(GTK_ENTRY(cmd_te), prefs.pr_cmd);
gtk_table_attach_defaults(GTK_TABLE(main_tb), cmd_te, 1, 2, 2, 3);
gtk_widget_show(cmd_te);
/* File button and text entry */
file_bt_hb = gtk_hbox_new(FALSE, 0);
@ -236,19 +195,25 @@ printer_opts_fs_destroy_cb(GtkWidget *win, gpointer data)
void
printer_prefs_fetch(GtkWidget *w)
{
if (prefs.pr_cmd)
g_free(prefs.pr_cmd);
prefs.pr_cmd =
g_strdup(gtk_entry_get_text(
GTK_ENTRY(gtk_object_get_data(GTK_OBJECT(w),
PRINT_CMD_TE_KEY))));
prefs.pr_format = fetch_preference_radio_buttons_val(
gtk_object_get_data(GTK_OBJECT(w), E_PRINT_FORMAT_KEY),
print_format_vals);
if (prefs.pr_file)
g_free(prefs.pr_file);
prefs.pr_file =
g_strdup(gtk_entry_get_text(
GTK_ENTRY(gtk_object_get_data(GTK_OBJECT(w),
PRINT_FILE_TE_KEY))));
prefs.pr_dest = fetch_preference_radio_buttons_val(
gtk_object_get_data(GTK_OBJECT(w), E_PRINT_DESTINATION_KEY),
print_dest_vals);
if (prefs.pr_cmd)
g_free(prefs.pr_cmd);
prefs.pr_cmd = g_strdup(gtk_entry_get_text(
GTK_ENTRY(gtk_object_get_data(GTK_OBJECT(w),
PRINT_CMD_TE_KEY))));
if (prefs.pr_file)
g_free(prefs.pr_file);
prefs.pr_file = g_strdup(gtk_entry_get_text(
GTK_ENTRY(gtk_object_get_data(GTK_OBJECT(w),
PRINT_FILE_TE_KEY))));
}
void
@ -271,27 +236,3 @@ printer_prefs_destroy(GtkWidget *w)
gtk_widget_destroy(fs);
}
}
static void
printer_opts_toggle_format(GtkWidget *widget, gpointer data)
{
if (GTK_TOGGLE_BUTTON (widget)->active) {
prefs.pr_format = PR_FMT_PS;
/* toggle file/cmd */
}
else {
prefs.pr_format = PR_FMT_TEXT;
/* toggle file/cmd */
}
}
static void
printer_opts_toggle_dest(GtkWidget *widget, gpointer data)
{
if (GTK_TOGGLE_BUTTON (widget)->active) {
prefs.pr_dest = PR_DEST_FILE;
}
else {
prefs.pr_dest = PR_DEST_CMD;
}
}

View File

@ -1,7 +1,7 @@
/* ipproto.c
* Routines for converting IPv4 protocol/v6 nxthdr field into string
*
* $Id: ipproto.c,v 1.15 2001/11/13 23:55:29 gram Exp $
* $Id: ipproto.c,v 1.16 2002/01/13 20:35:08 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -42,7 +42,7 @@
#include "ipproto.h"
#include "packet.h"
#include "prefs.h"
#include "resolv.h"
#include "packet-ip.h"
static const value_string ipproto_val[] = {
@ -102,7 +102,11 @@ const char *ipprotostr(int proto) {
goto ok;
#ifdef HAVE_GETPROTOBYNUMBER
if (prefs.name_resolve) {
/*
* XXX - have another flag for resolving network-layer
* protocol names?
*/
if (g_resolv_flags != 0) {
pe = getprotobynumber(proto);
if (pe) {
s = pe->p_name;

21
prefs.c
View File

@ -1,7 +1,7 @@
/* prefs.c
* Routines for handling preferences
*
* $Id: prefs.c,v 1.76 2002/01/10 07:43:37 guy Exp $
* $Id: prefs.c,v 1.77 2002/01/13 20:35:08 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -42,6 +42,7 @@
#include <glib.h>
#include <filesystem.h>
#include <resolv.h>
#include "globals.h"
#include "packet.h"
#include "file.h"
@ -805,7 +806,7 @@ read_prefs(int *gpf_errno_return, char **gpf_path_return,
prefs.capture_prom_mode = TRUE;
prefs.capture_real_time = FALSE;
prefs.capture_auto_scroll = FALSE;
prefs.name_resolve = PREFS_RESOLV_ALL;
prefs.name_resolve = RESOLV_ALL;
}
/* Construct the pathname of the global preferences file. */
@ -1092,9 +1093,9 @@ typedef struct {
} name_resolve_opt_t;
static name_resolve_opt_t name_resolve_opt[] = {
{ 'm', PREFS_RESOLV_MAC },
{ 'n', PREFS_RESOLV_NETWORK },
{ 't', PREFS_RESOLV_TRANSPORT },
{ 'm', RESOLV_MAC },
{ 'n', RESOLV_NETWORK },
{ 't', RESOLV_TRANSPORT },
};
#define N_NAME_RESOLVE_OPT (sizeof name_resolve_opt / sizeof name_resolve_opt[0])
@ -1107,7 +1108,7 @@ name_resolve_to_string(guint32 name_resolve)
unsigned int i;
gboolean all_opts_set = TRUE;
if (name_resolve == PREFS_RESOLV_NONE)
if (name_resolve == RESOLV_NONE)
return "FALSE";
p = &string[0];
for (i = 0; i < N_NAME_RESOLVE_OPT; i++) {
@ -1340,16 +1341,16 @@ set_pref(gchar *pref_name, gchar *value)
strcmp(pref_name, PRS_CAP_NAME_RESOLVE) == 0) {
/*
* "TRUE" and "FALSE", for backwards compatibility, are synonyms for
* PREFS_RESOLV_ALL and PREFS_RESOLV_NONE.
* RESOLV_ALL and RESOLV_NONE.
*
* Otherwise, we treat it as a list of name types we want to resolve.
*/
if (strcasecmp(value, "true") == 0)
prefs.name_resolve = PREFS_RESOLV_ALL;
prefs.name_resolve = RESOLV_ALL;
else if (strcasecmp(value, "false") == 0)
prefs.name_resolve = PREFS_RESOLV_NONE;
prefs.name_resolve = RESOLV_NONE;
else {
prefs.name_resolve = PREFS_RESOLV_NONE; /* start out with none set */
prefs.name_resolve = RESOLV_NONE; /* start out with none set */
if (string_to_name_resolve(value, &prefs.name_resolve) != '\0')
return PREFS_SET_SYNTAX_ERR;
}

11
prefs.h
View File

@ -1,7 +1,7 @@
/* prefs.h
* Definitions for preference handling routines
*
* $Id: prefs.h,v 1.36 2002/01/10 07:43:37 guy Exp $
* $Id: prefs.h,v 1.37 2002/01/13 20:35:08 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -35,15 +35,6 @@
#define DEF_WIDTH 750
#define DEF_HEIGHT 550
/* 32 types are sufficient (as are 640k of RAM) */
/* FIXME: Maybe MANUF/m, IP/i, IP6/6, IPX/x, UDP+TCP/t etc would be
more useful/consistent */
#define PREFS_RESOLV_NONE 0x0
#define PREFS_RESOLV_MAC 0x1
#define PREFS_RESOLV_NETWORK 0x2
#define PREFS_RESOLV_TRANSPORT 0x4
#define PREFS_RESOLV_ALL 0xFFFFFFFF
/*
* Convert a string listing name resolution types to a bitmask of
* those types.

View File

@ -1,6 +1,6 @@
/* tethereal.c
*
* $Id: tethereal.c,v 1.116 2002/01/11 11:04:03 guy Exp $
* $Id: tethereal.c,v 1.117 2002/01/13 20:35:08 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -325,6 +325,9 @@ main(int argc, char *argv[])
strerror(pf_open_errno));
}
/* Set the name resolution code's flags from the preferences. */
g_resolv_flags = prefs->name_resolve;
#ifdef WIN32
/* Load Wpcap, if possible */
load_wpcap();
@ -511,12 +514,12 @@ main(int argc, char *argv[])
line_buffered = TRUE;
break;
case 'n': /* No name resolution */
prefs->name_resolve = PREFS_RESOLV_NONE;
g_resolv_flags = RESOLV_NONE;
break;
case 'N': /* Select what types of addresses/port #s to resolve */
if (prefs->name_resolve == PREFS_RESOLV_ALL)
prefs->name_resolve = PREFS_RESOLV_NONE;
badopt = string_to_name_resolve(optarg, &prefs->name_resolve);
if (g_resolv_flags == RESOLV_ALL)
g_resolv_flags = RESOLV_NONE;
badopt = string_to_name_resolve(optarg, &g_resolv_flags);
if (badopt != '\0') {
fprintf(stderr, "tethereal: -N specifies unknown resolving option '%c'; valid options are 'm', 'n', and 't'\n",
badopt);