diff options
-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | Makefile.in | 44 | ||||
-rw-r--r-- | VERSION | 2 | ||||
-rw-r--r-- | aclocal.m4 | 5 | ||||
-rw-r--r-- | column.c | 644 | ||||
-rw-r--r-- | column.h | 44 | ||||
-rwxr-xr-x | configure | 109 | ||||
-rw-r--r-- | configure.in | 4 | ||||
-rw-r--r-- | ethereal.c | 62 | ||||
-rw-r--r-- | ethereal.h | 51 | ||||
-rw-r--r-- | ethertype.c | 4 | ||||
-rw-r--r-- | file.c | 16 | ||||
-rw-r--r-- | file.h | 5 | ||||
-rw-r--r-- | filter.c | 11 | ||||
-rw-r--r-- | image/dn_arrow.xpm | 21 | ||||
-rw-r--r-- | image/up_arrow.xpm | 21 | ||||
-rw-r--r-- | packet-aarp.c | 37 | ||||
-rw-r--r-- | packet-arp.c | 28 | ||||
-rw-r--r-- | packet-atalk.c | 15 | ||||
-rw-r--r-- | packet-bootp.c | 11 | ||||
-rw-r--r-- | packet-dns.c | 10 | ||||
-rw-r--r-- | packet-eth.c | 22 | ||||
-rw-r--r-- | packet-fddi.c | 19 | ||||
-rw-r--r-- | packet-ip.c | 65 | ||||
-rw-r--r-- | packet-ipv6.c | 33 | ||||
-rw-r--r-- | packet-ipx.c | 46 | ||||
-rw-r--r-- | packet-llc.c | 14 | ||||
-rw-r--r-- | packet-lpd.c | 11 | ||||
-rw-r--r-- | packet-nbipx.c | 15 | ||||
-rw-r--r-- | packet-nbns.c | 11 | ||||
-rw-r--r-- | packet-ncp.c | 10 | ||||
-rw-r--r-- | packet-null.c | 16 | ||||
-rw-r--r-- | packet-osi.c | 115 | ||||
-rw-r--r-- | packet-ospf.c | 11 | ||||
-rw-r--r-- | packet-ppp.c | 19 | ||||
-rw-r--r-- | packet-raw.c | 15 | ||||
-rw-r--r-- | packet-rip.c | 10 | ||||
-rw-r--r-- | packet-tcp.c | 10 | ||||
-rw-r--r-- | packet-tr.c | 16 | ||||
-rw-r--r-- | packet-trmac.c | 10 | ||||
-rw-r--r-- | packet-udp.c | 10 | ||||
-rw-r--r-- | packet-vines.c | 76 | ||||
-rw-r--r-- | packet.c | 57 | ||||
-rw-r--r-- | packet.h | 30 | ||||
-rw-r--r-- | prefs.c | 235 | ||||
-rw-r--r-- | prefs.h | 20 | ||||
-rwxr-xr-x | wiretap/configure | 41 |
47 files changed, 1557 insertions, 526 deletions
diff --git a/Makefile.am b/Makefile.am index 70506332cc..d1c331da47 100644 --- a/Makefile.am +++ b/Makefile.am @@ -6,6 +6,7 @@ sysconf_DATA = manuf ethereal_SOURCES = \ capture.c \ + column.c \ ethereal.c \ ethertype.c \ file.c \ @@ -46,6 +47,7 @@ ethereal_SOURCES = \ resolv.c \ util.c \ capture.h \ + column.h \ config.h \ ethereal.h \ etypes.h \ diff --git a/Makefile.in b/Makefile.in index 1678de55ef..3c25e1a492 100644 --- a/Makefile.in +++ b/Makefile.in @@ -80,6 +80,7 @@ sysconf_DATA = manuf ethereal_SOURCES = \ capture.c \ + column.c \ ethereal.c \ ethertype.c \ file.c \ @@ -120,6 +121,7 @@ ethereal_SOURCES = \ resolv.c \ util.c \ capture.h \ + column.h \ config.h \ ethereal.h \ etypes.h \ @@ -175,14 +177,14 @@ DEFS = @DEFS@ -I. -I$(srcdir) -I. CPPFLAGS = @CPPFLAGS@ LDFLAGS = @LDFLAGS@ LIBS = @LIBS@ -ethereal_OBJECTS = capture.o ethereal.o ethertype.o file.o filter.o \ -follow.o menu.o packet.o packet-aarp.o packet-arp.o packet-atalk.o \ -packet-bootp.o packet-data.o packet-dns.o packet-eth.o packet-fddi.o \ -packet-llc.o packet-lpd.o packet-ip.o packet-ipv6.o packet-ipx.o \ -packet-nbipx.o packet-nbns.o packet-ncp.o packet-null.o packet-osi.o \ -packet-ospf.o packet-ppp.o packet-raw.o packet-rip.o packet-tcp.o \ -packet-tr.o packet-trmac.o packet-udp.o packet-vines.o prefs.o print.o \ -ps.o resolv.o util.o +ethereal_OBJECTS = capture.o column.o ethereal.o ethertype.o file.o \ +filter.o follow.o menu.o packet.o packet-aarp.o packet-arp.o \ +packet-atalk.o packet-bootp.o packet-data.o packet-dns.o packet-eth.o \ +packet-fddi.o packet-llc.o packet-lpd.o packet-ip.o packet-ipv6.o \ +packet-ipx.o packet-nbipx.o packet-nbns.o packet-ncp.o packet-null.o \ +packet-osi.o packet-ospf.o packet-ppp.o packet-raw.o packet-rip.o \ +packet-tcp.o packet-tr.o packet-trmac.o packet-udp.o packet-vines.o \ +prefs.o print.o ps.o resolv.o util.o ethereal_LDFLAGS = CFLAGS = @CFLAGS@ COMPILE = $(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) @@ -203,19 +205,19 @@ DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) TAR = tar GZIP = --best -DEP_FILES = .deps/capture.P .deps/ethereal.P .deps/ethertype.P \ -.deps/file.P .deps/filter.P .deps/follow.P .deps/menu.P \ -.deps/packet-aarp.P .deps/packet-arp.P .deps/packet-atalk.P \ -.deps/packet-bootp.P .deps/packet-data.P .deps/packet-dns.P \ -.deps/packet-eth.P .deps/packet-fddi.P .deps/packet-ip.P \ -.deps/packet-ipv6.P .deps/packet-ipx.P .deps/packet-llc.P \ -.deps/packet-lpd.P .deps/packet-nbipx.P .deps/packet-nbns.P \ -.deps/packet-ncp.P .deps/packet-null.P .deps/packet-osi.P \ -.deps/packet-ospf.P .deps/packet-ppp.P .deps/packet-raw.P \ -.deps/packet-rip.P .deps/packet-tcp.P .deps/packet-tr.P \ -.deps/packet-trmac.P .deps/packet-udp.P .deps/packet-vines.P \ -.deps/packet.P .deps/prefs.P .deps/print.P .deps/ps.P .deps/resolv.P \ -.deps/snprintf.P .deps/util.P +DEP_FILES = .deps/capture.P .deps/column.P .deps/ethereal.P \ +.deps/ethertype.P .deps/file.P .deps/filter.P .deps/follow.P \ +.deps/menu.P .deps/packet-aarp.P .deps/packet-arp.P \ +.deps/packet-atalk.P .deps/packet-bootp.P .deps/packet-data.P \ +.deps/packet-dns.P .deps/packet-eth.P .deps/packet-fddi.P \ +.deps/packet-ip.P .deps/packet-ipv6.P .deps/packet-ipx.P \ +.deps/packet-llc.P .deps/packet-lpd.P .deps/packet-nbipx.P \ +.deps/packet-nbns.P .deps/packet-ncp.P .deps/packet-null.P \ +.deps/packet-osi.P .deps/packet-ospf.P .deps/packet-ppp.P \ +.deps/packet-raw.P .deps/packet-rip.P .deps/packet-tcp.P \ +.deps/packet-tr.P .deps/packet-trmac.P .deps/packet-udp.P \ +.deps/packet-vines.P .deps/packet.P .deps/prefs.P .deps/print.P \ +.deps/ps.P .deps/resolv.P .deps/snprintf.P .deps/util.P SOURCES = $(ethereal_SOURCES) $(EXTRA_ethereal_SOURCES) OBJECTS = $(ethereal_OBJECTS) @@ -1 +1 @@ -0.4.1 +0.4.2 diff --git a/aclocal.m4 b/aclocal.m4 index aa8e872e78..9192f53645 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -244,13 +244,10 @@ int main () { int major, minor, micro; - char *tmp_version; system ("touch conf.gtktest"); - /* HP/UX 9 (%@#!) writes to sscanf strings */ - tmp_version = g_strdup("$min_gtk_version"); - if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, µ) != 3) { + if (sscanf("$min_gtk_version", "%d.%d.%d", &major, &minor, µ) != 3) { printf("%s, bad version string\n", "$min_gtk_version"); exit(1); } diff --git a/column.c b/column.c new file mode 100644 index 0000000000..418c60d18c --- /dev/null +++ b/column.c @@ -0,0 +1,644 @@ +/* column.c + * Routines for handling column preferences + * + * $Id: column.c,v 1.1 1998/11/17 04:28:40 gerald 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. + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#ifdef HAVE_SYS_TYPES_H +#include <sys/types.h> +#endif + +#include <gtk/gtk.h> + +#include <ctype.h> +#include <errno.h> +#include <unistd.h> +#include <sys/stat.h> + +#include "ethereal.h" +#include "prefs.h" +#include "column.h" + +extern e_prefs prefs; + +static GtkWidget *column_l, *chg_bt, *del_bt, *title_te, *fmt_m, *up_bt, + *dn_bt; +static gint cur_fmt; + +#define E_COL_NAME_KEY "column_name" +#define E_COL_LBL_KEY "column_label" +#define E_COL_CM_KEY "in_col_cancel_mode" + +static gchar *col_format_to_string(gint); +static gchar *col_format_desc(gint); +static gint get_column_format_from_str(gchar *str); +static void column_sel_list_cb(GtkWidget *, gpointer); +static void column_sel_new_cb(GtkWidget *, gpointer); +static void column_sel_chg_cb(GtkWidget *, gpointer); +static void column_sel_del_cb(GtkWidget *, gpointer); +static void column_sel_arrow_cb(GtkWidget *, gpointer); +static void column_set_fmt_cb(GtkWidget *, gpointer); + +/* Given a format number (as defined in ethereal.h), returns its equivalent + string */ +static gchar * +col_format_to_string(gint fmt) { + gchar *slist[] = { "%m", "%t", "%t", "%t", "%s", "%rs", "%us", "%hs", + "%rhs", "%uhs", "%ns", "%rns", "%uns", "%d", "%rd", + "%ud", "%hd", "%rhd", "%uhd", "%nd", "%rnd", "%und", + "%S", "%rS", "%uS", "%D", "%rD", "%uD", "%p", "%i" }; + + if (fmt < 0 || fmt > NUM_COL_FMTS) + return NULL; + + return(slist[fmt]); +} + +/* Given a format number (as defined in ethereal.h), returns its + description */ +static gchar * +col_format_desc(gint fmt) { + gchar *dlist[] = { "Number", "Relative time", "Absolute time", + "Delta time", "Source address", "Src addr (resolved)", + "Src addr (unresolved)", "Hardware src addr", + "Hw src addr (resolved)", "Hw src addr (unresolved)", + "Network src addr", "Net scr addr (resolved)", + "Net src addr (unresolved)", "Destination address", + "Dest addr (resolved)", "Dest addr (unresolved)", + "Hardware dest addr", "Hw dest addr (resolved)", + "Hw dest addr (unresolved)", "Network dest addr", + "Net dest addr (resolved)", "Net dest addr (unresolved)", + "Source port", "Src port (resolved)", + "Src port (unresolved)", "Destination port", + "Dest port (resolved)", "Dest port (unresolved)", + "Protocol", "Information" }; + + if (fmt < 0 || fmt > NUM_COL_FMTS) + return NULL; + + return(dlist[fmt]); +} + +/* Marks each array element true if it can be substituted for the given + column format */ +void +get_column_format_matches(gboolean *fmt_list, gint format) { + int i; + + for (i = 0; i < NUM_COL_FMTS; i++) { + /* Get the obvious: the format itself */ + if (i == format) + fmt_list[i] = TRUE; + /* Get any formats lower down on the chain */ + switch (format) { + case COL_DEF_SRC: + fmt_list[COL_RES_DL_SRC] = TRUE; + fmt_list[COL_RES_NET_SRC] = TRUE; + break; + case COL_RES_SRC: + fmt_list[COL_RES_DL_SRC] = TRUE; + fmt_list[COL_RES_NET_SRC] = TRUE; + break; + case COL_UNRES_SRC: + fmt_list[COL_UNRES_DL_SRC] = TRUE; + fmt_list[COL_UNRES_NET_SRC] = TRUE; + break; + case COL_DEF_DST: + fmt_list[COL_RES_DL_DST] = TRUE; + fmt_list[COL_RES_NET_DST] = TRUE; + break; + case COL_RES_DST: + fmt_list[COL_RES_DL_DST] = TRUE; + fmt_list[COL_RES_NET_DST] = TRUE; + break; + case COL_UNRES_DST: + fmt_list[COL_UNRES_DL_DST] = TRUE; + fmt_list[COL_UNRES_NET_DST] = TRUE; + break; + case COL_DEF_DL_SRC: + fmt_list[COL_RES_DL_SRC] = TRUE; + break; + case COL_DEF_DL_DST: + fmt_list[COL_RES_DL_DST] = TRUE; + break; + case COL_DEF_NET_SRC: + fmt_list[COL_RES_NET_SRC] = TRUE; + break; + case COL_DEF_NET_DST: + fmt_list[COL_RES_NET_DST] = TRUE; + break; + default: + break; + } + } +} + +/* Returns the longest possible width for a particular column type */ +gint +get_column_width(gint format, GdkFont *font) { + switch (format) { + case COL_NUMBER: + return (gdk_string_width(font, "0") * 7); + break; + case COL_ABS_TIME: + return (gdk_string_width(font, "00:00:00.000000")); + break; + case COL_REL_TIME: + case COL_DELTA_TIME: + return (gdk_string_width(font, "0000.000000")); + break; + case COL_DEF_SRC: + case COL_RES_SRC: + case COL_UNRES_SRC: + case COL_DEF_DL_SRC: + case COL_RES_DL_SRC: + case COL_UNRES_DL_SRC: + case COL_DEF_NET_SRC: + case COL_RES_NET_SRC: + case COL_UNRES_NET_SRC: + case COL_DEF_DST: + case COL_RES_DST: + case COL_UNRES_DST: + case COL_DEF_DL_DST: + case COL_RES_DL_DST: + case COL_UNRES_DL_DST: + case COL_DEF_NET_DST: + case COL_RES_NET_DST: + case COL_UNRES_NET_DST: + return (gdk_string_width(font, "00:00:00:00:00:00")); + break; + case COL_DEF_SRC_PORT: + case COL_RES_SRC_PORT: + case COL_UNRES_SRC_PORT: + case COL_DEF_DST_PORT: + case COL_RES_DST_PORT: + case COL_UNRES_DST_PORT: + return (gdk_string_width(font, "0") * 6); + break; + case COL_PROTOCOL: + return (gdk_string_width(font, "NBNS (UDP)")); + break; + default: /* COL_INFO */ + return (gdk_string_width(font, "Source port: kerberos-master " + "Destination port: kerberos-master")); + break; + } +} + +#define RES_DEF 0 +#define RES_DO 1 +#define RES_DONT 2 + +#define ADDR_DEF 0 +#define ADDR_DL 3 +#define ADDR_NET 6 + +gint +get_column_format(gint col) { + fmt_data *cfmt = (g_list_nth(prefs.col_list, col))->data; + + return(get_column_format_from_str(cfmt->fmt)); +} + +static gint +get_column_format_from_str(gchar *str) { + gchar *cptr = str, last_char = '\0'; + gboolean in_fmt = FALSE; + gint res_off = RES_DEF, addr_off = ADDR_DEF; + + /* To do: Make this parse %-formatted strings "for real" */ + while (*cptr != '\0') { + switch (*cptr) { + case 't': /* To do: fix for absolute and delta */ + return COL_REL_TIME; + break; + case 'm': + return COL_NUMBER; + break; + case 's': + return COL_DEF_SRC + res_off + addr_off; + break; + case 'd': + return COL_DEF_DST + res_off + addr_off; + break; + case 'S': + return COL_DEF_SRC_PORT + res_off; + break; + case 'D': + return COL_DEF_DST_PORT + res_off; + break; + case 'p': + return COL_PROTOCOL; + break; + case 'i': + return COL_INFO; + break; + case 'r': + res_off = RES_DO; + break; + case 'u': + res_off = RES_DONT; + break; + case 'h': + addr_off = ADDR_DL; + break; + case 'n': + addr_off = ADDR_NET; + break; + } + cptr++; + } + return COL_NUMBER; +} + +gchar * +get_column_title(gint col) { + fmt_data *cfmt = (g_list_nth(prefs.col_list, col))->data; + + return(cfmt->title); +} + +#define MAX_FMT_PREF_LEN 1024 +#define MAX_FMT_PREF_LINE_LEN 60 +gchar * +col_format_to_pref_str() { + static gchar pref_str[MAX_FMT_PREF_LEN] = ""; + GList *clp = g_list_first(prefs.col_list); + fmt_data *cfmt; + int cur_pos = 0, cur_len = 0, fmt_len; + + while (clp) { + cfmt = (fmt_data *) clp->data; + + fmt_len = strlen(cfmt->title) + 4; + if ((fmt_len + cur_len) < (MAX_FMT_PREF_LEN - 1)) { + if ((fmt_len + cur_pos) > MAX_FMT_PREF_LINE_LEN) { + cur_len--; + cur_pos = 0; + pref_str[cur_len] = '\n'; cur_len++; + pref_str[cur_len] = '\t'; cur_len++; + } + sprintf(&pref_str[cur_len], "\"%s\", ", cfmt->title); + cur_len += fmt_len; + cur_pos += fmt_len; + } + + fmt_len = strlen(cfmt->fmt) + 4; + if ((fmt_len + cur_len) < (MAX_FMT_PREF_LEN - 1)) { + if ((fmt_len + cur_pos) > MAX_FMT_PREF_LINE_LEN) { + cur_len--; + cur_pos = 0; + pref_str[cur_len] = '\n'; cur_len++; + pref_str[cur_len] = '\t'; cur_len++; + } + sprintf(&pref_str[cur_len], "\"%s\", ", cfmt->fmt); + cur_len += fmt_len; + cur_pos += fmt_len; + } + + clp = clp->next; + } + + if (cur_len > 2) + pref_str[cur_len - 2] = '\0'; + + return(pref_str); +} + +/* Create and display the column selection widgets. */ +/* Called when the 'Columns' preference notebook page is selected. */ +GtkWidget * +column_prefs_show() { + GtkWidget *main_vb, *top_hb, *list_bb, *new_bt, *column_sc, *nl_item, + *nl_lb, *tb, *lb, *bottom_hb, *column_lb, *menu, *mitem, + *arrow_hb, *arrow_pm; + GtkWidget *l_select = NULL; + GList *clp = NULL; + fmt_data *cfmt; + gchar *column_te_str = NULL, **arrow; + gint i; + GdkPixmap *pm; + GdkBitmap *mask; + GtkStyle *style; + GdkColormap *cmap; + + + /* Container for each row of widgets */ + main_vb = gtk_vbox_new(FALSE, 5); + gtk_container_border_width(GTK_CONTAINER(main_vb), 5); + gtk_widget_show(main_vb); + gtk_object_set_data(GTK_OBJECT(main_vb), E_COL_CM_KEY, (gpointer)FALSE); + + /* Top row: Column list and buttons */ + top_hb = gtk_hbox_new(FALSE, 5); + gtk_container_add(GTK_CONTAINER(main_vb), top_hb); + gtk_widget_show(top_hb); + + list_bb = gtk_vbutton_box_new(); + gtk_button_box_set_layout (GTK_BUTTON_BOX (list_bb), GTK_BUTTONBOX_START); + gtk_container_add(GTK_CONTAINER(top_hb), list_bb); + gtk_widget_show(list_bb); + + new_bt = gtk_button_new_with_label ("New"); + gtk_signal_connect(GTK_OBJECT(new_bt), "clicked", + GTK_SIGNAL_FUNC(column_sel_new_cb), NULL); + gtk_container_add(GTK_CONTAINER(list_bb), new_bt); + gtk_widget_show(new_bt); + + chg_bt = gtk_button_new_with_label ("Change"); + gtk_widget_set_sensitive(chg_bt, FALSE); + gtk_signal_connect(GTK_OBJECT(chg_bt), "clicked", + GTK_SIGNAL_FUNC(column_sel_chg_cb), NULL); + gtk_container_add(GTK_CONTAINER(list_bb), chg_bt); + gtk_widget_show(chg_bt); + + del_bt = gtk_button_new_with_label ("Delete"); + gtk_widget_set_sensitive(del_bt, FALSE); + gtk_signal_connect(GTK_OBJECT(del_bt), "clicked", + GTK_SIGNAL_FUNC(column_sel_del_cb), NULL); + gtk_container_add(GTK_CONTAINER(list_bb), del_bt); + gtk_widget_show(del_bt); + + arrow_hb = gtk_hbox_new(TRUE, 3); + gtk_container_add(GTK_CONTAINER(list_bb), arrow_hb); + gtk_widget_show(arrow_hb); + + up_bt = gtk_button_new_with_label("Up"); + gtk_widget_set_sensitive(up_bt, FALSE); + gtk_signal_connect(GTK_OBJECT(up_bt), "clicked", + GTK_SIGNAL_FUNC(column_sel_arrow_cb), NULL); + gtk_box_pack_start(GTK_BOX(arrow_hb), up_bt, TRUE, TRUE, 0); + gtk_widget_show(up_bt); + + dn_bt = gtk_button_new_with_label("Down"); + gtk_widget_set_sensitive(dn_bt, FALSE); + gtk_signal_connect(GTK_OBJECT(dn_bt), "clicked", + GTK_SIGNAL_FUNC(column_sel_arrow_cb), NULL); + gtk_box_pack_start(GTK_BOX(arrow_hb), dn_bt, TRUE, TRUE, 0); + gtk_widget_show(dn_bt); + + column_sc = gtk_scrolled_window_new(NULL, NULL); + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(column_sc), + GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + gtk_widget_set_usize(column_sc, 250, 150); + gtk_container_add(GTK_CONTAINER(top_hb), column_sc); + gtk_widget_show(column_sc); + + column_l = gtk_list_new(); + gtk_list_set_selection_mode(GTK_LIST(column_l), GTK_SELECTION_SINGLE); + gtk_signal_connect(GTK_OBJECT(column_l), "selection_changed", + GTK_SIGNAL_FUNC(column_sel_list_cb), main_vb); + gtk_container_add(GTK_CONTAINER(column_sc), column_l); + gtk_widget_show(column_l); + + clp = g_list_first(prefs.col_list); + while (clp) { + cfmt = (fmt_data *) clp->data; + nl_lb = gtk_label_new(cfmt->title); + nl_item = gtk_list_item_new(); + gtk_misc_set_alignment (GTK_MISC (nl_lb), 0.0, 0.5); + gtk_container_add(GTK_CONTAINER(nl_item), nl_lb); + gtk_widget_show(nl_lb); + gtk_container_add(GTK_CONTAINER(column_l), nl_item); + gtk_widget_show(nl_item); + gtk_object_set_data(GTK_OBJECT(nl_item), E_COL_LBL_KEY, nl_lb); + gtk_object_set_data(GTK_OBJECT(nl_item), E_COL_NAME_KEY, clp); + + clp = clp->next; + } + + /* Colunm name entry and format selection */ + tb = gtk_table_new(2, 2, FALSE); + gtk_container_add(GTK_CONTAINER(main_vb), tb); + gtk_table_set_row_spacings(GTK_TABLE(tb), 10); + gtk_table_set_col_spacings(GTK_TABLE(tb), 15); + gtk_widget_show(tb); + + lb = gtk_label_new("Column title:"); + gtk_misc_set_alignment(GTK_MISC(lb), 1.0, 0.5); + gtk_table_attach_defaults(GTK_TABLE(tb), lb, 0, 1, 0, 1); + gtk_widget_show(lb); + + title_te = gtk_entry_new(); + gtk_table_attach_defaults(GTK_TABLE(tb), title_te, 1, 2, 0, 1); + gtk_widget_show(title_te); + + lb = gtk_label_new("Column format:"); + gtk_misc_set_alignment(GTK_MISC(lb), 1.0, 0.5); + gtk_table_attach_defaults(GTK_TABLE(tb), lb, 0, 1, 1, 2); + gtk_widget_show(lb); + + fmt_m = gtk_option_menu_new(); + menu = gtk_menu_new(); + for (i = 0; i < NUM_COL_FMTS; i++) { + mitem = gtk_menu_item_new_with_label(col_format_desc(i)); + gtk_menu_append(GTK_MENU(menu), mitem); + gtk_signal_connect_object( GTK_OBJECT(mitem), "activate", + GTK_SIGNAL_FUNC(column_set_fmt_cb), (gpointer) i); + gtk_widget_show(mitem); + } + gtk_option_menu_set_menu(GTK_OPTION_MENU(fmt_m), menu); + cur_fmt = 0; + gtk_option_menu_set_history(GTK_OPTION_MENU(fmt_m), cur_fmt); + gtk_table_attach_defaults(GTK_TABLE(tb), fmt_m, 1, 2, 1, 2); + gtk_widget_show(fmt_m); + + return(main_vb); +} + +static void +column_sel_list_cb(GtkWidget *l, gpointer data) { + fmt_data *cfmt; + gchar *title = ""; + GList *sl, *clp; + GtkObject *l_item; + gint sensitivity = FALSE, up_sens = FALSE, dn_sens = FALSE; + + sl = GTK_LIST(l)->selection; + + if (sl) { /* Something was selected */ + l_item = GTK_OBJECT(sl->data); + clp = (GList *) gtk_object_get_data(l_item, E_COL_NAME_KEY); + if (clp) { + cfmt = (fmt_data *) clp->data; + title = cfmt->title; + cur_fmt = get_column_format_from_str(cfmt->fmt); + gtk_option_menu_set_history(GTK_OPTION_MENU(fmt_m), cur_fmt); + sensitivity = TRUE; + if (clp != g_list_first(prefs.col_list)) + up_sens = TRUE; + if (clp != g_list_last(prefs.col_list)) + dn_sens = TRUE; + } + } + + /* Did you know that this function is called when the window is destroyed? */ + /* Funny, that. */ + if (!gtk_object_get_data(GTK_OBJECT(data), E_COL_CM_KEY)) { + gtk_entry_set_text(GTK_ENTRY(title_te), title); + gtk_widget_set_sensitive(chg_bt, sensitivity); + gtk_widget_set_sensitive(del_bt, sensitivity); + gtk_widget_set_sensitive(up_bt, up_sens); + gtk_widget_set_sensitive(dn_bt, dn_sens); + } +} + +/* To do: add input checking to each of these callbacks */ + +static void +column_sel_new_cb(GtkWidget *w, gpointer data) { + fmt_data *cfmt; + gchar *title; + GtkWidget *nl_item, *nl_lb; + + title = gtk_entry_get_text(GTK_ENTRY(title_te)); + + if (strlen(title) > 0) { + cfmt = (fmt_data *) g_malloc(sizeof(fmt_data)); + cfmt->title = g_strdup(title); + cfmt->fmt = g_strdup(col_format_to_string(cur_fmt)); + prefs.col_list = g_list_append(prefs.col_list, cfmt); + nl_lb = gtk_label_new(cfmt->title); + nl_item = gtk_list_item_new(); + gtk_misc_set_alignment (GTK_MISC (nl_lb), 0.0, 0.5); + gtk_container_add(GTK_CONTAINER(nl_item), nl_lb); + gtk_widget_show(nl_lb); + gtk_container_add(GTK_CONTAINER(column_l), nl_item); + gtk_widget_show(nl_item); + gtk_object_set_data(GTK_OBJECT(nl_item), E_COL_LBL_KEY, nl_lb); + gtk_object_set_data(GTK_OBJECT(nl_item), E_COL_NAME_KEY, + g_list_last(prefs.col_list)); + gtk_list_select_child(GTK_LIST(column_l), nl_item); + } +} + +static void +column_sel_chg_cb(GtkWidget *w, gpointer data) { + fmt_data *cfmt; + gchar *title = ""; + GList *sl, *clp; + GtkObject *l_item; + GtkLabel *nl_lb; + + sl = GTK_LIST(column_l)->selection; + title = gtk_entry_get_text(GTK_ENTRY(title_te)); + + if (sl) { /* Something was selected */ + l_item = GTK_OBJECT(sl->data); + clp = (GList *) gtk_object_get_data(l_item, E_COL_NAME_KEY); + nl_lb = (GtkLabel *) gtk_object_get_data(l_item, E_COL_LBL_KEY); + if (clp && nl_lb) { + cfmt = (fmt_data *) clp->data; + + if (strlen(title) > 0 && cfmt) { + g_free(cfmt->title); + g_free(cfmt->fmt); + cfmt->title = g_strdup(title); + cfmt->fmt = g_strdup(col_format_to_string(cur_fmt)); + gtk_label_set(nl_lb, cfmt->title); + } + } + } +} + +static void +column_sel_del_cb(GtkWidget *w, gpointer data) { + GList *sl, *clp; + fmt_data *cfmt; + GtkObject *l_item; + gint pos; + + sl = GTK_LIST(column_l)->selection; + if (sl) { /* Something was selected */ + l_item = GTK_OBJECT(sl->data); + pos = gtk_list_child_position(GTK_LIST(column_l), GTK_WIDGET(l_item)); + clp = (GList *) gtk_object_get_data(l_item, E_COL_NAME_KEY); + if (clp) { + cfmt = (fmt_data *) clp->data; + g_free(cfmt->title); + g_free(cfmt->fmt); + g_free(cfmt); + prefs.col_list = g_list_remove_link(prefs.col_list, clp); + gtk_list_clear_items(GTK_LIST(column_l), pos, pos + 1); + } + } +} + +static void +column_sel_arrow_cb(GtkWidget *w, gpointer data) { + GList *sl, *clp, *il; + fmt_data *cfmt; + GtkObject *l_item; + gint pos, inc = 1; + + if (w == up_bt) + inc = -1; + + sl = GTK_LIST(column_l)->selection; + if (sl) { /* Something was selected */ + l_item = GTK_OBJECT(sl->data); + pos = gtk_list_child_position(GTK_LIST(column_l), GTK_WIDGET(l_item)); + clp = (GList *) gtk_object_get_data(l_item, E_COL_NAME_KEY); + if (clp) { + cfmt = (fmt_data *) clp->data; + prefs.col_list = g_list_remove(prefs.col_list, cfmt); + g_list_insert(prefs.col_list, cfmt, pos + inc); + il = (GList *) g_malloc(sizeof(GList)); + il->next = NULL; + il->prev = NULL; + il->data = l_item; + gtk_widget_ref(GTK_WIDGET(l_item)); + gtk_list_clear_items(GTK_LIST(column_l), pos, pos + 1); + gtk_list_insert_items(GTK_LIST(column_l), il, pos + inc); + gtk_widget_unref(GTK_WIDGET(l_item)); + gtk_list_select_item(GTK_LIST(column_l), pos + inc); + } + } +} + +void +column_set_fmt_cb(GtkWidget *w, gpointer data) { + cur_fmt = (gint) data; +} + +void +column_prefs_ok(GtkWidget *w) { + + column_prefs_cancel(w); +} + +void +column_prefs_save(GtkWidget *w) { +} + +void +column_prefs_cancel(GtkWidget *w) { + + /* Let the list cb know we're about to destroy the widget tree, so it */ + /* doesn't operate on widgets that don't exist. */ + gtk_object_set_data(GTK_OBJECT(w), E_COL_CM_KEY, (gpointer)TRUE); + gtk_widget_destroy(GTK_WIDGET(w)); +} diff --git a/column.h b/column.h new file mode 100644 index 0000000000..209b688c4e --- /dev/null +++ b/column.h @@ -0,0 +1,44 @@ +/* column.h + * Definitions for column handling routines + * + * $Id: column.h,v 1.1 1998/11/17 04:28:41 gerald 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 __COLUMN_H__ +#define __COLUMN_H__ + +typedef struct _fmt_data { + gchar *title; + gchar *fmt; +} fmt_data; + +gint get_column_format(gint); +gchar *get_column_title(gint); +gchar *col_format_to_pref_str(); +void get_column_format_matches(gboolean *, gint); +gint get_column_width(gint format, GdkFont *font); +GtkWidget *column_prefs_show(); +void column_prefs_ok(GtkWidget *); +void column_prefs_save(GtkWidget *); +void column_prefs_cancel(GtkWidget *); + +#endif /* column.h */ @@ -697,7 +697,7 @@ fi PACKAGE=ethereal -VERSION=0.4.1 +VERSION=0.4.2 if test "`cd $srcdir && pwd`" != "`pwd`" && test -f $srcdir/config.status; then { echo "configure: error: source directory already configured; run "make distclean" there first" 1>&2; exit 1; } @@ -1142,13 +1142,10 @@ int main () { int major, minor, micro; - char *tmp_version; system ("touch conf.gtktest"); - /* HP/UX 9 (%@#!) writes to sscanf strings */ - tmp_version = g_strdup("$min_gtk_version"); - if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, µ) != 3) { + if (sscanf("$min_gtk_version", "%d.%d.%d", &major, &minor, µ) != 3) { printf("%s, bad version string\n", "$min_gtk_version"); exit(1); } @@ -1198,7 +1195,7 @@ main () } EOF -if { (eval echo configure:1202: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null +if { (eval echo configure:1199: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null then : else @@ -1232,7 +1229,7 @@ fi CFLAGS="$CFLAGS $GTK_CFLAGS" LIBS="$LIBS $GTK_LIBS" cat > conftest.$ac_ext <<EOF -#line 1236 "configure" +#line 1233 "configure" #include "confdefs.h" #include <gtk/gtk.h> @@ -1242,7 +1239,7 @@ int main() { return ((gtk_major_version) || (gtk_minor_version) || (gtk_micro_version)); ; return 0; } EOF -if { (eval echo configure:1246: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:1243: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then rm -rf conftest* echo "*** The test program compiled, but did not run. This usually means" echo "*** that the run-time linker is not finding GTK or finding the wrong" @@ -1283,7 +1280,7 @@ rm -f conftest* # Pcap checks echo $ac_n "checking how to run the C preprocessor""... $ac_c" 1>&6 -echo "configure:1287: checking how to run the C preprocessor" >&5 +echo "configure:1284: checking how to run the C preprocessor" >&5 # On Suns, sometimes $CPP names a directory. if test -n "$CPP" && test -d "$CPP"; then CPP= @@ -1298,13 +1295,13 @@ else # On the NeXT, cc -E runs the code through the compiler's parser, # not just through cpp. cat > conftest.$ac_ext <<EOF -#line 1302 "configure" +#line 1299 "configure" #include "confdefs.h" #include <assert.h> Syntax Error EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1308: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1305: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out` if test -z "$ac_err"; then : @@ -1315,13 +1312,13 @@ else rm -rf conftest* CPP="${CC-cc} -E -traditional-cpp" cat > conftest.$ac_ext <<EOF -#line 1319 "configure" +#line 1316 "configure" #include "confdefs.h" #include <assert.h> Syntax Error EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1325: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1322: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out` if test -z "$ac_err"; then : @@ -1345,17 +1342,17 @@ echo "$ac_t""$CPP" 1>&6 ac_safe=`echo "net/bpf.h" | sed 'y%./+-%__p_%'` echo $ac_n "checking for net/bpf.h""... $ac_c" 1>&6 -echo "configure:1349: checking for net/bpf.h" >&5 +echo "configure:1346: checking for net/bpf.h" >&5 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1354 "configure" +#line 1351 "configure" #include "confdefs.h" #include <net/bpf.h> EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1359: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1356: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out` if test -z "$ac_err"; then rm -rf conftest* @@ -1379,17 +1376,17 @@ fi ac_safe=`echo "pcap.h" | sed 'y%./+-%__p_%'` echo $ac_n "checking for pcap.h""... $ac_c" 1>&6 -echo "configure:1383: checking for pcap.h" >&5 +echo "configure:1380: checking for pcap.h" >&5 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1388 "configure" +#line 1385 "configure" #include "confdefs.h" #include <pcap.h> EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1393: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1390: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out` if test -z "$ac_err"; then rm -rf conftest* @@ -1412,7 +1409,7 @@ else fi echo $ac_n "checking for pcap_open_offline in -lpcap""... $ac_c" 1>&6 -echo "configure:1416: checking for pcap_open_offline in -lpcap" >&5 +echo "configure:1413: checking for pcap_open_offline in -lpcap" >&5 ac_lib_var=`echo pcap'_'pcap_open_offline | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -1420,7 +1417,7 @@ else ac_save_LIBS="$LIBS" LIBS="-lpcap $LIBS" cat > conftest.$ac_ext <<EOF -#line 1424 "configure" +#line 1421 "configure" #include "confdefs.h" /* Override any gcc2 internal prototype to avoid an error. */ /* We use char because int might match the return type of a gcc2 @@ -1431,7 +1428,7 @@ int main() { pcap_open_offline() ; return 0; } EOF -if { (eval echo configure:1435: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:1432: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else @@ -1462,7 +1459,7 @@ fi # Evidently, some systems have pcap.h, etc. in */include/pcap echo $ac_n "checking for extraneous pcap header directories""... $ac_c" 1>&6 -echo "configure:1466: checking for extraneous pcap header directories" >&5 +echo "configure:1463: checking for extraneous pcap header directories" >&5 found_pcap_dir="" for pcap_dir in /usr/include/pcap /usr/local/include/pcap do @@ -1480,7 +1477,7 @@ fi # Wiretap check echo $ac_n "checking whether to include wiretap library""... $ac_c" 1>&6 -echo "configure:1484: checking whether to include wiretap library" >&5 +echo "configure:1481: checking whether to include wiretap library" >&5 # Check whether --with-wiretap or --without-wiretap was given. if test "${with_wiretap+set}" = set; then withval="$with_wiretap" @@ -1507,12 +1504,12 @@ fi echo $ac_n "checking for ANSI C header files""... $ac_c" 1>&6 -echo "configure:1511: checking for ANSI C header files" >&5 +echo "configure:1508: checking for ANSI C header files" >&5 if eval "test \"`echo '$''{'ac_cv_header_stdc'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1516 "configure" +#line 1513 "configure" #include "confdefs.h" #include <stdlib.h> #include <stdarg.h> @@ -1520,7 +1517,7 @@ else #include <float.h> EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1524: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1521: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out` if test -z "$ac_err"; then rm -rf conftest* @@ -1537,7 +1534,7 @@ rm -f conftest* if test $ac_cv_header_stdc = yes; then # SunOS 4.x string.h does not declare mem*, contrary to ANSI. cat > conftest.$ac_ext <<EOF -#line 1541 "configure" +#line 1538 "configure" #include "confdefs.h" #include <string.h> EOF @@ -1555,7 +1552,7 @@ fi if test $ac_cv_header_stdc = yes; then # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. cat > conftest.$ac_ext <<EOF -#line 1559 "configure" +#line 1556 "configure" #include "confdefs.h" #include <stdlib.h> EOF @@ -1576,7 +1573,7 @@ if test "$cross_compiling" = yes; then : else cat > conftest.$ac_ext <<EOF -#line 1580 "configure" +#line 1577 "configure" #include "confdefs.h" #include <ctype.h> #define ISLOWER(c) ('a' <= (c) && (c) <= 'z') @@ -1587,7 +1584,7 @@ if (XOR (islower (i), ISLOWER (i)) || toupper (i) != TOUPPER (i)) exit(2); exit (0); } EOF -if { (eval echo configure:1591: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null +if { (eval echo configure:1588: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null then : else @@ -1614,17 +1611,17 @@ for ac_hdr in fcntl.h strings.h sys/ioctl.h sys/time.h unistd.h stdarg.h do ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6 -echo "configure:1618: checking for $ac_hdr" >&5 +echo "configure:1615: checking for $ac_hdr" >&5 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1623 "configure" +#line 1620 "configure" #include "confdefs.h" #include <$ac_hdr> EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1628: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1625: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out` if test -z "$ac_err"; then rm -rf conftest* @@ -1655,17 +1652,17 @@ for ac_hdr in sys/sockio.h sys/types.h netinet/in.h do ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6 -echo "configure:1659: checking for $ac_hdr" >&5 +echo "configure:1656: checking for $ac_hdr" >&5 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1664 "configure" +#line 1661 "configure" #include "confdefs.h" #include <$ac_hdr> EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1669: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1666: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out` if test -z "$ac_err"; then rm -rf conftest* @@ -1698,12 +1695,12 @@ done # for get_interface_list(). echo $ac_n "checking for sa_len in struct sockaddr""... $ac_c" 1>&6 -echo "configure:1702: checking for sa_len in struct sockaddr" >&5 +echo "configure:1699: checking for sa_len in struct sockaddr" >&5 if eval "test \"`echo '$''{'ac_cv_ethereal_struct_sa_len'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1707 "configure" +#line 1704 "configure" #include "confdefs.h" #include <sys/types.h> #include <sys/socket.h> @@ -1711,7 +1708,7 @@ int main() { struct sockaddr s; s.sa_len; ; return 0; } EOF -if { (eval echo configure:1715: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:1712: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_ethereal_struct_sa_len=yes else @@ -1734,14 +1731,14 @@ fi # We must know our byte order echo $ac_n "checking whether byte ordering is bigendian""... $ac_c" 1>&6 -echo "configure:1738: checking whether byte ordering is bigendian" >&5 +echo "configure:1735: checking whether byte ordering is bigendian" >&5 if eval "test \"`echo '$''{'ac_cv_c_bigendian'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else ac_cv_c_bigendian=unknown # See if sys/param.h defines the BYTE_ORDER macro. cat > conftest.$ac_ext <<EOF -#line 1745 "configure" +#line 1742 "configure" #include "confdefs.h" #include <sys/types.h> #include <sys/param.h> @@ -1752,11 +1749,11 @@ int main() { #endif ; return 0; } EOF -if { (eval echo configure:1756: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:1753: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* # It does; now see whether it defined to BIG_ENDIAN or not. cat > conftest.$ac_ext <<EOF -#line 1760 "configure" +#line 1757 "configure" #include "confdefs.h" #include <sys/types.h> #include <sys/param.h> @@ -1767,7 +1764,7 @@ int main() { #endif ; return 0; } EOF -if { (eval echo configure:1771: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:1768: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_c_bigendian=yes else @@ -1787,7 +1784,7 @@ if test "$cross_compiling" = yes; then { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; } else cat > conftest.$ac_ext <<EOF -#line 1791 "configure" +#line 1788 "configure" #include "confdefs.h" main () { /* Are we little or big endian? From Harbison&Steele. */ @@ -1800,7 +1797,7 @@ main () { exit (u.c[sizeof (long) - 1] == 1); } EOF -if { (eval echo configure:1804: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null +if { (eval echo configure:1801: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null then ac_cv_c_bigendian=no else @@ -1826,13 +1823,13 @@ fi if test $ac_cv_prog_gcc = yes; then echo $ac_n "checking whether ${CC-cc} needs -traditional""... $ac_c" 1>&6 -echo "configure:1830: checking whether ${CC-cc} needs -traditional" >&5 +echo "configure:1827: checking whether ${CC-cc} needs -traditional" >&5 if eval "test \"`echo '$''{'ac_cv_prog_gcc_traditional'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else ac_pattern="Autoconf.*'x'" cat > conftest.$ac_ext <<EOF -#line 1836 "configure" +#line 1833 "configure" #include "confdefs.h" #include <sgtty.h> Autoconf TIOCGETP @@ -1850,7 +1847,7 @@ rm -f conftest* if test $ac_cv_prog_gcc_traditional = no; then cat > conftest.$ac_ext <<EOF -#line 1854 "configure" +#line 1851 "configure" #include "confdefs.h" #include <termio.h> Autoconf TCGETA @@ -1872,12 +1869,12 @@ echo "$ac_t""$ac_cv_prog_gcc_traditional" 1>&6 fi echo $ac_n "checking for socket""... $ac_c" 1>&6 -echo "configure:1876: checking for socket" >&5 +echo "configure:1873: checking for socket" >&5 if eval "test \"`echo '$''{'ac_cv_func_socket'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1881 "configure" +#line 1878 "configure" #include "confdefs.h" /* System header to define __stub macros and hopefully few prototypes, which can conflict with char socket(); below. */ @@ -1900,7 +1897,7 @@ socket(); ; return 0; } EOF -if { (eval echo configure:1904: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:1901: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then rm -rf conftest* eval "ac_cv_func_socket=yes" else @@ -1926,12 +1923,12 @@ fi SNPRINTF_C="" SNPRINTF_O="" echo $ac_n "checking for snprintf""... $ac_c" 1>&6 -echo "configure:1930: checking for snprintf" >&5 +echo "configure:1927: checking for snprintf" >&5 if eval "test \"`echo '$''{'ac_cv_func_snprintf'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1935 "configure" +#line 1932 "configure" #include "confdefs.h" /* System header to define __stub macros and hopefully few prototypes, which can conflict with char snprintf(); below. */ @@ -1954,7 +1951,7 @@ snprintf(); ; return 0; } EOF -if { (eval echo configure:1958: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:1955: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then rm -rf conftest* eval "ac_cv_func_snprintf=yes" else diff --git a/configure.in b/configure.in index f881c8e67a..73b56b4f42 100644 --- a/configure.in +++ b/configure.in @@ -1,8 +1,8 @@ -# $Id: configure.in,v 1.14 1998/11/17 02:17:27 guy Exp $ +# $Id: configure.in,v 1.15 1998/11/17 04:28:43 gerald Exp $ dnl Process this file with autoconf to produce a configure script. AC_INIT(etypes.h) -AM_INIT_AUTOMAKE(ethereal, 0.4.1) +AM_INIT_AUTOMAKE(ethereal, 0.4.2) dnl Check for CPU / vendor / OS AC_CANONICAL_HOST diff --git a/ethereal.c b/ethereal.c index 4c9f5c9131..3a878f9834 100644 --- a/ethereal.c +++ b/ethereal.c @@ -1,6 +1,6 @@ /* ethereal.c * - * $Id: ethereal.c,v 1.11 1998/11/12 00:06:19 gram Exp $ + * $Id: ethereal.c,v 1.12 1998/11/17 04:28:44 gerald Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -61,6 +61,7 @@ #include "menu.h" #include "etypes.h" #include "prefs.h" +#include "column.h" #include "print.h" #include "resolv.h" #include "follow.h" @@ -362,10 +363,11 @@ print_usage(void) { fprintf(stderr, " [-T tree view height] [-w savefile] \n"); } +/* And now our feature presentation... [ fade to music ] */ int main(int argc, char *argv[]) { - int opt; + int opt, i, j; extern char *optarg; GtkWidget *window, *main_vbox, *menubar, *u_pane, *l_pane, *bv_table, *bv_hscroll, *bv_vscroll, *stat_hbox, @@ -374,11 +376,17 @@ main(int argc, char *argv[]) GtkAcceleratorTable *accel; gint col_width, pl_size = 280, tv_size = 95, bv_size = 75; gchar *rc_file, *cf_name = NULL; - gchar *cl_title[] = {"No.", "Time", "Source", "Destination", - "Protocol", "Info"}; gchar *medium_font = MONO_MEDIUM_FONT; gchar *bold_font = MONO_BOLD_FONT; + e_prefs *prefs; + gint *col_fmt; + gchar **col_title; + /* Let GTK get its args */ + gtk_init (&argc, &argv); + + prefs = read_prefs(); + /* Initialize the capture file struct */ cf.plist = NULL; #ifdef WITH_WIRETAP @@ -393,12 +401,24 @@ main(int argc, char *argv[]) cf.save_file = NULL; cf.snap = 68; cf.count = 0; + cf.cinfo.num_cols = prefs->num_cols; + cf.cinfo.fmt_matx = (gboolean **) g_malloc(sizeof(gboolean *) * + cf.cinfo.num_cols); + cf.cinfo.col_data = (gchar **) g_malloc(sizeof(gchar *) * + cf.cinfo.num_cols); + + col_fmt = (gint *) g_malloc(sizeof(gint) * cf.cinfo.num_cols); + col_title = (gchar **) g_malloc(sizeof(gchar *) * cf.cinfo.num_cols); + + for (i = 0; i < cf.cinfo.num_cols; i++) { + col_fmt[i] = get_column_format(i); + col_title[i] = g_strdup(get_column_title(i)); + cf.cinfo.fmt_matx[i] = (gboolean *) g_malloc0(sizeof(gboolean) * + NUM_COL_FMTS); + get_column_format_matches(cf.cinfo.fmt_matx[i], col_fmt[i]); + cf.cinfo.col_data[i] = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN); + } - /* Let GTK get its args */ - gtk_init (&argc, &argv); - - read_prefs(); - /* Now get our args */ while ((opt = getopt(argc, argv, "b:B:c:hi:m:nP:r:s:t:T:w:v")) != EOF) { switch (opt) { @@ -518,7 +538,8 @@ main(int argc, char *argv[]) gtk_widget_show(l_pane); /* Packet list */ - packet_list = gtk_clist_new_with_titles(NUM_COLS, cl_title); + packet_list = gtk_clist_new_with_titles(cf.cinfo.num_cols, col_title); + gtk_clist_column_titles_passive(GTK_CLIST(packet_list)); pl_style = gtk_style_new(); gdk_font_unref(pl_style->font); pl_style->font = m_r_font; @@ -528,20 +549,13 @@ main(int argc, char *argv[]) GTK_SIGNAL_FUNC(packet_list_select_cb), NULL); gtk_signal_connect(GTK_OBJECT(packet_list), "unselect_row", GTK_SIGNAL_FUNC(packet_list_unselect_cb), NULL); - gtk_clist_set_column_justification(GTK_CLIST(packet_list), 0, - GTK_JUSTIFY_RIGHT); - col_width = (gdk_string_width(pl_style->font, "0") * 7) + 2; - gtk_clist_set_column_width(GTK_CLIST(packet_list), COL_NUM, col_width); - if (timestamp_type == ABSOLUTE) - col_width = gdk_string_width(pl_style->font, "00:00:00.000000"); - else - col_width = gdk_string_width(pl_style->font, "0000.000000"); - gtk_clist_set_column_width(GTK_CLIST(packet_list), COL_TIME, col_width); - col_width = gdk_string_width(pl_style->font, "00:00:00:00:00:00") + 2; - gtk_clist_set_column_width(GTK_CLIST(packet_list), COL_SOURCE, col_width); - gtk_clist_set_column_width(GTK_CLIST(packet_list), COL_DESTINATION, col_width); - col_width = gdk_string_width(pl_style->font, "NBNS (UDP)") + 2; - gtk_clist_set_column_width(GTK_CLIST(packet_list), COL_PROTOCOL, col_width); + for (i = 0; i < cf.cinfo.num_cols; i++) { + gtk_clist_set_column_width(GTK_CLIST(packet_list), i, + get_column_width(get_column_format(i), pl_style->font)); + if (col_fmt[i] == COL_NUMBER) + gtk_clist_set_column_justification(GTK_CLIST(packet_list), i, + GTK_JUSTIFY_RIGHT); + } gtk_widget_set_usize(packet_list, -1, pl_size); gtk_paned_add1(GTK_PANED(u_pane), packet_list); gtk_widget_show(packet_list); diff --git a/ethereal.h b/ethereal.h index ded1e7d452..fd7e0eb64e 100644 --- a/ethereal.h +++ b/ethereal.h @@ -1,7 +1,7 @@ /* ethereal.h * Global defines, etc. * - * $Id: ethereal.h,v 1.7 1998/10/16 01:18:27 gerald Exp $ + * $Id: ethereal.h,v 1.8 1998/11/17 04:28:45 gerald Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -28,7 +28,8 @@ #include "config.h" -#define RC_FILE ".etherealrc" +#define PF_DIR ".ethereal" +#define RC_FILE PF_DIR "/gtkrc" #define MONO_MEDIUM_FONT "-*-lucidatypewriter-medium-r-normal-*-*-120-*-*-*-*-iso8859-1" #define MONO_BOLD_FONT "-*-lucidatypewriter-bold-r-normal-*-*-120-*-*-*-*-iso8859-1" #define DEF_WIDTH 750 @@ -72,16 +73,44 @@ typedef struct _selection_info { } selection_info; /* - * Columns in summary listing. + * All of the possible columns in summary listing. + * + * NOTE: The SRC and DST entries MUST remain in this order, or else you + * need to fix the offset #defines before get_column_format! */ -#define COL_NUM 0 -#define COL_TIME 1 -#define COL_SOURCE 2 -#define COL_DESTINATION 3 -#define COL_PROTOCOL 4 -#define COL_INFO 5 - -#define NUM_COLS 6 +enum { + COL_NUMBER, /* Packet list item number */ + COL_REL_TIME, /* Relative time (default) */ + COL_ABS_TIME, /* Absolute time */ + COL_DELTA_TIME, /* Delta time */ + COL_DEF_SRC, /* Source address */ + COL_RES_SRC, /* Resolved source */ + COL_UNRES_SRC, /* Unresolved source */ + COL_DEF_DL_SRC, /* Data link layer source address */ + COL_RES_DL_SRC, /* Resolved DL source */ + COL_UNRES_DL_SRC, /* Unresolved DL source */ + COL_DEF_NET_SRC, /* Network layer source address */ + COL_RES_NET_SRC, /* Resolved net source */ + COL_UNRES_NET_SRC, /* Unresolved net source */ + COL_DEF_DST, /* Destination address */ + COL_RES_DST, /* Resolved dest */ + COL_UNRES_DST, /* Unresolved dest */ + COL_DEF_DL_DST, /* Data link layer dest address */ + COL_RES_DL_DST, /* Resolved DL dest */ + COL_UNRES_DL_DST, /* Unresolved DL dest */ + COL_DEF_NET_DST, /* Network layer dest address */ + COL_RES_NET_DST, /* Resolved net dest */ + COL_UNRES_NET_DST, /* Unresolved net dest */ + COL_DEF_SRC_PORT, /* Source port */ + COL_RES_SRC_PORT, /* Resolved source port */ + COL_UNRES_SRC_PORT, /* Unresolved source port */ + COL_DEF_DST_PORT, /* Destination port */ + COL_RES_DST_PORT, /* Resolved dest port */ + COL_UNRES_DST_PORT, /* Unresolved dest port */ + COL_PROTOCOL, /* Protocol */ + COL_INFO, /* Description */ + NUM_COL_FMTS /* Should always be last */ +}; /* * Type of time-stamp shown in the summary display. diff --git a/ethertype.c b/ethertype.c index a42ad8b43f..0ae599aec7 100644 --- a/ethertype.c +++ b/ethertype.c @@ -2,7 +2,7 @@ * Routines for calling the right protocol for the ethertype. * This is called by both packet-eth.c (Ethernet II) and packet-llc.c (SNAP) * - * $Id: ethertype.c,v 1.9 1998/11/12 00:06:20 gram Exp $ + * $Id: ethertype.c,v 1.10 1998/11/17 04:28:46 gerald Exp $ * * Gilbert Ramirez <gram@verdict.uthscsa.edu> * @@ -95,7 +95,7 @@ ethertype(guint16 etype, int offset, break; default: dissect_data(pd, offset, fd, tree); - if (fd->win_info[COL_NUM]) { sprintf(fd->win_info[COL_PROTOCOL], "0x%04x", etype); } + if (check_col(fd, COL_PROTOCOL)) { col_add_fstr(fd, COL_PROTOCOL, "0x%04x", etype); } break; } } @@ -1,7 +1,7 @@ /* file.c * File I/O routines * - * $Id: file.c,v 1.12 1998/11/15 05:28:59 guy Exp $ + * $Id: file.c,v 1.13 1998/11/17 04:28:46 gerald Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -317,8 +317,6 @@ pcap_dispatch_cb(u_char *user, const struct pcap_pkthdr *phdr, #endif const u_char *buf) { frame_data *fdata; - /* To do: make sure this is big enough. */ - gchar p_info[NUM_COLS][256]; gint i, row; capture_file *cf = (capture_file *) user; guint32 tssecs, tsusecs; @@ -383,11 +381,15 @@ pcap_dispatch_cb(u_char *user, const struct pcap_pkthdr *phdr, tsusecs = 0; break; } - for (i = 0; i < NUM_COLS; i++) { fdata->win_info[i] = &p_info[i][0]; } - sprintf(fdata->win_info[COL_NUM], "%d", cf->count); + fdata->cinfo = &cf->cinfo; + for (i = 0; i < fdata->cinfo->num_cols; i++) { + fdata->cinfo->col_data[i][0] = '\0'; + } + if (check_col(fdata, COL_NUMBER)) + col_add_fstr(fdata, COL_NUMBER, "%d", cf->count); dissect_packet(buf, tssecs, tsusecs, fdata, NULL); - row = gtk_clist_append(GTK_CLIST(packet_list), fdata->win_info); - for (i = 0; i < NUM_COLS; i++) { fdata->win_info[i] = NULL; } + row = gtk_clist_append(GTK_CLIST(packet_list), fdata->cinfo->col_data); + fdata->cinfo = NULL; /* Make sure we always have an available list entry */ if (cf->plist->next == NULL) { @@ -1,7 +1,7 @@ /* file.h * Definitions for file structures and routines * - * $Id: file.h,v 1.6 1998/11/15 05:29:01 guy Exp $ + * $Id: file.h,v 1.7 1998/11/17 04:28:47 gerald Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -73,7 +73,7 @@ typedef struct _capture_file { gchar *iface; /* Interface */ gchar *save_file; /* File to write capture data */ #ifdef WITH_WIRETAP - wtap *wth; /* Wiretap session */ + wtap *wth; /* Wiretap session */ #else pcap_t *pfh; /* Pcap session */ #endif @@ -83,6 +83,7 @@ typedef struct _capture_file { guint8 pd[4096]; /* Packet data */ GList *plist; /* Packet list */ frame_data *cur; /* Current list item */ + column_info cinfo; /* Column formatting information */ } capture_file; /* Taken from RFC 1761 */ @@ -1,7 +1,7 @@ /* filter.c * Routines for managing filter sets * - * $Id: filter.c,v 1.8 1998/10/16 01:18:28 gerald Exp $ + * $Id: filter.c,v 1.9 1998/11/17 04:28:48 gerald Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -54,7 +54,7 @@ void get_filter_list() { filter_def *filt; FILE *ff; - gchar *ff_path, *ff_name = ".ethereal/filters", f_buf[256]; + gchar *ff_path, *ff_name = PF_DIR "/filters", f_buf[256]; gchar *name_begin, *name_end, *filt_begin; int len, line = 0; @@ -104,7 +104,7 @@ get_filter_list() { g_free(ff_path); } -/* filter_sel_pg - Create and display the filter selection widgets. */ +/* Create and display the filter selection widgets. */ /* Called when the 'Filter' preference notebook page is selected. */ GtkWidget * filter_prefs_show(GtkWidget *w) { @@ -172,6 +172,7 @@ filter_prefs_show(GtkWidget *w) { gtk_widget_show(filter_sc); filter_l = gtk_list_new(); + gtk_list_set_selection_mode(GTK_LIST(filter_l), GTK_SELECTION_SINGLE); gtk_signal_connect(GTK_OBJECT(filter_l), "selection_changed", GTK_SIGNAL_FUNC(filter_sel_list_cb), main_vb); gtk_container_add(GTK_CONTAINER(filter_sc), filter_l); @@ -376,7 +377,7 @@ filter_sel_del_cb(GtkWidget *w, gpointer data) { g_free(filt->name); g_free(filt->strval); g_free(filt); - fl = g_list_remove_link(fl, flp); + fl = g_list_remove(fl, flp); gtk_list_clear_items(GTK_LIST(filter_l), pos, pos + 1); } } @@ -406,7 +407,7 @@ void filter_prefs_save(GtkWidget *w) { GList *flp; filter_def *filt; - gchar *ff_path, *ff_dir = ".ethereal", *ff_name = "filters"; + gchar *ff_path, *ff_dir = PF_DIR, *ff_name = "filters"; FILE *ff; struct stat s_buf; diff --git a/image/dn_arrow.xpm b/image/dn_arrow.xpm new file mode 100644 index 0000000000..8f71d31e55 --- /dev/null +++ b/image/dn_arrow.xpm @@ -0,0 +1,21 @@ +/* XPM */ +static char *dn_arrow[] = { +/* width height num_colors chars_per_pixel */ +" 11 12 2 1", +/* colors */ +". c None", +"# c #000000", +/* pixels */ +"...........", +".#.......#.", +".##.....##.", +"..##...##..", +"...##.##...", +".#..###..#.", +".##..#..##.", +"..##...##..", +"...##.##...", +"....###....", +".....#.....", +"..........." +}; diff --git a/image/up_arrow.xpm b/image/up_arrow.xpm new file mode 100644 index 0000000000..a33294ca5d --- /dev/null +++ b/image/up_arrow.xpm @@ -0,0 +1,21 @@ +/* XPM */ +static char *up_arrow[] = { +/* width height num_colors chars_per_pixel */ +" 11 12 2 1", +/* colors */ +". c None", +"# c #000000", +/* pixels */ +"...........", +".....#.....", +"....###....", +"...##.##...", +"..##...##..", +".##..#..##.", +".#..###..#.", +"...##.##...", +"..##...##..", +".##.....##.", +".#.......#.", +"..........." +}; diff --git a/packet-aarp.c b/packet-aarp.c index 33f374bc20..1d3e4c3cb3 100644 --- a/packet-aarp.c +++ b/packet-aarp.c @@ -97,7 +97,8 @@ dissect_aarp(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) { memcpy(&ea.hdaddr, &pd[offset + 18], 6); memcpy(&ea.pdaddr, &pd[offset + 24], 4); - if (fd->win_info[COL_NUM]) { strcpy(fd->win_info[COL_PROTOCOL], "AARP"); } + if(check_col(fd, COL_PROTOCOL)) + col_add_str(fd, COL_PROTOCOL, "AARP"); if (tree) { if ((op_str = match_strval(ea.op, op_vals))) @@ -127,31 +128,27 @@ dissect_aarp(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) { "Target ID: %s", atalkid_to_str((guint8 *) ea.pdaddr)); } - if (ea.ptype != ETHERTYPE_AARP && ea.ptype !=ETHERTYPE_ATALK && - fd->win_info[COL_NUM]) { - sprintf(fd->win_info[COL_INFO], "h/w %d (%d) prot %d (%d) op 0x%04x", + if (ea.ptype != ETHERTYPE_AARP && ea.ptype != ETHERTYPE_ATALK && + check_col(fd, COL_INFO)) { + col_add_fstr(fd, COL_INFO, "h/w %d (%d) prot %d (%d) op 0x%04x", ea.htype, ea.halen, ea.ptype, ea.palen, ea.op); return; } - switch (ea.op) { - case AARP_REQUEST: - if (fd->win_info[COL_NUM]) { - sprintf(fd->win_info[COL_INFO], "Who has %s? Tell %s", + if (check_col(fd, COL_INFO)) { + switch (ea.op) { + case AARP_REQUEST: + col_add_fstr(fd, COL_INFO, "Who has %s? Tell %s", atalkid_to_str((guint8 *) ea.pdaddr), atalkid_to_str((guint8 *) ea.psaddr)); - } - break; - case AARP_REPLY: - if (fd->win_info[COL_NUM]) { - sprintf(fd->win_info[COL_INFO], "%s is at %s", + break; + case AARP_REPLY: + col_add_fstr(fd, COL_INFO, "%s is at %s", atalkid_to_str((guint8 *) ea.psaddr), ether_to_str((guint8 *) ea.hsaddr)); - } - break; - case AARP_PROBE: - if (fd->win_info[COL_NUM]) { - sprintf(fd->win_info[COL_INFO], "Is there a %s", + break; + case AARP_PROBE: + col_add_fstr(fd, COL_INFO, "Is there a %s", atalkid_to_str((guint8 *) ea.pdaddr)); - } - break; + break; + } } } diff --git a/packet-arp.c b/packet-arp.c index d6a9bf0498..9906f607d3 100644 --- a/packet-arp.c +++ b/packet-arp.c @@ -1,7 +1,7 @@ /* packet-arp.c * Routines for ARP packet disassembly * - * $Id: packet-arp.c,v 1.9 1998/11/12 00:06:23 gram Exp $ + * $Id: packet-arp.c,v 1.10 1998/11/17 04:28:49 gerald Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -207,31 +207,31 @@ dissect_arp(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) { tpa_offset = tha_offset + ar_hln; tpa_str = arpproaddr_to_str((guint8 *) &pd[tpa_offset], ar_pln, ar_pro); - if (fd->win_info[COL_NUM]) { + if (check_col(fd, COL_PROTOCOL)) { + if ((op_str = match_strval(ar_op, op_vals))) + col_add_str(fd, COL_PROTOCOL, op_str); + else + col_add_str(fd, COL_PROTOCOL, "ARP"); + } + + if (check_col(fd, COL_INFO)) { switch (ar_op) { case ARPOP_REQUEST: - strcpy(fd->win_info[COL_PROTOCOL], "ARP"); - sprintf(fd->win_info[COL_INFO], "Who has %s? Tell %s", + col_add_fstr(fd, COL_INFO, "Who has %s? Tell %s", tpa_str, spa_str); break; case ARPOP_REPLY: - strcpy(fd->win_info[COL_PROTOCOL], "ARP"); - sprintf(fd->win_info[COL_INFO], "%s is at %s", - spa_str, sha_str); + col_add_fstr(fd, COL_INFO, "%s is at %s", spa_str, sha_str); break; case ARPOP_RREQUEST: - strcpy(fd->win_info[COL_PROTOCOL], "RARP"); - sprintf(fd->win_info[COL_INFO], "Who is %s? Tell %s", + col_add_fstr(fd, COL_INFO, "Who is %s? Tell %s", tha_str, sha_str); break; case ARPOP_RREPLY: - strcpy(fd->win_info[COL_PROTOCOL], "RARP"); - sprintf(fd->win_info[COL_INFO], "%s is at %s", - sha_str, spa_str); + col_add_fstr(fd, COL_INFO, "%s is at %s", sha_str, spa_str); break; default: - strcpy(fd->win_info[COL_PROTOCOL], "ARP"); - sprintf(fd->win_info[COL_INFO], "Unknown ARP opcode 0x%04x", ar_op); + col_add_fstr(fd, COL_INFO, "Unknown ARP opcode 0x%04x", ar_op); break; } } diff --git a/packet-atalk.c b/packet-atalk.c index 6fce54b4a8..9dbb64f0bf 100644 --- a/packet-atalk.c +++ b/packet-atalk.c @@ -79,14 +79,15 @@ dissect_ddp(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) { ddp.snet=ntohs(ddp.snet); ddp.sum=ntohs(ddp.sum); - if (fd->win_info[COL_NUM]) { - strcpy(fd->win_info[COL_PROTOCOL], "DDP"); - strcpy(fd->win_info[COL_INFO], + if (check_col(fd, COL_RES_NET_SRC)) + col_add_fstr(fd, COL_RES_NET_SRC, "%d.%d:%d", ddp.snet, ddp.snode, ddp.sport); + if (check_col(fd, COL_RES_NET_DST)) + col_add_fstr(fd, COL_RES_NET_DST, "%d.%d:%d", ddp.dnet, ddp.dnode, ddp.dport); + if (check_col(fd, COL_PROTOCOL)) + col_add_str(fd, COL_PROTOCOL, "DDP"); + if (check_col(fd, COL_INFO)) + col_add_str(fd, COL_INFO, val_to_str(ddp.type, op_vals, "Unknown DDP protocol (%02x)")); - - sprintf(fd->win_info[COL_SOURCE],"%d.%d:%d",ddp.snet,ddp.snode,ddp.sport); - sprintf(fd->win_info[COL_DESTINATION], "%d.%d:%d",ddp.dnet,ddp.dnode,ddp.dport); - } if (tree) { ti = add_item_to_tree(GTK_WIDGET(tree), offset, 13, diff --git a/packet-bootp.c b/packet-bootp.c index 83931d1cad..e3e77ff75f 100644 --- a/packet-bootp.c +++ b/packet-bootp.c @@ -2,7 +2,7 @@ * Routines for BOOTP/DHCP packet disassembly * Gilbert Ramirez <gram@verdict.uthscsa.edu> * - * $Id: packet-bootp.c,v 1.9 1998/11/12 21:39:18 gram Exp $ + * $Id: packet-bootp.c,v 1.10 1998/11/17 04:28:51 gerald Exp $ * * The information used comes from: * RFC 2132: DHCP Options and BOOTP Vendor Extensions @@ -388,16 +388,17 @@ dissect_bootp(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) GtkWidget *bp_tree, *ti; int voff, eoff; /* vender offset, end offset */ - if (fd->win_info[COL_NUM]) { - strcpy(fd->win_info[COL_PROTOCOL], "BOOTP"); + if (check_col(fd, COL_PROTOCOL)) + col_add_str(fd, COL_PROTOCOL, "BOOTP"); + if (check_col(fd, COL_INFO)) { /* if hwaddr is 6 bytes, assume MAC */ if (pd[offset] == 1 && pd[offset+2] == 6) { - sprintf(fd->win_info[COL_INFO], "Boot Request from %s", + col_add_fstr(fd, COL_INFO, "Boot Request from %s", ether_to_str((guint8*)&pd[offset+28])); } else { - strcpy(fd->win_info[COL_INFO], pd[offset] == 1 ? "Boot Request" : + col_add_str(fd, COL_INFO, pd[offset] == 1 ? "Boot Request" : "Boot Reply"); } } diff --git a/packet-dns.c b/packet-dns.c index 21f7a67be0..5416706934 100644 --- a/packet-dns.c +++ b/packet-dns.c @@ -1,7 +1,7 @@ /* packet-dns.c * Routines for DNS packet disassembly * - * $Id: packet-dns.c,v 1.8 1998/11/12 00:06:26 gram Exp $ + * $Id: packet-dns.c,v 1.9 1998/11/17 04:28:51 gerald Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -463,10 +463,10 @@ dissect_dns(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) { query = ! (flags & (1 << 15)); - if (fd->win_info[COL_NUM]) { - strcpy(fd->win_info[COL_PROTOCOL], "DNS (UDP)"); - strcpy(fd->win_info[COL_INFO], query ? "Query" : "Response"); - } + if (check_col(fd, COL_PROTOCOL)) + col_add_str(fd, COL_PROTOCOL, "DNS (UDP)"); + if (check_col(fd, COL_INFO)) + col_add_str(fd, COL_INFO, query ? "Query" : "Response"); if (tree) { ti = add_item_to_tree(GTK_WIDGET(tree), offset, 4, diff --git a/packet-eth.c b/packet-eth.c index 60aeddf88e..57ef1fcc46 100644 --- a/packet-eth.c +++ b/packet-eth.c @@ -1,7 +1,7 @@ /* packet-eth.c * Routines for ethernet packet disassembly * - * $Id: packet-eth.c,v 1.6 1998/11/12 00:06:26 gram Exp $ + * $Id: packet-eth.c,v 1.7 1998/11/17 04:28:52 gerald Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -62,11 +62,18 @@ dissect_eth(const u_char *pd, frame_data *fd, GtkTree *tree) { GtkWidget *fh_tree = NULL, *ti; int ethhdr_type; /* the type of ethernet frame */ - if (fd->win_info[COL_NUM]) { - strcpy(fd->win_info[COL_DESTINATION], get_ether_name((u_char *)&pd[0])); - strcpy(fd->win_info[COL_SOURCE], get_ether_name((u_char *)&pd[6])); - strcpy(fd->win_info[COL_INFO], "Ethernet II"); - } + if (check_col(fd, COL_RES_DL_DST)) + col_add_str(fd, COL_RES_DL_DST, get_ether_name((u_char *)&pd[0])); + if (check_col(fd, COL_RES_DL_SRC)) + col_add_str(fd, COL_RES_DL_SRC, get_ether_name((u_char *)&pd[6])); + if (check_col(fd, COL_UNRES_DL_DST)) + col_add_str(fd, COL_UNRES_DL_DST, ether_to_str((u_char *)&pd[0])); + if (check_col(fd, COL_UNRES_DL_SRC)) + col_add_str(fd, COL_UNRES_DL_SRC, ether_to_str((u_char *)&pd[6])); + if (check_col(fd, COL_PROTOCOL)) + col_add_str(fd, COL_PROTOCOL, "N/A"); + if (check_col(fd, COL_INFO)) + col_add_str(fd, COL_INFO, "Ethernet II"); etype = (pd[12] << 8) | pd[13]; @@ -87,7 +94,8 @@ dissect_eth(const u_char *pd, frame_data *fd, GtkTree *tree) { ethhdr_type = ETHERNET_802_2; } - if (fd->win_info[COL_NUM]) { sprintf(fd->win_info[COL_INFO], "802.3"); } + if (check_col(fd, COL_INFO)) + col_add_str(fd, COL_INFO, "802.3"); if (tree) { ti = add_item_to_tree(GTK_WIDGET(tree), 0, offset, "IEEE 802.3 %s", (ethhdr_type == ETHERNET_802_3 ? "Raw " : "")); diff --git a/packet-fddi.c b/packet-fddi.c index 2bcdffe749..b131839a0f 100644 --- a/packet-fddi.c +++ b/packet-fddi.c @@ -3,7 +3,7 @@ * * Laurent Deniel <deniel@worldnet.fr> * - * $Id: packet-fddi.c,v 1.7 1998/11/12 21:22:47 guy Exp $ + * $Id: packet-fddi.c,v 1.8 1998/11/17 04:28:53 gerald Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -151,11 +151,18 @@ void dissect_fddi(const u_char *pd, frame_data *fd, GtkTree *tree) fc = (int) pd[FDDI_P_FC]; - if (fd->win_info[COL_NUM]) { - strcpy(fd->win_info[COL_DESTINATION], get_ether_name(dst)); - strcpy(fd->win_info[COL_SOURCE], get_ether_name(src)); - strcpy(fd->win_info[COL_INFO], "FDDI"); - } + if (check_col(fd, COL_RES_DL_SRC)) + col_add_str(fd, COL_RES_DL_SRC, get_ether_name(src)); + if (check_col(fd, COL_RES_DL_DST)) + col_add_str(fd, COL_RES_DL_DST, get_ether_name(dst)); + if (check_col(fd, COL_UNRES_DL_SRC)) + col_add_str(fd, COL_UNRES_DL_SRC, ether_to_str(src)); + if (check_col(fd, COL_UNRES_DL_DST)) + col_add_str(fd, COL_UNRES_DL_DST, ether_to_str(dst)); + if (check_col(fd, COL_PROTOCOL)) + col_add_str(fd, COL_PROTOCOL, "N/A"); + if (check_col(fd, COL_INFO)) + col_add_str(fd, COL_INFO, "FDDI"); if (tree) { ti = add_item_to_tree(GTK_WIDGET(tree), 0, offset, diff --git a/packet-ip.c b/packet-ip.c index 5f70b4299f..fa703cfa4d 100644 --- a/packet-ip.c +++ b/packet-ip.c @@ -1,7 +1,7 @@ /* packet-ip.c * Routines for IP and miscellaneous IP protocol packet disassembly * - * $Id: packet-ip.c,v 1.11 1998/11/12 00:06:28 gram Exp $ + * $Id: packet-ip.c,v 1.12 1998/11/17 04:28:54 gerald Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -403,23 +403,29 @@ dissect_ip(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) { hlen = iph.ip_hl * 4; /* IP header length, in bytes */ - if (fd->win_info[COL_NUM]) { - switch (iph.ip_p) { - case IP_PROTO_ICMP: - case IP_PROTO_IGMP: - case IP_PROTO_TCP: - case IP_PROTO_UDP: - case IP_PROTO_OSPF: - /* Names are set in the associated dissect_* routines */ - break; - default: - strcpy(fd->win_info[COL_PROTOCOL], "IP"); - sprintf(fd->win_info[COL_INFO], "Unknown IP protocol (%02x)", iph.ip_p); - } - - strcpy(fd->win_info[COL_SOURCE], get_hostname(iph.ip_src)); - strcpy(fd->win_info[COL_DESTINATION], get_hostname(iph.ip_dst)); + switch (iph.ip_p) { + case IP_PROTO_ICMP: + case IP_PROTO_IGMP: + case IP_PROTO_TCP: + case IP_PROTO_UDP: + case IP_PROTO_OSPF: + /* Names are set in the associated dissect_* routines */ + break; + default: + if (check_col(fd, COL_PROTOCOL)) + col_add_str(fd, COL_PROTOCOL, "IP"); + if (check_col(fd, COL_INFO)) + col_add_fstr(fd, COL_INFO, "Unknown IP protocol (%02x)", iph.ip_p); } + + if (check_col(fd, COL_RES_NET_SRC)) + col_add_str(fd, COL_RES_NET_SRC, get_hostname(iph.ip_src)); + if (check_col(fd, COL_UNRES_NET_SRC)) + col_add_str(fd, COL_UNRES_NET_SRC, ip_to_str((guint8 *) &iph.ip_src)); + if (check_col(fd, COL_RES_NET_DST)) + col_add_str(fd, COL_RES_NET_DST, get_hostname(iph.ip_dst)); + if (check_col(fd, COL_UNRES_NET_DST)) + col_add_str(fd, COL_UNRES_NET_DST, ip_to_str((guint8 *) &iph.ip_dst)); iph.ip_tos = IPTOS_TOS(iph.ip_tos); switch (iph.ip_tos) { @@ -466,10 +472,12 @@ dissect_ip(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) { val_to_str(iph.ip_p, proto_vals, "Unknown (%x)")); add_item_to_tree(ip_tree, offset + 10, 2, "Header checksum: 0x%04x", iph.ip_sum); - add_item_to_tree(ip_tree, offset + 12, 4, "Source address: %s", - get_hostname(iph.ip_src)); - add_item_to_tree(ip_tree, offset + 16, 4, "Destination address: %s", - get_hostname(iph.ip_dst)); + add_item_to_tree(ip_tree, offset + 12, 4, "Source address: %s (%s)", + get_hostname(iph.ip_src), + ip_to_str((guint8 *) &iph.ip_src)); + add_item_to_tree(ip_tree, offset + 16, 4, "Destination address: %s (%s)", + get_hostname(iph.ip_dst), + ip_to_str((guint8 *) &iph.ip_dst)); /* Decode IP options, if any. */ if (hlen > sizeof (e_ip)) { @@ -606,10 +614,10 @@ dissect_icmp(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) { strcpy(type_str, "Unknown ICMP (obsolete or malformed?)"); } - if (fd->win_info[COL_NUM]) { - strcpy(fd->win_info[COL_PROTOCOL], "ICMP"); - strcpy(fd->win_info[COL_INFO], type_str); - } + if (check_col(fd, COL_PROTOCOL)) + col_add_str(fd, COL_PROTOCOL, "ICMP"); + if (check_col(fd, COL_INFO)) + col_add_str(fd, COL_INFO, type_str); if (tree) { ti = add_item_to_tree(GTK_WIDGET(tree), offset, 4, @@ -666,9 +674,10 @@ dissect_igmp(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) { strcpy(type_str, "Unknown IGMP"); } - if (fd->win_info[COL_NUM]) { - strcpy(fd->win_info[COL_PROTOCOL], "IGMP"); - } + if (check_col(fd, COL_PROTOCOL)) + col_add_str(fd, COL_PROTOCOL, "IGMP"); + if (check_col(fd, COL_INFO)) + col_add_str(fd, COL_INFO, type_str); if (tree) { ti = add_item_to_tree(GTK_WIDGET(tree), offset, 4, diff --git a/packet-ipv6.c b/packet-ipv6.c index 1335f58685..b9466e5b22 100644 --- a/packet-ipv6.c +++ b/packet-ipv6.c @@ -1,7 +1,7 @@ /* packet-ipv6.c * Routines for IPv6 packet disassembly * - * $Id: packet-ipv6.c,v 1.4 1998/11/12 00:06:29 gram Exp $ + * $Id: packet-ipv6.c,v 1.5 1998/11/17 04:28:55 gerald Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -52,22 +52,23 @@ dissect_ipv6(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) { memcpy(&ipv6, (void *) &pd[offset], 8); - if (fd->win_info[COL_NUM]) { - switch(ipv6.next_header){ - /* - case IP_PROTO_ICMP: - case IP_PROTO_IGMP: - case IP_PROTO_TCP: - case IP_PROTO_UDP: - case IP_PROTO_OSPF: - */ - /* Names are set in the associated dissect_* routines */ - /* break; */ - default: - strcpy(fd->win_info[COL_PROTOCOL], "IPv6"); - sprintf(fd->win_info[COL_INFO], "IPv6 support is still under development (%d)", ipv6.next_header); - } + switch(ipv6.next_header){ + /* + case IP_PROTO_ICMP: + case IP_PROTO_IGMP: + case IP_PROTO_TCP: + case IP_PROTO_UDP: + case IP_PROTO_OSPF: + */ + /* Names are set in the associated dissect_* routines */ + /* break; */ + default: + if (check_col(fd, COL_PROTOCOL)) + col_add_str(fd, COL_PROTOCOL, "IPv6"); + if (check_col(fd, COL_INFO)) + col_add_fstr(fd, COL_INFO, "IPv6 support is still under development (%d)", ipv6.next_header); } + if (tree) { /* !!! specify length */ ti = add_item_to_tree(GTK_WIDGET(tree), offset, 40, diff --git a/packet-ipx.c b/packet-ipx.c index e94fbc0bef..7fb4139fca 100644 --- a/packet-ipx.c +++ b/packet-ipx.c @@ -2,7 +2,7 @@ * Routines for NetWare's IPX * Gilbert Ramirez <gram@verdict.uthscsa.edu> * - * $Id: packet-ipx.c,v 1.12 1998/11/12 00:06:30 gram Exp $ + * $Id: packet-ipx.c,v 1.13 1998/11/17 04:28:55 gerald Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@unicom.net> @@ -170,15 +170,15 @@ dissect_ipx(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) { guint16 dsocket, ssocket; void (*dissect) (const u_char *, int, frame_data *, GtkTree *); - /* Calculate here for use in win_info[] and in tree */ + /* Calculate here for use in pinfo and in tree */ dnet = ipxnet_to_string((guint8*)&pd[offset+6]); snet = ipxnet_to_string((guint8*)&pd[offset+18]); dsocket = pntohs(&pd[offset+16]); - if (fd->win_info[COL_NUM]) { - strcpy(fd->win_info[COL_PROTOCOL], "IPX"); - sprintf(fd->win_info[COL_INFO], "%s (0x%04X)", port_text(dsocket), dsocket); - } + if (check_col(fd, COL_PROTOCOL)) + col_add_str(fd, COL_PROTOCOL, "IPX"); + if (check_col(fd, COL_INFO)) + col_add_fstr(fd, COL_INFO, "%s (0x%04X)", port_text(dsocket), dsocket); ipx_type = pd[offset+5]; @@ -284,10 +284,10 @@ dissect_spx(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) { GtkWidget *spx_tree, *ti; - if (fd->win_info[COL_NUM]) { - strcpy(fd->win_info[COL_PROTOCOL], "SPX"); - strcpy(fd->win_info[COL_INFO], "SPX"); - } + if (check_col(fd, COL_PROTOCOL)) + col_add_str(fd, COL_PROTOCOL, "SPX"); + if (check_col(fd, COL_INFO)) + col_add_str(fd, COL_INFO, "SPX"); if (tree) { ti = add_item_to_tree(GTK_WIDGET(tree), offset, 12, @@ -338,14 +338,15 @@ dissect_ipxrip(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) { operation = pntohs(&pd[offset]) - 1; - if (fd->win_info[COL_NUM]) { - strcpy(fd->win_info[COL_PROTOCOL], "IPX RIP"); - if (operation < 2) { - sprintf(fd->win_info[COL_INFO], rip_type[operation]); - } - else { - strcpy(fd->win_info[COL_INFO], "Unknown Packet Type"); - } + if (check_col(fd, COL_PROTOCOL)) + col_add_str(fd, COL_PROTOCOL, "IPX RIP"); + if (check_col(fd, COL_PROTOCOL)) { + if (operation < 2) { + col_add_str(fd, COL_INFO, rip_type[operation]); + } + else { + col_add_str(fd, COL_INFO, "Unknown Packet Type"); + } } if (tree) { @@ -457,13 +458,14 @@ dissect_sap(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) { query.query_type = pntohs(&pd[offset]); query.server_type = pntohs(&pd[offset+2]); - if (fd->win_info[COL_NUM]) { - strcpy(fd->win_info[COL_PROTOCOL], "SAP"); + if (check_col(fd, COL_PROTOCOL)) + col_add_str(fd, COL_PROTOCOL, "SAP"); + if (check_col(fd, COL_INFO)) { if (query.query_type < 4) { - sprintf(fd->win_info[COL_INFO], sap_type[query.query_type - 1]); + col_add_str(fd, COL_INFO, sap_type[query.query_type - 1]); } else { - strcpy(fd->win_info[COL_INFO], "Unknown Packet Type"); + col_add_str(fd, COL_INFO, "Unknown Packet Type"); } } diff --git a/packet-llc.c b/packet-llc.c index 9b63756e13..131cb4811f 100644 --- a/packet-llc.c +++ b/packet-llc.c @@ -2,7 +2,7 @@ * Routines for IEEE 802.2 LLC layer * Gilbert Ramirez <gram@verdict.uthscsa.edu> * - * $Id: packet-llc.c,v 1.9 1998/11/12 00:06:30 gram Exp $ + * $Id: packet-llc.c,v 1.10 1998/11/17 04:28:56 gerald Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@unicom.net> @@ -132,8 +132,8 @@ dissect_llc(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) { is_snap = (pd[offset] == 0xAA) && (pd[offset+1] == 0xAA); - if (fd->win_info[COL_NUM]) { - strcpy(fd->win_info[COL_PROTOCOL], "LLC"); + if (check_col(fd, COL_PROTOCOL)) { + col_add_str(fd, COL_PROTOCOL, "LLC"); } if (tree) { @@ -150,8 +150,8 @@ dissect_llc(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) { } if (is_snap) { - if (fd->win_info[COL_NUM]) { - strcpy(fd->win_info[COL_INFO], "802.2 LLC (SNAP)"); + if (check_col(fd, COL_INFO)) { + col_add_str(fd, COL_INFO, "802.2 LLC (SNAP)"); } if (tree) { add_item_to_tree(llc_tree, offset+3, 3, @@ -164,8 +164,8 @@ dissect_llc(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) { ethertype(etype, offset, pd, fd, tree, llc_tree); } else { - if (fd->win_info[COL_NUM]) { - sprintf(fd->win_info[COL_INFO], "802.2 LLC (%s)", sap_text(pd[offset])); + if (check_col(fd, COL_INFO)) { + col_add_fstr(fd, COL_INFO, "802.2 LLC (%s)", sap_text(pd[offset])); } dissect = sap_func(pd[offset]); diff --git a/packet-lpd.c b/packet-lpd.c index 151cd63e4d..49a2f4439a 100644 --- a/packet-lpd.c +++ b/packet-lpd.c @@ -2,7 +2,7 @@ * Routines for LPR and LPRng packet disassembly * Gilbert Ramirez <gram@verdict.uthscsa.edu> * - * $Id: packet-lpd.c,v 1.4 1998/11/12 00:06:31 gram Exp $ + * $Id: packet-lpd.c,v 1.5 1998/11/17 04:28:57 gerald Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@unicom.net> @@ -89,13 +89,14 @@ dissect_lpd(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) } - if (fd->win_info[COL_NUM]) { - strcpy(fd->win_info[COL_PROTOCOL], "LPD"); + if (check_col(fd, COL_PROTOCOL)) + col_add_str(fd, COL_PROTOCOL, "LPD"); + if (check_col(fd, COL_INFO)) { if (lpr_packet_type == request) { - strcpy(fd->win_info[COL_INFO], lpd_client_code[pd[offset]]); + col_add_str(fd, COL_INFO, lpd_client_code[pd[offset]]); } else { - strcpy(fd->win_info[COL_INFO], "LPD response"); + col_add_str(fd, COL_INFO, "LPD response"); } } diff --git a/packet-nbipx.c b/packet-nbipx.c index d35a7f04a9..53833b449d 100644 --- a/packet-nbipx.c +++ b/packet-nbipx.c @@ -2,7 +2,7 @@ * Routines for NetBIOS over IPX packet disassembly * Gilbert Ramirez <gram@verdict.uthscsa.edu> * - * $Id: packet-nbipx.c,v 1.4 1998/11/12 00:06:32 gram Exp $ + * $Id: packet-nbipx.c,v 1.5 1998/11/17 04:28:57 gerald Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -120,22 +120,23 @@ nbipx_ns(const u_char *pd, int offset, frame_data *fd, GtkTree *tree, header.node_name[17] = 0; /* null-terminate the string */ } - if (fd->win_info[COL_NUM]) { + if (check_col(fd, COL_PROTOCOL)) { if (nbipx == NETBIOS_NETWARE) { - strcpy(fd->win_info[COL_PROTOCOL], "NetBIOS"); + col_add_str(fd, COL_PROTOCOL, "NetBIOS"); } else { - strcpy(fd->win_info[COL_PROTOCOL], "NWLink"); + col_add_str(fd, COL_PROTOCOL, "NWLink"); } + } + if (check_col(fd, COL_INFO)) { switch (header.packet_type) { case 1: - sprintf(fd->win_info[COL_INFO], "Name Query for %s", - header.name); + col_add_fstr(fd, COL_INFO, "Name Query for %s", header.name); break; default: - strcpy(fd->win_info[COL_INFO], "NetBIOS over IPX"); + col_add_str(fd, COL_INFO, "NetBIOS over IPX"); } } diff --git a/packet-nbns.c b/packet-nbns.c index 86f24f412d..43be706505 100644 --- a/packet-nbns.c +++ b/packet-nbns.c @@ -3,7 +3,7 @@ * Gilbert Ramirez <gram@verdict.uthscsa.edu> * Much stuff added by Guy Harris <guy@netapp.com> * - * $Id: packet-nbns.c,v 1.6 1998/11/12 00:06:32 gram Exp $ + * $Id: packet-nbns.c,v 1.7 1998/11/17 04:28:58 gerald Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -697,13 +697,14 @@ dissect_nbns(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) header.nscount = pntohs(&pd[offset+8]); header.arcount = pntohs(&pd[offset+10]); - if (fd->win_info[COL_NUM]) { - strcpy(fd->win_info[COL_PROTOCOL], "NBNS (UDP)"); + if (check_col(fd, COL_PROTOCOL)) + col_add_str(fd, COL_PROTOCOL, "NBNS (UDP)"); + if (check_col(fd, COL_INFO)) { if (header.opcode <= 15) { - sprintf(fd->win_info[COL_INFO], "%s %s", + col_add_fstr(fd, COL_INFO, "%s %s", opcode[header.opcode], header.r ? "reply" : "request"); } else { - sprintf(fd->win_info[COL_INFO], "Unknown operation (%d) %s", + col_add_fstr(fd, COL_INFO, "Unknown operation (%d) %s", header.opcode, header.r ? "reply" : "request"); } } diff --git a/packet-ncp.c b/packet-ncp.c index 6c9a10ed7f..e014eba868 100644 --- a/packet-ncp.c +++ b/packet-ncp.c @@ -2,7 +2,7 @@ * Routines for NetWare Core Protocol * Gilbert Ramirez <gram@verdict.uthscsa.edu> * - * $Id: packet-ncp.c,v 1.6 1998/11/12 00:06:34 gram Exp $ + * $Id: packet-ncp.c,v 1.7 1998/11/17 04:28:59 gerald Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@unicom.net> @@ -212,12 +212,12 @@ dissect_ncp(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) { ncp_hdr = 6; /* in order to get ncp_type_text[0] */ } - if (fd->win_info[COL_NUM]) { - strcpy(fd->win_info[COL_PROTOCOL], "NCP"); + if (check_col(fd, COL_PROTOCOL)) + col_add_str(fd, COL_PROTOCOL, "NCP"); + if (check_col(fd, COL_INFO)) /* I take advantage of the ncp_hdr length to use as an index into * ncp_type_text[]. Ugly hack, but quick. */ - sprintf(fd->win_info[COL_INFO], "%s", ncp_type_text[ncp_hdr - 6]); - } + col_add_fstr(fd, COL_INFO, "%s", ncp_type_text[ncp_hdr - 6]); if (tree) { diff --git a/packet-null.c b/packet-null.c index cc7e9c7edd..be02ea3517 100644 --- a/packet-null.c +++ b/packet-null.c @@ -1,7 +1,7 @@ /* packet-null.c * Routines for null packet disassembly * - * $Id: packet-null.c,v 1.4 1998/11/12 00:06:34 gram Exp $ + * $Id: packet-null.c,v 1.5 1998/11/17 04:29:00 gerald Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -50,12 +50,14 @@ dissect_null( const u_char *pd, frame_data *fd, GtkTree *tree ) { /* load the top pane info. This should be overwritten by the next protocol in the stack */ - if(fd->win_info[COL_NUM]) { - strcpy(fd->win_info[COL_SOURCE], "N/A" ); - strcpy(fd->win_info[COL_DESTINATION], "N/A" ); - strcpy(fd->win_info[COL_PROTOCOL], "N/A" ); - strcpy(fd->win_info[COL_INFO], "Null/Loopback" ); - } + if(check_col(fd, COL_RES_DL_SRC)) + col_add_str(fd, COL_RES_DL_SRC, "N/A" ); + if(check_col(fd, COL_RES_DL_DST)) + col_add_str(fd, COL_RES_DL_DST, "N/A" ); + if(check_col(fd, COL_PROTOCOL)) + col_add_str(fd, COL_PROTOCOL, "N/A" ); + if(check_col(fd, COL_INFO)) + col_add_str(fd, COL_INFO, "Null/Loopback" ); /* populate a tree in the second pane with the status of the link layer (ie none) */ diff --git a/packet-osi.c b/packet-osi.c index 7434ff0261..65dcc919d4 100644 --- a/packet-osi.c +++ b/packet-osi.c @@ -1,7 +1,7 @@ /* packet-osi.c * Routines for ISO/OSI network and transport protocol packet disassembly * - * $Id: packet-osi.c,v 1.4 1998/11/12 00:06:35 gram Exp $ + * $Id: packet-osi.c,v 1.5 1998/11/17 04:29:01 gerald Exp $ * Laurent Deniel <deniel@worldnet.fr> * * Ethereal - Network traffic analyzer @@ -240,11 +240,11 @@ static int osi_decode_DR(const u_char *pd, int offset, break; } - if (fd->win_info[COL_NUM]) { - strcpy(fd->win_info[COL_PROTOCOL], "COTP"); - sprintf(fd->win_info[COL_INFO], "DR TPDU src-ref: 0x%04x dst-ref: 0x%04x", + if (check_col(fd, COL_PROTOCOL)) + col_add_str(fd, COL_PROTOCOL, "COTP"); + if (check_col(fd, COL_INFO)) + col_add_fstr(fd, COL_INFO, "DR TPDU src-ref: 0x%04x dst-ref: 0x%04x", src_ref, dst_ref); - } if (tree) { ti = add_item_to_tree(GTK_WIDGET(tree), offset, li + 1, @@ -331,13 +331,13 @@ static int osi_decode_DT(const u_char *pd, int offset, break; } - if (fd->win_info[COL_NUM]) { - strcpy(fd->win_info[COL_PROTOCOL], "COTP"); - sprintf(fd->win_info[COL_INFO], "DT TPDU (%d) dst-ref: 0x%04x %s", + if (check_col(fd, COL_PROTOCOL)) + col_add_str(fd, COL_PROTOCOL, "COTP"); + if (check_col(fd, COL_INFO)) + col_add_fstr(fd, COL_INFO, "DT TPDU (%d) dst-ref: 0x%04x %s", tpdu_nr, dst_ref, (fragment)? "(fragment)" : ""); - } if (tree) { ti = add_item_to_tree(GTK_WIDGET(tree), offset, li + 1, @@ -469,10 +469,10 @@ static int osi_decode_ED(const u_char *pd, int offset, break; } /* li */ - if (fd->win_info[COL_NUM]) { - strcpy(fd->win_info[COL_PROTOCOL], "COTP"); - sprintf(fd->win_info[COL_INFO], "ED TPDU (%d) dst-ref: 0x%04x", tpdu_nr, dst_ref); - } + if (check_col(fd, COL_PROTOCOL)) + col_add_str(fd, COL_PROTOCOL, "COTP"); + if (check_col(fd, COL_INFO)) + col_add_fstr(fd, COL_INFO, "ED TPDU (%d) dst-ref: 0x%04x", tpdu_nr, dst_ref); if (tree) { ti = add_item_to_tree(GTK_WIDGET(tree), offset, li + 1, @@ -552,10 +552,10 @@ static int osi_decode_RJ(const u_char *pd, int offset, break; } - if (fd->win_info[COL_NUM]) { - strcpy(fd->win_info[COL_PROTOCOL], "COTP"); - sprintf(fd->win_info[COL_INFO], "RJ TPDU (%d) dst-ref: 0x%04x", tpdu_nr, dst_ref); - } + if (check_col(fd, COL_PROTOCOL)) + col_add_str(fd, COL_PROTOCOL, "COTP"); + if (check_col(fd, COL_INFO)) + col_add_fstr(fd, COL_INFO, "RJ TPDU (%d) dst-ref: 0x%04x", tpdu_nr, dst_ref); if (tree) { ti = add_item_to_tree(GTK_WIDGET(tree), offset, li + 1, @@ -638,13 +638,13 @@ static int osi_decode_CC(const u_char *pd, int offset, if (class_option > 4) return -1; - if (fd->win_info[COL_NUM]) { - strcpy(fd->win_info[COL_PROTOCOL], "COTP"); - sprintf(fd->win_info[COL_INFO], "%s TPDU src-ref: 0x%04x dst-ref: 0x%04x", + if (check_col(fd, COL_PROTOCOL)) + col_add_str(fd, COL_PROTOCOL, "COTP"); + if (check_col(fd, COL_INFO)) + col_add_fstr(fd, COL_INFO, "%s TPDU src-ref: 0x%04x dst-ref: 0x%04x", (tpdu == CR_TPDU) ? "CR" : "CC", src_ref, dst_ref); - } if (tree) { ti = add_item_to_tree(GTK_WIDGET(tree), offset, li + 1, @@ -912,12 +912,12 @@ static int osi_decode_DC(const u_char *pd, int offset, break; } /* li */ - if (fd->win_info[COL_NUM]) { - strcpy(fd->win_info[COL_PROTOCOL], "COTP"); - sprintf(fd->win_info[COL_INFO], "DC TPDU src-ref: 0x%04x dst-ref: 0x%04x", + if (check_col(fd, COL_PROTOCOL)) + col_add_str(fd, COL_PROTOCOL, "COTP"); + if (check_col(fd, COL_INFO)) + col_add_fstr(fd, COL_INFO, "DC TPDU src-ref: 0x%04x dst-ref: 0x%04x", src_ref, dst_ref); - } if (tree) { ti = add_item_to_tree(GTK_WIDGET(tree), offset, li + 1, @@ -967,11 +967,11 @@ static int osi_decode_AK(const u_char *pd, int offset, if (!is_LI_NORMAL_AK(li)) { tpdu_nr = pd[offset + P_TPDU_NR_234]; - if (fd->win_info[COL_NUM]) { - strcpy(fd->win_info[COL_PROTOCOL], "COTP"); - sprintf(fd->win_info[COL_INFO], "AK TPDU (%d) dst-ref: 0x%04x", + if (check_col(fd, COL_PROTOCOL)) + col_add_str(fd, COL_PROTOCOL, "COTP"); + if (check_col(fd, COL_INFO)) + col_add_fstr(fd, COL_INFO, "AK TPDU (%d) dst-ref: 0x%04x", tpdu_nr, dst_ref); - } if (tree) { ti = add_item_to_tree(GTK_WIDGET(tree), offset, li + 1, @@ -1075,11 +1075,11 @@ static int osi_decode_AK(const u_char *pd, int offset, tpdu_nr = EXTRACT_LONG(&pd[offset + P_TPDU_NR_234]); cdt_in_ak = EXTRACT_SHORT(&pd[offset + P_CDT_IN_AK]); - if (fd->win_info[COL_NUM]) { - strcpy(fd->win_info[COL_PROTOCOL], "COTP"); - sprintf(fd->win_info[COL_INFO], "AK TPDU (%d) dst-ref: 0x%04x", + if (check_col(fd, COL_PROTOCOL)) + col_add_str(fd, COL_PROTOCOL, "COTP"); + if (check_col(fd, COL_INFO)) + col_add_fstr(fd, COL_INFO, "AK TPDU (%d) dst-ref: 0x%04x", tpdu_nr, dst_ref); - } if (tree) { ti = add_item_to_tree(GTK_WIDGET(tree), offset, li + 1, @@ -1229,10 +1229,10 @@ static int osi_decode_EA(const u_char *pd, int offset, break; } /* li */ - if (fd->win_info[COL_NUM]) { - strcpy(fd->win_info[COL_PROTOCOL], "COTP"); - sprintf(fd->win_info[COL_INFO], "EA TPDU (%d) dst-ref: 0x%04x", tpdu_nr, dst_ref); - } + if (check_col(fd, COL_PROTOCOL)) + col_add_str(fd, COL_PROTOCOL, "COTP"); + if (check_col(fd, COL_INFO)) + col_add_fstr(fd, COL_INFO, "EA TPDU (%d) dst-ref: 0x%04x", tpdu_nr, dst_ref); if (tree) { ti = add_item_to_tree(GTK_WIDGET(tree), offset, li + 1, @@ -1315,10 +1315,10 @@ static int osi_decode_ER(const u_char *pd, int offset, break; } - if (fd->win_info[COL_NUM]) { - strcpy(fd->win_info[COL_PROTOCOL], "COTP"); - sprintf(fd->win_info[COL_INFO], "ER TPDU dst-ref: 0x%04x", dst_ref); - } + if (check_col(fd, COL_PROTOCOL)) + col_add_str(fd, COL_PROTOCOL, "COTP"); + if (check_col(fd, COL_INFO)) + col_add_fstr(fd, COL_INFO, "ER TPDU dst-ref: 0x%04x", dst_ref); if (tree) { ti = add_item_to_tree(GTK_WIDGET(tree), offset, li + 1, @@ -1514,12 +1514,12 @@ void dissect_clnp(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) print_nsap(&pd[offset + dst_len + 2], src_len)); } - if (fd->win_info[COL_NUM]) { - sprintf(fd->win_info[COL_SOURCE], "%s", + if (check_col(fd, COL_RES_NET_SRC)) + col_add_fstr(fd, COL_RES_NET_SRC, "%s", print_nsap(&pd[offset + dst_len + 2], src_len)); - sprintf(fd->win_info[COL_DESTINATION], "%s", + if (check_col(fd, COL_RES_NET_DST)) + col_add_fstr(fd, COL_RES_NET_DST, "%s", print_nsap(&pd[offset + 1], dst_len)); - } /* Segmentation Part */ @@ -1576,38 +1576,41 @@ void dissect_osi(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) /* only CLNP is currently decoded */ case ISO8473_CLNP: - if (fd->win_info[COL_NUM]) + if (check_col(fd, COL_PROTOCOL)) { - strcpy(fd->win_info[COL_PROTOCOL], "CLNP"); + col_add_str(fd, COL_PROTOCOL, "CLNP"); } dissect_clnp(pd, offset, fd, tree); break; case ISO9542_ESIS: - if (fd->win_info[COL_NUM]) + if (check_col(fd, COL_PROTOCOL)) { - strcpy(fd->win_info[COL_PROTOCOL], "ESIS"); + col_add_str(fd, COL_PROTOCOL, "ESIS"); } dissect_data(pd, offset, fd, tree); break; case ISO9542X25_ESIS: - if (fd->win_info[COL_NUM]) + if (check_col(fd, COL_PROTOCOL)) { - strcpy(fd->win_info[COL_PROTOCOL], "ESIS(X25)"); + col_add_str(fd, COL_PROTOCOL, "ESIS(X25)"); } dissect_data(pd, offset, fd, tree); break; case ISO10589_ISIS: - if (fd->win_info[COL_NUM]) + if (check_col(fd, COL_PROTOCOL)) { - strcpy(fd->win_info[COL_PROTOCOL], "ISIS"); + col_add_str(fd, COL_PROTOCOL, "ISIS"); } dissect_data(pd, offset, fd, tree); break; default: - if (fd->win_info[COL_NUM]) + if (check_col(fd, COL_PROTOCOL)) + { + col_add_str(fd, COL_PROTOCOL, "ISO"); + } + if (check_col(fd, COL_INFO)) { - strcpy(fd->win_info[COL_PROTOCOL], "ISO"); - sprintf(fd->win_info[COL_INFO], "Unknown ISO protocol (%02x)", pd[offset]); + col_add_fstr(fd, COL_INFO, "Unknown ISO protocol (%02x)", pd[offset]); } dissect_data(pd, offset, fd, tree); break; diff --git a/packet-ospf.c b/packet-ospf.c index 3fb182bc2a..dc00129420 100644 --- a/packet-ospf.c +++ b/packet-ospf.c @@ -2,7 +2,7 @@ * Routines for OSPF packet disassembly * (c) Copyright Hannes R. Boehm <hannes@boehm.org> * - * $Id: packet-ospf.c,v 1.7 1998/10/20 05:31:01 guy Exp $ + * $Id: packet-ospf.c,v 1.8 1998/11/17 04:29:02 gerald Exp $ * * At this time, this module is able to analyze OSPF * packets as specified in RFC2328. MOSPF (RFC1584) and other @@ -71,12 +71,13 @@ dissect_ospf(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) { memcpy(&ospfh, &pd[offset], sizeof(e_ospfhdr)); packet_type = match_strval(ospfh.packet_type, pt_vals); - if (fd->win_info[COL_NUM]) { - strcpy(fd->win_info[COL_PROTOCOL], "OSPF"); + if (check_col(fd, COL_PROTOCOL)) + col_add_str(fd, COL_PROTOCOL, "OSPF"); + if (check_col(fd, COL_INFO)) { if (packet_type != NULL) - sprintf(fd->win_info[COL_INFO], "%s", packet_type); + col_add_str(fd, COL_INFO, packet_type); else - sprintf(fd->win_info[COL_INFO], "Unknown (%d)", ospfh.packet_type); + col_add_fstr(fd, COL_INFO, "Unknown (%d)", ospfh.packet_type); } if (tree) { diff --git a/packet-ppp.c b/packet-ppp.c index 2a30a24912..1a0d1a8c3c 100644 --- a/packet-ppp.c +++ b/packet-ppp.c @@ -1,7 +1,7 @@ /* packet-ppp.c * Routines for ppp packet disassembly * - * $Id: packet-ppp.c,v 1.7 1998/11/12 00:06:36 gram Exp $ + * $Id: packet-ppp.c,v 1.8 1998/11/17 04:29:03 gerald Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -79,12 +79,14 @@ dissect_ppp( const u_char *pd, frame_data *fd, GtkTree *tree ) { /* load the top pane info. This should be overwritten by the next protocol in the stack */ - if(fd->win_info[COL_NUM]) { - strcpy(fd->win_info[COL_SOURCE], "N/A" ); - strcpy(fd->win_info[COL_DESTINATION], "N/A" ); - strcpy(fd->win_info[COL_PROTOCOL], "N/A" ); - strcpy(fd->win_info[COL_INFO], "PPP" ); - } + if(check_col(fd, COL_RES_DL_SRC)) + col_add_str(fd, COL_RES_DL_SRC, "N/A" ); + if(check_col(fd, COL_RES_DL_DST)) + col_add_str(fd, COL_RES_DL_DST, "N/A" ); + if(check_col(fd, COL_PROTOCOL)) + col_add_str(fd, COL_PROTOCOL, "N/A" ); + if(check_col(fd, COL_INFO)) + col_add_str(fd, COL_INFO, "PPP" ); /* populate a tree in the second pane with the status of the link layer (ie none) */ @@ -117,7 +119,8 @@ dissect_ppp( const u_char *pd, frame_data *fd, GtkTree *tree ) { break; default: dissect_data(pd, 4, fd, tree); - if (fd->win_info[COL_NUM]) { sprintf(fd->win_info[COL_PROTOCOL], "0x%04x", ph.ppp_prot); } + if (check_col(fd, COL_PROTOCOL)) + col_add_fstr(fd, COL_PROTOCOL, "0x%04x", ph.ppp_prot); break; } } diff --git a/packet-raw.c b/packet-raw.c index af01fe3aba..9836df75ae 100644 --- a/packet-raw.c +++ b/packet-raw.c @@ -1,7 +1,7 @@ /* packet-raw.c * Routines for raw packet disassembly * - * $Id: packet-raw.c,v 1.6 1998/11/12 00:06:37 gram Exp $ + * $Id: packet-raw.c,v 1.7 1998/11/17 04:29:04 gerald Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -44,11 +44,14 @@ dissect_raw( const u_char *pd, frame_data *fd, GtkTree *tree ) { /* load the top pane info. This should be overwritten by the next protocol in the stack */ - if(fd->win_info[COL_NUM]) { - strcpy(fd->win_info[COL_SOURCE], "N/A" ); - strcpy(fd->win_info[COL_DESTINATION], "N/A" ); - strcpy(fd->win_info[COL_INFO], "Raw packet data" ); - } + if(check_col(fd, COL_RES_DL_SRC)) + col_add_str(fd, COL_RES_DL_SRC, "N/A" ); + if(check_col(fd, COL_RES_DL_DST)) + col_add_str(fd, COL_RES_DL_DST, "N/A" ); + if(check_col(fd, COL_PROTOCOL)) + col_add_str(fd, COL_PROTOCOL, "N/A" ); + if(check_col(fd, COL_INFO)) + col_add_str(fd, COL_INFO, "Raw packet data" ); /* populate a tree in the second pane with the status of the link layer (ie none) */ diff --git a/packet-rip.c b/packet-rip.c index 589061fdd1..ae5f251678 100644 --- a/packet-rip.c +++ b/packet-rip.c @@ -2,7 +2,7 @@ * Routines for RIPv1 and RIPv2 packet disassembly * (c) Copyright Hannes R. Boehm <hannes@boehm.org> * - * $Id: packet-rip.c,v 1.3 1998/09/27 22:12:38 gerald Exp $ + * $Id: packet-rip.c,v 1.4 1998/11/17 04:29:04 gerald Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -86,10 +86,10 @@ dissect_rip(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) { } - if (fd->win_info[COL_NUM]) { - strcpy(fd->win_info[COL_PROTOCOL], version[rip_header->version] ); - sprintf(fd->win_info[COL_INFO], "%s", packet_type[rip_header->command]); - } + if (check_col(fd, COL_PROTOCOL)) + col_add_str(fd, COL_PROTOCOL, version[rip_header->version] ); + if (check_col(fd, COL_INFO)) + col_add_str(fd, COL_INFO, packet_type[rip_header->command]); if (tree) { ti = add_item_to_tree(GTK_WIDGET(tree), offset, (fd->cap_len - offset), "Routing Information Protocol"); diff --git a/packet-tcp.c b/packet-tcp.c index 97d9f02e3b..433ab55e5d 100644 --- a/packet-tcp.c +++ b/packet-tcp.c @@ -1,7 +1,7 @@ /* packet-tcp.c * Routines for TCP packet disassembly * - * $Id: packet-tcp.c,v 1.5 1998/10/13 05:40:04 guy Exp $ + * $Id: packet-tcp.c,v 1.6 1998/11/17 04:29:05 gerald Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -250,11 +250,11 @@ dissect_tcp(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) { } flags[fpos] = '\0'; - if (fd->win_info[COL_NUM]) { - strcpy(fd->win_info[COL_PROTOCOL], "TCP"); - sprintf(fd->win_info[COL_INFO], "Source port: %d Destination port: %d", + if (check_col(fd, COL_PROTOCOL)) + col_add_str(fd, COL_PROTOCOL, "TCP"); + if (check_col(fd, COL_INFO)) + col_add_fstr(fd, COL_INFO, "Source port: %d Destination port: %d", th.th_sport, th.th_dport); - } hlen = th.th_off * 4; /* TCP header length, in bytes */ diff --git a/packet-tr.c b/packet-tr.c index b14e75e6a5..89702e8a11 100644 --- a/packet-tr.c +++ b/packet-tr.c @@ -2,7 +2,7 @@ * Routines for Token-Ring packet disassembly * Gilbert Ramirez <gram@verdict.uthscsa.edu> * - * $Id: packet-tr.c,v 1.7 1998/11/12 00:06:38 gram Exp $ + * $Id: packet-tr.c,v 1.8 1998/11/17 04:29:06 gerald Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@unicom.net> @@ -178,12 +178,14 @@ dissect_tr(const u_char *pd, frame_data *fd, GtkTree *tree) { /* information window */ - if (fd->win_info[COL_NUM]) { - strcpy(fd->win_info[COL_DESTINATION], ether_to_str((guint8 *)&pd[2])); - strcpy(fd->win_info[COL_SOURCE], ether_to_str(trn_shost_nonsr)); - strcpy(fd->win_info[COL_PROTOCOL], "TR"); - sprintf(fd->win_info[COL_INFO], "Token-Ring %s", fc[frame_type]); - } + if (check_col(fd, COL_RES_DL_DST)) + col_add_str(fd, COL_RES_DL_DST, ether_to_str((guint8 *)&pd[2])); + if (check_col(fd, COL_RES_DL_SRC)) + col_add_str(fd, COL_RES_DL_SRC, ether_to_str(trn_shost_nonsr)); + if (check_col(fd, COL_PROTOCOL)) + col_add_str(fd, COL_PROTOCOL, "TR"); + if (check_col(fd, COL_INFO)) + col_add_fstr(fd, COL_INFO, "Token-Ring %s", fc[frame_type]); /* protocol analysis tree */ if (tree) { diff --git a/packet-trmac.c b/packet-trmac.c index c9e06b3abe..2ef6974ff8 100644 --- a/packet-trmac.c +++ b/packet-trmac.c @@ -2,7 +2,7 @@ * Routines for Token-Ring Media Access Control * Gilbert Ramirez <gram@verdict.uthscsa.edu> * - * $Id: packet-trmac.c,v 1.7 1998/11/12 00:06:39 gram Exp $ + * $Id: packet-trmac.c,v 1.8 1998/11/17 04:29:06 gerald Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@unicom.net> @@ -277,10 +277,10 @@ dissect_trmac(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) { mv_text = match_strval(pd[offset+3], major_vectors); /* Summary information */ - if (fd->win_info[COL_NUM]) { - strcpy(fd->win_info[COL_PROTOCOL], "TR MAC"); - strcpy(fd->win_info[COL_INFO], mv_text); - } + if (check_col(fd, COL_PROTOCOL)) + col_add_str(fd, COL_PROTOCOL, "TR MAC"); + if (check_col(fd, COL_INFO)) + col_add_str(fd, COL_INFO, mv_text); if (tree) { if (mv_text) diff --git a/packet-udp.c b/packet-udp.c index cec5c5b9ee..8ac5c3ff24 100644 --- a/packet-udp.c +++ b/packet-udp.c @@ -1,7 +1,7 @@ /* packet-udp.c * Routines for UDP packet disassembly * - * $Id: packet-udp.c,v 1.6 1998/10/14 08:47:16 guy Exp $ + * $Id: packet-udp.c,v 1.7 1998/11/17 04:29:07 gerald Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -57,11 +57,11 @@ dissect_udp(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) { uh_ulen = ntohs(uh.uh_ulen); uh_sum = ntohs(uh.uh_sum); - if (fd->win_info[COL_NUM]) { - strcpy(fd->win_info[COL_PROTOCOL], "UDP"); - sprintf(fd->win_info[COL_INFO], "Source port: %s Destination port: %s", + if (check_col(fd, COL_PROTOCOL)) + col_add_str(fd, COL_PROTOCOL, "UDP"); + if (check_col(fd, COL_INFO)) + col_add_fstr(fd, COL_INFO, "Source port: %s Destination port: %s", get_udp_port(uh_sport), get_udp_port(uh_dport)); - } if (tree) { ti = add_item_to_tree(GTK_WIDGET(tree), offset, 8, diff --git a/packet-vines.c b/packet-vines.c index 453cf60447..a174902949 100644 --- a/packet-vines.c +++ b/packet-vines.c @@ -1,7 +1,7 @@ /* packet-vines.c * Routines for Banyan VINES protocol packet disassembly * - * $Id: packet-vines.c,v 1.3 1998/11/12 00:06:39 gram Exp $ + * $Id: packet-vines.c,v 1.4 1998/11/17 04:29:08 gerald Exp $ * * Don Lafontaine <lafont02@cn.ca> * @@ -65,26 +65,31 @@ dissect_vines(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) iph.vip_dsub = pntohs(&pd[offset+10]); iph.vip_ssub = pntohs(&pd[offset+16]); - if (fd->win_info[COL_NUM]) - { switch (iph.vip_proto) { case VINES_VSPP: - strcpy(fd->win_info[COL_PROTOCOL], "Vines"); - sprintf(fd->win_info[COL_INFO], "VSPP (%02x)", iph.vip_proto); + if (check_col(fd, COL_PROTOCOL)) + col_add_str(fd, COL_PROTOCOL, "Vines"); + if (check_col(fd, COL_INFO)) + col_add_fstr(fd, COL_INFO, "VSPP (%02x)", iph.vip_proto); break; case VINES_DATA: - strcpy(fd->win_info[COL_PROTOCOL], "Vines IP"); - sprintf(fd->win_info[COL_INFO], "DATA (%02x)", iph.vip_proto); + if (check_col(fd, COL_PROTOCOL)) + col_add_str(fd, COL_PROTOCOL, "Vines IP"); + if (check_col(fd, COL_INFO)) + col_add_fstr(fd, COL_INFO, "DATA (%02x)", iph.vip_proto); break; default: - strcpy(fd->win_info[COL_PROTOCOL], "Vines IP"); - sprintf(fd->win_info[COL_INFO], "Unknown VIP protocol (%02x)", iph.vip_proto); + if (check_col(fd, COL_PROTOCOL)) + col_add_str(fd, COL_PROTOCOL, "Vines IP"); + if (check_col(fd, COL_INFO)) + col_add_fstr(fd, COL_INFO, "Unknown VIP protocol (%02x)", iph.vip_proto); } - sprintf(fd->win_info[COL_SOURCE], "%08x.%04x", iph.vip_snet, iph.vip_ssub); - sprintf(fd->win_info[COL_DESTINATION], "%08x.%04x", iph.vip_dnet, iph.vip_dsub); - } + if (check_col(fd, COL_RES_NET_SRC)) + col_add_fstr(fd, COL_RES_NET_SRC, "%08x.%04x", iph.vip_snet, iph.vip_ssub); + if (check_col(fd, COL_RES_NET_DST)) + col_add_fstr(fd, COL_RES_NET_DST, "%08x.%04x", iph.vip_dnet, iph.vip_dsub); /* iph.ip_tos = IPTOS_TOS(iph.ip_tos); switch (iph.ip_tos) @@ -148,28 +153,31 @@ void dissect_vspp(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) iph.vspp_lclid = ntohs(iph.vspp_lclid); iph.vspp_rmtid = ntohs(iph.vspp_rmtid); - if (fd->win_info[COL_NUM]) - { - switch (iph.vspp_pkttype) - { - case VINES_VSPP_DATA: - strcpy(fd->win_info[COL_PROTOCOL], "Vines"); - sprintf(fd->win_info[COL_INFO], "VSPP Data Port=%04x(Transient) NS=%04x NR=%04x Window=%04x RID=%04x LID=%04x D=%04x S=%04x", - iph.vspp_sport, iph.vspp_seq, iph.vspp_ack, iph.vspp_win, iph.vspp_rmtid, - iph.vspp_lclid, iph.vspp_dport, iph.vspp_sport); - break; - case VINES_VSPP_ACK: - strcpy(fd->win_info[COL_PROTOCOL], "Vines"); - sprintf(fd->win_info[COL_INFO], "VSPP Ack Port=%04x(Transient) NS=%04x NR=%04x Window=%04x RID=%04x LID=%04x", - iph.vspp_sport, iph.vspp_seq, iph.vspp_ack, iph.vspp_win, iph.vspp_rmtid, - iph.vspp_lclid); - - break; - default: - strcpy(fd->win_info[COL_PROTOCOL], "Vines IP"); - sprintf(fd->win_info[COL_INFO], "Unknown VSPP packet type (%02x)", iph.vspp_pkttype); - } - } + switch (iph.vspp_pkttype) + { + case VINES_VSPP_DATA: + if (check_col(fd, COL_PROTOCOL)) + col_add_str(fd, COL_PROTOCOL, "Vines"); + if (check_col(fd, COL_INFO)) + col_add_fstr(fd, COL_INFO, "VSPP Data Port=%04x(Transient) NS=%04x NR=%04x Window=%04x RID=%04x LID=%04x D=%04x S=%04x", + iph.vspp_sport, iph.vspp_seq, iph.vspp_ack, iph.vspp_win, iph.vspp_rmtid, + iph.vspp_lclid, iph.vspp_dport, iph.vspp_sport); + break; + case VINES_VSPP_ACK: + if (check_col(fd, COL_PROTOCOL)) + col_add_str(fd, COL_PROTOCOL, "Vines"); + if (check_col(fd, COL_INFO)) + col_add_fstr(fd, COL_INFO, "VSPP Ack Port=%04x(Transient) NS=%04x NR=%04x Window=%04x RID=%04x LID=%04x", + iph.vspp_sport, iph.vspp_seq, iph.vspp_ack, iph.vspp_win, iph.vspp_rmtid, + iph.vspp_lclid); + + break; + default: + if (check_col(fd, COL_PROTOCOL)) + col_add_str(fd, COL_PROTOCOL, "Vines IP"); + if (check_col(fd, COL_INFO)) + col_add_fstr(fd, COL_INFO, "Unknown VSPP packet type (%02x)", iph.vspp_pkttype); + } /* iph.ip_tos = IPTOS_TOS(iph.ip_tos); switch (iph.ip_tos) @@ -1,7 +1,7 @@ /* packet.c * Routines for packet disassembly * - * $Id: packet.c,v 1.10 1998/11/12 00:06:40 gram Exp $ + * $Id: packet.c,v 1.11 1998/11/17 04:29:08 gerald Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -155,9 +155,6 @@ add_item_to_tree(GtkWidget *tree, gint start, gint len, va_list ap; gchar label_str[256]; - /* This limits us to a max packet size of 65535 bytes. */ - /* Are there any systems out there with < 32-bit pointers? */ - /* To do: use gtk_object_set_data instead, now that I know it exists. */ va_start(ap, format); vsnprintf(label_str, 256, format, ap); ti = gtk_tree_item_new_with_label(label_str); @@ -232,6 +229,48 @@ match_strval(guint32 val, const value_string *vs) { return(NULL); } +/* Checks to see if a particular packet information element is needed for + the packet list */ +gint +check_col(frame_data *fd, gint el) { + int i; + + if (fd->cinfo) { + for (i = 0; i < fd->cinfo->num_cols; i++) { + if (fd->cinfo->fmt_matx[i][el]) + return TRUE; + } + } + return FALSE; +} + +/* To do: Add check_col checks to the pinfo_add* routines */ + +/* Adds a vararg list to a packet info string. */ +void +col_add_fstr(frame_data *fd, gint el, gchar *format, ...) { + va_list ap; + int i; + + va_start(ap, format); + for (i = 0; i < fd->cinfo->num_cols; i++) { + if (fd->cinfo->fmt_matx[i][el]) + vsnprintf(fd->cinfo->col_data[i], COL_MAX_LEN, format, ap); + } +} + +void +col_add_str(frame_data *fd, gint el, gchar* str) { + int i; + + for (i = 0; i < fd->cinfo->num_cols; i++) { + if (fd->cinfo->fmt_matx[i][el]) { + strncpy(fd->cinfo->col_data[i], str, COL_MAX_LEN); + fd->cinfo->col_data[i][COL_MAX_LEN - 1] = 0; + } + } +} + static const char *mon_names[12] = { "Jan", "Feb", @@ -257,17 +296,19 @@ dissect_packet(const u_char *pd, guint32 ts_secs, guint32 ts_usecs, time_t then; /* Put in frame header information. */ - if (fd->win_info[COL_NUM]) { + if (check_col(fd, COL_ABS_TIME)) { if (timestamp_type == ABSOLUTE) { then = fd->secs; tmp = localtime(&then); - sprintf(fd->win_info[COL_TIME], "%02d:%02d:%02d.%04ld", + col_add_fstr(fd, COL_ABS_TIME, "%02d:%02d:%02d.%04ld", tmp->tm_hour, tmp->tm_min, tmp->tm_sec, (long)fd->usecs/100); - } else - sprintf(fd->win_info[COL_TIME], "%d.%06d", ts_secs, ts_usecs); + } + } + if (check_col(fd, COL_REL_TIME)) { + col_add_fstr(fd, COL_REL_TIME, "%d.%06d", ts_secs, ts_usecs); } if (tree) { @@ -1,7 +1,7 @@ /* packet.h * Definitions for packet disassembly structures and routines * - * $Id: packet.h,v 1.23 1998/11/03 07:45:10 guy Exp $ + * $Id: packet.h,v 1.24 1998/11/17 04:29:09 gerald Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -60,13 +60,21 @@ #define IEEE_802_3_MAX_LEN 1500 #define BYTE_VIEW_WIDTH 16 +typedef struct _column_info { + gint num_cols; /* Number of columns */ + gboolean **fmt_matx; /* Specifies which formats apply to a column */ + gchar **col_data; /* Column data */ +} column_info; + +#define COL_MAX_LEN 256 + typedef struct _frame_data { - guint32 pkt_len; /* Packet length */ - guint32 cap_len; /* Amount actually captured */ - guint32 secs; /* Seconds */ - guint32 usecs; /* Microseconds */ - long file_off; /* File offset */ - gchar *win_info[NUM_COLS]; /* Text for packet summary list fields */ + guint32 pkt_len; /* Packet length */ + guint32 cap_len; /* Amount actually captured */ + guint32 secs; /* Seconds */ + guint32 usecs; /* Microseconds */ + long file_off; /* File offset */ + column_info *cinfo; /* Column formatting information */ } frame_data; typedef struct _packet_info { @@ -477,6 +485,14 @@ GtkWidget* add_item_to_tree(GtkWidget *, gint, gint, gchar *, ...); #endif gchar* val_to_str(guint32, const value_string *, const char *); gchar* match_strval(guint32, const value_string*); +gint check_col(frame_data *, gint); +#if __GNUC__ == 2 +void col_add_fstr(frame_data *, gint, gchar *, ...) + __attribute__((format (printf, 3, 4))); +#else +void col_add_fstr(frame_data *, gint, gchar *, ...); +#endif +void col_add_str(frame_data *, gint, gchar *); /* Routines in packet.c */ @@ -1,7 +1,7 @@ /* prefs.c * Routines for handling preferences * - * $Id: prefs.c,v 1.9 1998/10/29 15:59:00 gerald Exp $ + * $Id: prefs.c,v 1.10 1998/11/17 04:29:10 gerald Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -35,26 +35,35 @@ #include <ctype.h> #include <errno.h> +#include <unistd.h> +#include <sys/stat.h> #include "ethereal.h" #include "packet.h" #include "file.h" #include "prefs.h" +#include "column.h" #include "print.h" #include "filter.h" #include "util.h" /* Internal functions */ -static int set_pref(gchar*, gchar*); -static void write_prefs(); -static void prefs_main_ok_cb(GtkWidget *, gpointer); -static void prefs_main_save_cb(GtkWidget *, gpointer); -static void prefs_main_cancel_cb(GtkWidget *, gpointer); +static int set_pref(gchar*, gchar*); +static void write_prefs(); +static void prefs_main_ok_cb(GtkWidget *, gpointer); +static void prefs_main_save_cb(GtkWidget *, gpointer); +static void prefs_main_cancel_cb(GtkWidget *, gpointer); +static GList *get_string_list(gchar *); +static void clear_string_list(GList *); e_prefs prefs; static int init_prefs = 1; -#define PF_NAME ".ethereal/preferences" +#define PF_NAME "preferences" + +#define E_PRINT_PAGE_KEY "printer_options_page" +#define E_FILTER_PAGE_KEY "filter_options_page" +#define E_COLUMN_PAGE_KEY "column_options_page" static gchar *pf_path = NULL; @@ -62,7 +71,7 @@ void prefs_cb(GtkWidget *w, gpointer sp) { GtkWidget *prefs_w, *main_vb, *top_hb, *bbox, *prefs_nb, *ok_bt, *save_bt, *cancel_bt; - GtkWidget *print_pg, *filter_pg, *filter_te, *label; + GtkWidget *print_pg, *filter_pg, *column_pg, *filter_te, *label; /* GtkWidget *nlabel; */ gint start_page = (gint) sp; @@ -107,6 +116,12 @@ prefs_cb(GtkWidget *w, gpointer sp) { label = gtk_label_new ("Filters"); gtk_notebook_append_page (GTK_NOTEBOOK(prefs_nb), filter_pg, label); + /* Column prefs */ + column_pg = column_prefs_show(); + gtk_object_set_data(GTK_OBJECT(prefs_w), E_COLUMN_PAGE_KEY, column_pg); + label = gtk_label_new ("Columns"); + gtk_notebook_append_page (GTK_NOTEBOOK(prefs_nb), column_pg, label); + /* Jump to the specified page, if it was supplied */ if (start_page > E_PR_PG_NONE) gtk_notebook_set_page(GTK_NOTEBOOK(prefs_nb), start_page); @@ -148,6 +163,7 @@ prefs_main_ok_cb(GtkWidget *w, gpointer win) { printer_prefs_ok(gtk_object_get_data(GTK_OBJECT(win), E_PRINT_PAGE_KEY)); filter_prefs_ok(gtk_object_get_data(GTK_OBJECT(win), E_FILTER_PAGE_KEY)); + column_prefs_ok(gtk_object_get_data(GTK_OBJECT(win), E_COLUMN_PAGE_KEY)); gtk_widget_destroy(GTK_WIDGET(win)); } @@ -155,6 +171,7 @@ void prefs_main_save_cb(GtkWidget *w, gpointer win) { printer_prefs_save(gtk_object_get_data(GTK_OBJECT(win), E_PRINT_PAGE_KEY)); filter_prefs_save(gtk_object_get_data(GTK_OBJECT(win), E_FILTER_PAGE_KEY)); + column_prefs_save(gtk_object_get_data(GTK_OBJECT(win), E_COLUMN_PAGE_KEY)); write_prefs(); } @@ -163,9 +180,67 @@ prefs_main_cancel_cb(GtkWidget *w, gpointer win) { printer_prefs_cancel(gtk_object_get_data(GTK_OBJECT(win), E_PRINT_PAGE_KEY)); filter_prefs_cancel(gtk_object_get_data(GTK_OBJECT(win), E_FILTER_PAGE_KEY)); + column_prefs_cancel(gtk_object_get_data(GTK_OBJECT(win), E_COLUMN_PAGE_KEY)); gtk_widget_destroy(GTK_WIDGET(win)); } +/* Parse through a list of comma-separated, quoted strings. Return a + list of the string data */ +static GList * +get_string_list(gchar *str) { + enum { PRE_QUOT, IN_QUOT, POST_QUOT }; + + gint state = PRE_QUOT, i = 0, j = 0; + gboolean backslash = FALSE; + gchar cur_c, *slstr; + GList *sl = NULL; + + while ((cur_c = str[i]) != '\0') { + if (cur_c == '"' && ! backslash) { + switch (state) { + case PRE_QUOT: + state = IN_QUOT; + slstr = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN); + j = 0; + break; + case IN_QUOT: + state = POST_QUOT; + slstr[j] = '\0'; + sl = g_list_append(sl, slstr); + break; + case POST_QUOT: + clear_string_list(sl); + return NULL; + break; + default: + break; + } + } else if (cur_c == '\\' && ! backslash) { + backslash = TRUE; + } else if (cur_c == ',' && state == POST_QUOT) { + state = PRE_QUOT; + } else if (state == IN_QUOT && j < COL_MAX_LEN) { + slstr[j] = str[i]; + j++; + } + i++; + } + if (state != POST_QUOT) { + clear_string_list(sl); + } + return(sl); +} + +void +clear_string_list(GList *sl) { + GList *l = sl; + + while (l) { + g_free(l->data); + l = g_list_remove_link(l, l); + } +} + /* Preferences file format: * - Configuration directives start at the beginning of the line, and * are terminated with a colon. @@ -181,29 +256,45 @@ print.file: /a/very/long/path/ * */ -#define MAX_VAR_LEN 32 -#define MAX_VAL_LEN 256 -void +#define MAX_VAR_LEN 32 +#define MAX_VAL_LEN 1024 +#define DEF_NUM_COLS 6 +e_prefs * read_prefs() { enum { START, IN_VAR, PRE_VAL, IN_VAL, IN_SKIP }; - FILE *pf; - gchar cur_var[MAX_VAR_LEN], cur_val[MAX_VAL_LEN]; - int got_c, state = START; - gint var_len = 0, val_len = 0, fline = 1, pline = 1; + FILE *pf; + gchar cur_var[MAX_VAR_LEN], cur_val[MAX_VAL_LEN], **cfdata; + int got_c, state = START, i; + gint var_len = 0, val_len = 0, fline = 1, pline = 1; + gboolean got_val = FALSE; + fmt_data *cfmt; + gchar *col_fmt[] = {"No.", "%m", "Time", "%t", + "Source", "%s", "Destination", "%d", + "Protocol", "%p", "Info", "%i"}; + /* Initialize preferences. With any luck, these values will be overwritten below. */ if (init_prefs) { - init_prefs = 0; - prefs.pr_format = PR_FMT_TEXT; - prefs.pr_dest = PR_DEST_CMD; - prefs.pr_file = g_strdup("ethereal.out"); - prefs.pr_cmd = g_strdup("lpr"); + init_prefs = 0; + prefs.pr_format = PR_FMT_TEXT; + prefs.pr_dest = PR_DEST_CMD; + prefs.pr_file = g_strdup("ethereal.out"); + prefs.pr_cmd = g_strdup("lpr"); + prefs.col_list = NULL; + for (i = 0; i < DEF_NUM_COLS; i++) { + cfmt = (fmt_data *) g_malloc(sizeof(fmt_data)); + cfmt->title = g_strdup(col_fmt[i * 2]); + cfmt->fmt = g_strdup(col_fmt[(i * 2) + 1]); + prefs.col_list = g_list_append(prefs.col_list, cfmt); + } + prefs.num_cols = DEF_NUM_COLS; } if (! pf_path) { - pf_path = (gchar *) g_malloc(strlen(getenv("HOME")) + strlen(PF_NAME) + 4); - sprintf(pf_path, "%s/%s", getenv("HOME"), PF_NAME); + pf_path = (gchar *) g_malloc(strlen(getenv("HOME")) + strlen(PF_DIR) + + strlen(PF_NAME) + 4); + sprintf(pf_path, "%s/%s/%s", getenv("HOME"), PF_DIR, PF_NAME); } if ((pf = fopen(pf_path, "r")) == NULL) { @@ -236,17 +327,22 @@ read_prefs() { switch (state) { case START: if (isalnum(got_c)) { - state = IN_VAR; if (var_len > 0) { - cur_var[var_len] = '\0'; - cur_val[val_len] = '\0'; - if (! set_pref(cur_var, cur_val)) - g_warning ("%s line %d: Bogus preference", pf_path, pline); + if (got_val) { + cur_var[var_len] = '\0'; + cur_val[val_len] = '\0'; + if (! set_pref(cur_var, cur_val)) + g_warning ("%s line %d: Bogus preference", pf_path, pline); + } else { + g_warning ("%s line %d: Incomplete preference", pf_path, pline); + } } + state = IN_VAR; + got_val = FALSE; cur_var[0] = got_c; - var_len = 1; + var_len = 1; pline = fline; - } else if (isspace(got_c) && var_len > 0) { + } else if (isspace(got_c) && var_len > 0 && got_val) { state = PRE_VAL; } else if (got_c == '#') { state = IN_SKIP; @@ -259,8 +355,9 @@ read_prefs() { cur_var[var_len] = got_c; var_len++; } else { - state = PRE_VAL; + state = PRE_VAL; val_len = 0; + got_val = TRUE; } break; case PRE_VAL: @@ -271,30 +368,47 @@ read_prefs() { } break; case IN_VAL: - cur_val[val_len] = got_c; - val_len++; + if (got_c != '#') { + cur_val[val_len] = got_c; + val_len++; + } else { + while (isspace(cur_val[val_len]) && val_len > 0) + val_len--; + state = IN_SKIP; + } break; } } if (var_len > 0) { - cur_var[var_len] = '\0'; - cur_val[val_len] = '\0'; - if (! set_pref(cur_var, cur_val)) - g_warning ("%s line %d: Bogus preference", pf_path, pline); + if (got_val) { + cur_var[var_len] = '\0'; + cur_val[val_len] = '\0'; + if (! set_pref(cur_var, cur_val)) + g_warning ("%s line %d: Bogus preference", pf_path, pline); + } else { + g_warning ("%s line %d: Incomplete preference", pf_path, pline); + } } fclose(pf); + + return &prefs; } #define PRS_PRINT_FMT "print.format" #define PRS_PRINT_DEST "print.destination" #define PRS_PRINT_FILE "print.file" #define PRS_PRINT_CMD "print.command" +#define PRS_COL_FMT "column.format" static gchar *pr_formats[] = { "text", "postscript" }; static gchar *pr_dests[] = { "command", "file" }; int set_pref(gchar *pref, gchar *value) { + gchar *col_ptr; + GList *col_l; + gint i, llen; + fmt_data *cfmt; if (strcmp(pref, PRS_PRINT_FMT) == 0) { if (strcmp(value, pr_formats[PR_FMT_TEXT]) == 0) { @@ -318,6 +432,29 @@ set_pref(gchar *pref, gchar *value) { } else if (strcmp(pref, PRS_PRINT_CMD) == 0) { if (prefs.pr_cmd) g_free(prefs.pr_cmd); prefs.pr_cmd = g_strdup(value); + } else if (strcmp(pref, PRS_COL_FMT) == 0) { + if ((col_l = get_string_list(value)) && (g_list_length(col_l) % 2) == 0) { + while (prefs.col_list) { + cfmt = prefs.col_list->data; + g_free(cfmt->title); + g_free(cfmt->fmt); + g_free(cfmt); + prefs.col_list = g_list_remove_link(prefs.col_list, prefs.col_list); + } + llen = g_list_length(col_l); + prefs.num_cols = llen / 2; + col_l = g_list_first(col_l); + while(col_l) { + cfmt = (fmt_data *) g_malloc(sizeof(fmt_data)); + cfmt->title = g_strdup(col_l->data); + col_l = col_l->next; + cfmt->fmt = g_strdup(col_l->data); + col_l = col_l->next; + prefs.col_list = g_list_append(prefs.col_list, cfmt); + } + /* To do: else print some sort of error? */ + } + clear_string_list(col_l); } else { return 0; } @@ -327,15 +464,25 @@ set_pref(gchar *pref, gchar *value) { void write_prefs() { - FILE *pf; + FILE *pf; + struct stat s_buf; - /* To do: Split output lines longer than MAX_VAL_LEN */ + /* To do: + * - Split output lines longer than MAX_VAL_LEN + * - Create a function for the preference directory check/creation + * so that duplication can be avoided with filter.c + */ if (! pf_path) { - pf_path = (gchar *) g_malloc(strlen(getenv("HOME")) + strlen(PF_NAME) + 4); - sprintf(pf_path, "%s/%s", getenv("HOME"), PF_NAME); + pf_path = (gchar *) g_malloc(strlen(getenv("HOME")) + strlen(PF_DIR) + + strlen(PF_NAME) + 4); } - + + sprintf(pf_path, "%s/%s", getenv("HOME"), PF_DIR); + if (stat(pf_path, &s_buf) != 0) + mkdir(pf_path, 0755); + + sprintf(pf_path, "%s/%s/%s", getenv("HOME"), PF_DIR, PF_NAME); if ((pf = fopen(pf_path, "w")) == NULL) { simple_dialog(ESD_TYPE_WARN, NULL, "Can't open preferences file\n\"%s\".", pf_path); @@ -362,7 +509,11 @@ write_prefs() { fprintf (pf, "# Output gets piped to this command when the destination " "is set to \"command\"\n" - "%s: %s\n", PRS_PRINT_CMD, prefs.pr_cmd); + "%s: %s\n\n", PRS_PRINT_CMD, prefs.pr_cmd); + + fprintf (pf, "# Packet list column format. Each pair of strings consists " + "of a column title \n# and its format.\n" + "%s: %s\n\n", PRS_COL_FMT, col_format_to_pref_str()); fclose(pf); } @@ -1,7 +1,7 @@ /* prefs.h * Definitions for preference handling routines * - * $Id: prefs.h,v 1.4 1998/10/28 21:38:10 gerald Exp $ + * $Id: prefs.h,v 1.5 1998/11/17 04:29:11 gerald Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -33,22 +33,22 @@ #define PR_DEST_FILE 1 typedef struct _e_prefs { - gint pr_format; - gint pr_dest; - gchar *pr_file; - gchar *pr_cmd; + gint pr_format; + gint pr_dest; + gchar *pr_file; + gchar *pr_cmd; + GList *col_list; + gint num_cols; } e_prefs; #define E_PR_PG_NONE -1 #define E_PR_PG_PRINTING 0 #define E_PR_PG_FILTER 1 - -#define E_PRINT_PAGE_KEY "printer_options_page" -#define E_FILTER_PAGE_KEY "filter_options_page" +#define E_PR_PG_COLUMN 2 #define E_FILT_TE_PTR_KEY "filter_te_ptr" -void prefs_cb(GtkWidget *, gpointer); -void read_prefs(); +void prefs_cb(GtkWidget *, gpointer); +e_prefs* read_prefs(); #endif /* prefs.h */ diff --git a/wiretap/configure b/wiretap/configure index 3c58fd137b..11672dd84b 100755 --- a/wiretap/configure +++ b/wiretap/configure @@ -1085,13 +1085,10 @@ int main () { int major, minor, micro; - char *tmp_version; system ("touch conf.gtktest"); - /* HP/UX 9 (%@#!) writes to sscanf strings */ - tmp_version = g_strdup("$min_gtk_version"); - if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, µ) != 3) { + if (sscanf("$min_gtk_version", "%d.%d.%d", &major, &minor, µ) != 3) { printf("%s, bad version string\n", "$min_gtk_version"); exit(1); } @@ -1141,7 +1138,7 @@ main () } EOF -if { (eval echo configure:1145: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null +if { (eval echo configure:1142: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null then : else @@ -1175,7 +1172,7 @@ fi CFLAGS="$CFLAGS $GTK_CFLAGS" LIBS="$LIBS $GTK_LIBS" cat > conftest.$ac_ext <<EOF -#line 1179 "configure" +#line 1176 "configure" #include "confdefs.h" #include <gtk/gtk.h> @@ -1185,7 +1182,7 @@ int main() { return ((gtk_major_version) || (gtk_minor_version) || (gtk_micro_version)); ; return 0; } EOF -if { (eval echo configure:1189: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:1186: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then rm -rf conftest* echo "*** The test program compiled, but did not run. This usually means" echo "*** that the run-time linker is not finding GTK or finding the wrong" @@ -1225,7 +1222,7 @@ rm -f conftest* echo $ac_n "checking how to run the C preprocessor""... $ac_c" 1>&6 -echo "configure:1229: checking how to run the C preprocessor" >&5 +echo "configure:1226: checking how to run the C preprocessor" >&5 # On Suns, sometimes $CPP names a directory. if test -n "$CPP" && test -d "$CPP"; then CPP= @@ -1240,13 +1237,13 @@ else # On the NeXT, cc -E runs the code through the compiler's parser, # not just through cpp. cat > conftest.$ac_ext <<EOF -#line 1244 "configure" +#line 1241 "configure" #include "confdefs.h" #include <assert.h> Syntax Error EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1250: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1247: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out` if test -z "$ac_err"; then : @@ -1257,13 +1254,13 @@ else rm -rf conftest* CPP="${CC-cc} -E -traditional-cpp" cat > conftest.$ac_ext <<EOF -#line 1261 "configure" +#line 1258 "configure" #include "confdefs.h" #include <assert.h> Syntax Error EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1267: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1264: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out` if test -z "$ac_err"; then : @@ -1286,12 +1283,12 @@ fi echo "$ac_t""$CPP" 1>&6 echo $ac_n "checking for ANSI C header files""... $ac_c" 1>&6 -echo "configure:1290: checking for ANSI C header files" >&5 +echo "configure:1287: checking for ANSI C header files" >&5 if eval "test \"`echo '$''{'ac_cv_header_stdc'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1295 "configure" +#line 1292 "configure" #include "confdefs.h" #include <stdlib.h> #include <stdarg.h> @@ -1299,7 +1296,7 @@ else #include <float.h> EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1303: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1300: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out` if test -z "$ac_err"; then rm -rf conftest* @@ -1316,7 +1313,7 @@ rm -f conftest* if test $ac_cv_header_stdc = yes; then # SunOS 4.x string.h does not declare mem*, contrary to ANSI. cat > conftest.$ac_ext <<EOF -#line 1320 "configure" +#line 1317 "configure" #include "confdefs.h" #include <string.h> EOF @@ -1334,7 +1331,7 @@ fi if test $ac_cv_header_stdc = yes; then # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. cat > conftest.$ac_ext <<EOF -#line 1338 "configure" +#line 1335 "configure" #include "confdefs.h" #include <stdlib.h> EOF @@ -1355,7 +1352,7 @@ if test "$cross_compiling" = yes; then : else cat > conftest.$ac_ext <<EOF -#line 1359 "configure" +#line 1356 "configure" #include "confdefs.h" #include <ctype.h> #define ISLOWER(c) ('a' <= (c) && (c) <= 'z') @@ -1366,7 +1363,7 @@ if (XOR (islower (i), ISLOWER (i)) || toupper (i) != TOUPPER (i)) exit(2); exit (0); } EOF -if { (eval echo configure:1370: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null +if { (eval echo configure:1367: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null then : else @@ -1393,17 +1390,17 @@ for ac_hdr in unistd.h do ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6 -echo "configure:1397: checking for $ac_hdr" >&5 +echo "configure:1394: checking for $ac_hdr" >&5 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1402 "configure" +#line 1399 "configure" #include "confdefs.h" #include <$ac_hdr> EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1407: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1404: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out` if test -z "$ac_err"; then rm -rf conftest* |