2 * Routines for handling column preferences
4 * $Id: column.c,v 1.42 2003/01/27 20:45:42 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", "%XO", "%XR", "%I", "%c", "%Xs", "%Xd", "%V" };
57 if (fmt < 0 || fmt > NUM_COL_FMTS)
63 /* Given a format number (as defined in packet.h), returns its
65 static gchar *dlist[NUM_COL_FMTS] = {
67 "Time (command line specified)",
70 "Absolute date and time",
73 "Src addr (resolved)",
74 "Src addr (unresolved)",
76 "Hw src addr (resolved)",
77 "Hw src addr (unresolved)",
79 "Net src addr (resolved)",
80 "Net src addr (unresolved)",
81 "Destination address",
82 "Dest addr (resolved)",
83 "Dest addr (unresolved)",
85 "Hw dest addr (resolved)",
86 "Hw dest addr (unresolved)",
88 "Net dest addr (resolved)",
89 "Net dest addr (unresolved)",
91 "Src port (resolved)",
92 "Src port (unresolved)",
94 "Dest port (resolved)",
95 "Dest port (unresolved)",
98 "Packet length (bytes)" ,
101 "FW-1 monitor if/direction",
109 col_format_desc(gint fmt) {
110 g_assert((fmt >= 0) && (fmt < NUM_COL_FMTS));
114 /* Marks each array element true if it can be substituted for the given
117 get_column_format_matches(gboolean *fmt_list, gint format) {
119 /* Get the obvious: the format itself */
120 if ((format >= 0) && (format < NUM_COL_FMTS))
121 fmt_list[format] = TRUE;
123 /* Get any formats lower down on the chain */
126 fmt_list[COL_RES_DL_SRC] = TRUE;
127 fmt_list[COL_RES_NET_SRC] = TRUE;
130 fmt_list[COL_RES_DL_SRC] = TRUE;
131 fmt_list[COL_RES_NET_SRC] = TRUE;
134 fmt_list[COL_UNRES_DL_SRC] = TRUE;
135 fmt_list[COL_UNRES_NET_SRC] = TRUE;
138 fmt_list[COL_RES_DL_DST] = TRUE;
139 fmt_list[COL_RES_NET_DST] = TRUE;
142 fmt_list[COL_RES_DL_DST] = TRUE;
143 fmt_list[COL_RES_NET_DST] = TRUE;
146 fmt_list[COL_UNRES_DL_DST] = TRUE;
147 fmt_list[COL_UNRES_NET_DST] = TRUE;
150 fmt_list[COL_RES_DL_SRC] = TRUE;
153 fmt_list[COL_RES_DL_DST] = TRUE;
155 case COL_DEF_NET_SRC:
156 fmt_list[COL_RES_NET_SRC] = TRUE;
158 case COL_DEF_NET_DST:
159 fmt_list[COL_RES_NET_DST] = TRUE;
161 case COL_DEF_SRC_PORT:
162 fmt_list[COL_RES_SRC_PORT] = TRUE;
164 case COL_DEF_DST_PORT:
165 fmt_list[COL_RES_DST_PORT] = TRUE;
168 fmt_list[COL_OXID] = TRUE;
171 fmt_list[COL_RXID] = TRUE;
174 fmt_list[COL_IF_DIR] = TRUE;
177 fmt_list[COL_CIRCUIT_ID] = TRUE;
180 fmt_list[COL_SRCIDX] = TRUE;
183 fmt_list[COL_DSTIDX] = TRUE;
186 fmt_list[COL_VSAN] = TRUE;
193 /* Returns a string representing the longest possible value for a
194 particular column type.
196 Except for the COL...SRC and COL...DST columns, these are used
197 only when a capture is being displayed while it's taking place;
198 they are arguably somewhat fragile, as changes to the code that
199 generates them don't cause these widths to change, but that's
200 probably not too big a problem, given that the sizes are
201 recomputed based on the actual data in the columns when the capture
202 is done, and given that the width for COL...SRC and COL...DST columns
203 is somewhat arbitrary in any case. We should probably clean
204 that up eventually, though. */
206 get_column_longest_string(gint format)
213 if (timestamp_type == ABSOLUTE)
214 return "00:00:00.000000";
215 else if (timestamp_type == ABSOLUTE_WITH_DATE)
216 return "0000-00-00 00:00:00.000000";
218 return "0000.000000";
221 return "00:00:00.000000";
223 case COL_ABS_DATE_TIME:
224 return "0000-00-00 00:00:00.000000";
228 return "0000.000000";
235 case COL_UNRES_DL_SRC:
236 case COL_DEF_NET_SRC:
237 case COL_RES_NET_SRC:
238 case COL_UNRES_NET_SRC:
244 case COL_UNRES_DL_DST:
245 case COL_DEF_NET_DST:
246 case COL_RES_NET_DST:
247 case COL_UNRES_NET_DST:
248 return "00000000.000000000000"; /* IPX-style */
250 case COL_DEF_SRC_PORT:
251 case COL_RES_SRC_PORT:
252 case COL_UNRES_SRC_PORT:
253 case COL_DEF_DST_PORT:
254 case COL_RES_DST_PORT:
255 case COL_UNRES_DST_PORT:
259 return "NetBIOS"; /* not the longest, but the longest is too long */
261 case COL_PACKET_LENGTH:
269 return "i 00000000 I";
281 default: /* COL_INFO */
282 return "Source port: kerberos-master Destination port: kerberos-master";
287 /* Returns the longest possible width, in characters, for a particular
290 get_column_char_width(gint format)
292 return strlen(get_column_longest_string(format));
296 get_column_resize_type(gint format) {
301 case COL_ABS_DATE_TIME:
304 case COL_DEF_SRC_PORT:
305 case COL_RES_SRC_PORT:
306 case COL_UNRES_SRC_PORT:
307 case COL_DEF_DST_PORT:
308 case COL_RES_DST_PORT:
309 case COL_UNRES_DST_PORT:
311 case COL_PACKET_LENGTH:
314 /* We don't want these to resize during a live capture, as that
315 gets in the way of trying to look at the data while it's being
317 return (RESIZE_AUTO);
324 case COL_UNRES_DL_SRC:
325 case COL_DEF_NET_SRC:
326 case COL_RES_NET_SRC:
327 case COL_UNRES_NET_SRC:
333 case COL_UNRES_DL_DST:
334 case COL_DEF_NET_DST:
335 case COL_RES_NET_DST:
336 case COL_UNRES_NET_DST:
342 /* We don't want these to resize dynamically; if they get resolved
343 to names, those names could be very long, and auto-resizing
344 columns showing those names may leave too little room for
345 other columns such as the "Info" column. */
346 return (RESIZE_MANUAL);
348 default: /* COL_INFO */
349 /* We want this to resize dynamically, even during a live capture,
350 because otherewise you won't be able to see all that's in
352 return (RESIZE_LIVE);
360 #define DATE_TIME_ABS 3
372 get_column_format(gint col) {
373 GList *clp = g_list_nth(prefs.col_list, col);
376 cfmt = (fmt_data *) clp->data;
378 return(get_column_format_from_str(cfmt->fmt));
382 get_column_format_from_str(gchar *str) {
384 gint res_off = RES_DEF, addr_off = ADDR_DEF, time_off = TIME_DEF;
387 /* To do: Make this parse %-formatted strings "for real" */
388 while (*cptr != '\0') {
390 case 't': /* To do: fix for absolute and delta */
391 return COL_CLS_TIME + time_off;
397 if (prev_code == COL_OXID) {
401 return COL_DEF_SRC + res_off + addr_off;
405 if (prev_code == COL_OXID) {
409 return COL_DEF_DST + res_off + addr_off;
413 return COL_DEF_SRC_PORT + res_off;
416 return COL_DEF_DST_PORT + res_off;
437 if (prev_code == COL_OXID) {
448 time_off = DATE_TIME_ABS;
454 return COL_PACKET_LENGTH;
457 prev_code = COL_OXID;
466 return COL_CIRCUIT_ID;
474 return -1; /* illegal */
478 get_column_title(gint col) {
479 GList *clp = g_list_nth(prefs.col_list, col);
482 cfmt = (fmt_data *) clp->data;