2 * Routines for handling column preferences
4 * $Id: column.c,v 1.43 2003/09/03 10:49:01 sahlberg 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)" ,
100 "Culmulative 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 == ABSOLUTE)
216 return "00:00:00.000000";
217 else if (timestamp_type == 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 "NetBIOS"; /* not the longest, but the longest is too long */
263 case COL_PACKET_LENGTH:
266 case COL_CULMULATIVE_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));
301 get_column_resize_type(gint format) {
306 case COL_ABS_DATE_TIME:
309 case COL_DEF_SRC_PORT:
310 case COL_RES_SRC_PORT:
311 case COL_UNRES_SRC_PORT:
312 case COL_DEF_DST_PORT:
313 case COL_RES_DST_PORT:
314 case COL_UNRES_DST_PORT:
316 case COL_PACKET_LENGTH:
317 case COL_CULMULATIVE_BYTES:
320 /* We don't want these to resize during a live capture, as that
321 gets in the way of trying to look at the data while it's being
323 return (RESIZE_AUTO);
330 case COL_UNRES_DL_SRC:
331 case COL_DEF_NET_SRC:
332 case COL_RES_NET_SRC:
333 case COL_UNRES_NET_SRC:
339 case COL_UNRES_DL_DST:
340 case COL_DEF_NET_DST:
341 case COL_RES_NET_DST:
342 case COL_UNRES_NET_DST:
348 /* We don't want these to resize dynamically; if they get resolved
349 to names, those names could be very long, and auto-resizing
350 columns showing those names may leave too little room for
351 other columns such as the "Info" column. */
352 return (RESIZE_MANUAL);
354 default: /* COL_INFO */
355 /* We want this to resize dynamically, even during a live capture,
356 because otherewise you won't be able to see all that's in
358 return (RESIZE_LIVE);
366 #define DATE_TIME_ABS 3
378 get_column_format(gint col) {
379 GList *clp = g_list_nth(prefs.col_list, col);
382 cfmt = (fmt_data *) clp->data;
384 return(get_column_format_from_str(cfmt->fmt));
388 get_column_format_from_str(gchar *str) {
390 gint res_off = RES_DEF, addr_off = ADDR_DEF, time_off = TIME_DEF;
393 /* To do: Make this parse %-formatted strings "for real" */
394 while (*cptr != '\0') {
396 case 't': /* To do: fix for absolute and delta */
397 return COL_CLS_TIME + time_off;
403 if (prev_code == COL_OXID) {
407 return COL_DEF_SRC + res_off + addr_off;
411 if (prev_code == COL_OXID) {
415 return COL_DEF_DST + res_off + addr_off;
419 return COL_DEF_SRC_PORT + res_off;
422 return COL_DEF_DST_PORT + res_off;
443 if (prev_code == COL_OXID) {
454 time_off = DATE_TIME_ABS;
460 return COL_PACKET_LENGTH;
463 return COL_CULMULATIVE_BYTES;
466 prev_code = COL_OXID;
475 return COL_CIRCUIT_ID;
483 return -1; /* illegal */
487 get_column_title(gint col) {
488 GList *clp = g_list_nth(prefs.col_list, col);
491 cfmt = (fmt_data *) clp->data;