2 * Routines for handling column preferences
4 * $Id: column.c,v 1.35 2002/01/21 07:36:31 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.
29 #ifdef HAVE_SYS_TYPES_H
30 #include <sys/types.h>
42 #ifdef HAVE_SYS_STAT_H
46 #include <epan/timestamp.h>
49 #include <epan/packet.h>
51 /* Given a format number (as defined in packet.h), returns its equivalent
54 col_format_to_string(gint fmt) {
55 gchar *slist[] = { "%m", "%t", "%Rt", "%At", "%Yt", "%Tt", "%s", "%rs",
56 "%us","%hs", "%rhs", "%uhs", "%ns", "%rns", "%uns", "%d",
57 "%rd", "%ud", "%hd", "%rhd", "%uhd", "%nd", "%rnd",
58 "%und", "%S", "%rS", "%uS", "%D", "%rD", "%uD", "%p",
61 if (fmt < 0 || fmt > NUM_COL_FMTS)
67 /* Given a format number (as defined in packet.h), returns its
70 col_format_desc(gint fmt) {
71 gchar *dlist[] = { "Number", "Time (command line specified)",
72 "Relative time", "Absolute time",
73 "Absolute date and time", "Delta time",
74 "Source address", "Src addr (resolved)",
75 "Src addr (unresolved)", "Hardware src addr",
76 "Hw src addr (resolved)", "Hw src addr (unresolved)",
77 "Network src addr", "Net src addr (resolved)",
78 "Net src addr (unresolved)", "Destination address",
79 "Dest addr (resolved)", "Dest addr (unresolved)",
80 "Hardware dest addr", "Hw dest addr (resolved)",
81 "Hw dest addr (unresolved)", "Network dest addr",
82 "Net dest addr (resolved)", "Net dest addr (unresolved)",
83 "Source port", "Src port (resolved)",
84 "Src port (unresolved)", "Destination port",
85 "Dest port (resolved)", "Dest port (unresolved)",
86 "Protocol", "Information", "Packet length (bytes)" };
88 if (fmt < 0 || fmt > NUM_COL_FMTS)
94 /* Marks each array element true if it can be substituted for the given
97 get_column_format_matches(gboolean *fmt_list, gint format) {
99 /* Get the obvious: the format itself */
100 if ((format >= 0) && (format < NUM_COL_FMTS))
101 fmt_list[format] = TRUE;
103 /* Get any formats lower down on the chain */
106 fmt_list[COL_RES_DL_SRC] = TRUE;
107 fmt_list[COL_RES_NET_SRC] = TRUE;
110 fmt_list[COL_RES_DL_SRC] = TRUE;
111 fmt_list[COL_RES_NET_SRC] = TRUE;
114 fmt_list[COL_UNRES_DL_SRC] = TRUE;
115 fmt_list[COL_UNRES_NET_SRC] = TRUE;
118 fmt_list[COL_RES_DL_DST] = TRUE;
119 fmt_list[COL_RES_NET_DST] = TRUE;
122 fmt_list[COL_RES_DL_DST] = TRUE;
123 fmt_list[COL_RES_NET_DST] = TRUE;
126 fmt_list[COL_UNRES_DL_DST] = TRUE;
127 fmt_list[COL_UNRES_NET_DST] = TRUE;
130 fmt_list[COL_RES_DL_SRC] = TRUE;
133 fmt_list[COL_RES_DL_DST] = TRUE;
135 case COL_DEF_NET_SRC:
136 fmt_list[COL_RES_NET_SRC] = TRUE;
138 case COL_DEF_NET_DST:
139 fmt_list[COL_RES_NET_DST] = TRUE;
141 case COL_DEF_SRC_PORT:
142 fmt_list[COL_RES_SRC_PORT] = TRUE;
144 case COL_DEF_DST_PORT:
145 fmt_list[COL_RES_DST_PORT] = TRUE;
152 /* Returns a string representing the longest possible value for a
153 particular column type.
155 Except for the COL...SRC and COL...DST columns, these are used
156 only when a capture is being displayed while it's taking place;
157 they are arguably somewhat fragile, as changes to the code that
158 generates them don't cause these widths to change, but that's
159 probably not too big a problem, given that the sizes are
160 recomputed based on the actual data in the columns when the capture
161 is done, and given that the width for COL...SRC and COL...DST columns
162 is somewhat arbitrary in any case. We should probably clean
163 that up eventually, though. */
165 get_column_longest_string(gint format)
172 if (timestamp_type == ABSOLUTE)
173 return "00:00:00.000000";
174 else if (timestamp_type == ABSOLUTE_WITH_DATE)
175 return "0000-00-00 00:00:00.000000";
177 return "0000.000000";
180 return "00:00:00.000000";
182 case COL_ABS_DATE_TIME:
183 return "0000-00-00 00:00:00.000000";
187 return "0000.000000";
194 case COL_UNRES_DL_SRC:
195 case COL_DEF_NET_SRC:
196 case COL_RES_NET_SRC:
197 case COL_UNRES_NET_SRC:
203 case COL_UNRES_DL_DST:
204 case COL_DEF_NET_DST:
205 case COL_RES_NET_DST:
206 case COL_UNRES_NET_DST:
207 return "00000000.000000000000"; /* IPX-style */
209 case COL_DEF_SRC_PORT:
210 case COL_RES_SRC_PORT:
211 case COL_UNRES_SRC_PORT:
212 case COL_DEF_DST_PORT:
213 case COL_RES_DST_PORT:
214 case COL_UNRES_DST_PORT:
218 return "NetBIOS"; /* not the longest, but the longest is too long */
220 case COL_PACKET_LENGTH:
223 default: /* COL_INFO */
224 return "Source port: kerberos-master Destination port: kerberos-master";
229 /* Returns the longest possible width, in characters, for a particular
232 get_column_char_width(gint format)
234 return strlen(get_column_longest_string(format));
238 get_column_resize_type(gint format) {
243 case COL_ABS_DATE_TIME:
246 case COL_DEF_SRC_PORT:
247 case COL_RES_SRC_PORT:
248 case COL_UNRES_SRC_PORT:
249 case COL_DEF_DST_PORT:
250 case COL_RES_DST_PORT:
251 case COL_UNRES_DST_PORT:
253 case COL_PACKET_LENGTH:
254 /* We don't want these to resize during a live capture, as that
255 gets in the way of trying to look at the data while it's being
257 return (RESIZE_AUTO);
264 case COL_UNRES_DL_SRC:
265 case COL_DEF_NET_SRC:
266 case COL_RES_NET_SRC:
267 case COL_UNRES_NET_SRC:
273 case COL_UNRES_DL_DST:
274 case COL_DEF_NET_DST:
275 case COL_RES_NET_DST:
276 case COL_UNRES_NET_DST:
277 /* We don't want these to resize dynamically; if they get resolved
278 to names, those names could be very long, and auto-resizing
279 columns showing those names may leave too little room for
280 other columns such as the "Info" column. */
281 return (RESIZE_MANUAL);
283 default: /* COL_INFO */
284 /* We want this to resize dynamically, even during a live capture,
285 because otherewise you won't be able to see all that's in
287 return (RESIZE_LIVE);
295 #define DATE_TIME_ABS 3
307 get_column_format(gint col) {
308 GList *clp = g_list_nth(prefs.col_list, col);
311 cfmt = (fmt_data *) clp->data;
313 return(get_column_format_from_str(cfmt->fmt));
317 get_column_format_from_str(gchar *str) {
319 gint res_off = RES_DEF, addr_off = ADDR_DEF, time_off = TIME_DEF;
321 /* To do: Make this parse %-formatted strings "for real" */
322 while (*cptr != '\0') {
324 case 't': /* To do: fix for absolute and delta */
325 return COL_CLS_TIME + time_off;
331 return COL_DEF_SRC + res_off + addr_off;
334 return COL_DEF_DST + res_off + addr_off;
337 return COL_DEF_SRC_PORT + res_off;
340 return COL_DEF_DST_PORT + res_off;
367 time_off = DATE_TIME_ABS;
373 return COL_PACKET_LENGTH;
378 return -1; /* illegal */
382 get_column_title(gint col) {
383 GList *clp = g_list_nth(prefs.col_list, col);
386 cfmt = (fmt_data *) clp->data;