2 * Routines for handling column preferences
4 * $Id: column.c,v 1.46 2004/01/31 04:10:04 guy Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@ethereal.com>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
38 #ifdef HAVE_SYS_STAT_H
42 #include <epan/timestamp.h>
45 #include <epan/packet.h>
47 /* Given a format number (as defined in packet.h), returns its equivalent
50 col_format_to_string(gint fmt) {
51 gchar *slist[] = { "%m", "%t", "%Rt", "%At", "%Yt", "%Tt", "%s", "%rs",
52 "%us","%hs", "%rhs", "%uhs", "%ns", "%rns", "%uns", "%d",
53 "%rd", "%ud", "%hd", "%rhd", "%uhd", "%nd", "%rnd",
54 "%und", "%S", "%rS", "%uS", "%D", "%rD", "%uD", "%p",
55 "%i", "%L", "%B", "%XO", "%XR", "%I", "%c", "%Xs",
58 if (fmt < 0 || fmt > NUM_COL_FMTS)
64 /* Given a format number (as defined in packet.h), returns its
66 static gchar *dlist[NUM_COL_FMTS] = {
68 "Time (command line specified)",
71 "Absolute date and time",
74 "Src addr (resolved)",
75 "Src addr (unresolved)",
77 "Hw src addr (resolved)",
78 "Hw src addr (unresolved)",
80 "Net src addr (resolved)",
81 "Net src addr (unresolved)",
82 "Destination address",
83 "Dest addr (resolved)",
84 "Dest addr (unresolved)",
86 "Hw dest addr (resolved)",
87 "Hw dest addr (unresolved)",
89 "Net dest addr (resolved)",
90 "Net dest addr (unresolved)",
92 "Src port (resolved)",
93 "Src port (unresolved)",
95 "Dest port (resolved)",
96 "Dest port (unresolved)",
99 "Packet length (bytes)" ,
103 "FW-1 monitor if/direction",
111 col_format_desc(gint fmt) {
112 g_assert((fmt >= 0) && (fmt < NUM_COL_FMTS));
116 /* Marks each array element true if it can be substituted for the given
119 get_column_format_matches(gboolean *fmt_list, gint format) {
121 /* Get the obvious: the format itself */
122 if ((format >= 0) && (format < NUM_COL_FMTS))
123 fmt_list[format] = TRUE;
125 /* Get any formats lower down on the chain */
128 fmt_list[COL_RES_DL_SRC] = TRUE;
129 fmt_list[COL_RES_NET_SRC] = TRUE;
132 fmt_list[COL_RES_DL_SRC] = TRUE;
133 fmt_list[COL_RES_NET_SRC] = TRUE;
136 fmt_list[COL_UNRES_DL_SRC] = TRUE;
137 fmt_list[COL_UNRES_NET_SRC] = TRUE;
140 fmt_list[COL_RES_DL_DST] = TRUE;
141 fmt_list[COL_RES_NET_DST] = TRUE;
144 fmt_list[COL_RES_DL_DST] = TRUE;
145 fmt_list[COL_RES_NET_DST] = TRUE;
148 fmt_list[COL_UNRES_DL_DST] = TRUE;
149 fmt_list[COL_UNRES_NET_DST] = TRUE;
152 fmt_list[COL_RES_DL_SRC] = TRUE;
155 fmt_list[COL_RES_DL_DST] = TRUE;
157 case COL_DEF_NET_SRC:
158 fmt_list[COL_RES_NET_SRC] = TRUE;
160 case COL_DEF_NET_DST:
161 fmt_list[COL_RES_NET_DST] = TRUE;
163 case COL_DEF_SRC_PORT:
164 fmt_list[COL_RES_SRC_PORT] = TRUE;
166 case COL_DEF_DST_PORT:
167 fmt_list[COL_RES_DST_PORT] = TRUE;
170 fmt_list[COL_OXID] = TRUE;
173 fmt_list[COL_RXID] = TRUE;
176 fmt_list[COL_IF_DIR] = TRUE;
179 fmt_list[COL_CIRCUIT_ID] = TRUE;
182 fmt_list[COL_SRCIDX] = TRUE;
185 fmt_list[COL_DSTIDX] = TRUE;
188 fmt_list[COL_VSAN] = TRUE;
195 /* Returns a string representing the longest possible value for a
196 particular column type.
198 Except for the COL...SRC and COL...DST columns, these are used
199 only when a capture is being displayed while it's taking place;
200 they are arguably somewhat fragile, as changes to the code that
201 generates them don't cause these widths to change, but that's
202 probably not too big a problem, given that the sizes are
203 recomputed based on the actual data in the columns when the capture
204 is done, and given that the width for COL...SRC and COL...DST columns
205 is somewhat arbitrary in any case. We should probably clean
206 that up eventually, though. */
208 get_column_longest_string(gint format)
215 if (timestamp_type == TS_ABSOLUTE)
216 return "00:00:00.000000";
217 else if (timestamp_type == TS_ABSOLUTE_WITH_DATE)
218 return "0000-00-00 00:00:00.000000";
220 return "0000.000000";
223 return "00:00:00.000000";
225 case COL_ABS_DATE_TIME:
226 return "0000-00-00 00:00:00.000000";
230 return "0000.000000";
237 case COL_UNRES_DL_SRC:
238 case COL_DEF_NET_SRC:
239 case COL_RES_NET_SRC:
240 case COL_UNRES_NET_SRC:
246 case COL_UNRES_DL_DST:
247 case COL_DEF_NET_DST:
248 case COL_RES_NET_DST:
249 case COL_UNRES_NET_DST:
250 return "00000000.000000000000"; /* IPX-style */
252 case COL_DEF_SRC_PORT:
253 case COL_RES_SRC_PORT:
254 case COL_UNRES_SRC_PORT:
255 case COL_DEF_DST_PORT:
256 case COL_RES_DST_PORT:
257 case COL_UNRES_DST_PORT:
261 return "Protocol"; /* not the longest, but the longest is too long */
263 case COL_PACKET_LENGTH:
266 case COL_CUMULATIVE_BYTES:
274 return "i 00000000 I";
286 default: /* COL_INFO */
287 return "Source port: kerberos-master Destination port: kerberos-master";
292 /* Returns the longest possible width, in characters, for a particular
295 get_column_char_width(gint format)
297 return strlen(get_column_longest_string(format));
303 #define DATE_TIME_ABS 3
315 get_column_format(gint col) {
316 GList *clp = g_list_nth(prefs.col_list, col);
319 cfmt = (fmt_data *) clp->data;
321 return(get_column_format_from_str(cfmt->fmt));
325 get_column_format_from_str(gchar *str) {
327 gint res_off = RES_DEF, addr_off = ADDR_DEF, time_off = TIME_DEF;
330 /* To do: Make this parse %-formatted strings "for real" */
331 while (*cptr != '\0') {
333 case 't': /* To do: fix for absolute and delta */
334 return COL_CLS_TIME + time_off;
340 if (prev_code == COL_OXID) {
344 return COL_DEF_SRC + res_off + addr_off;
348 if (prev_code == COL_OXID) {
352 return COL_DEF_DST + res_off + addr_off;
356 return COL_DEF_SRC_PORT + res_off;
359 return COL_DEF_DST_PORT + res_off;
380 if (prev_code == COL_OXID) {
391 time_off = DATE_TIME_ABS;
397 return COL_PACKET_LENGTH;
400 return COL_CUMULATIVE_BYTES;
403 prev_code = COL_OXID;
412 return COL_CIRCUIT_ID;
420 return -1; /* illegal */
424 get_column_title(gint col) {
425 GList *clp = g_list_nth(prefs.col_list, col);
428 cfmt = (fmt_data *) clp->data;