2 * Routines for handling column preferences
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
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 #include <epan/timestamp.h>
39 #include <epan/prefs.h>
40 #include <epan/column.h>
41 #include <epan/packet.h>
43 /* Given a format number (as defined in packet.h), returns its equivalent
46 col_format_to_string(gint fmt) {
47 const gchar *slist[] = {
99 if (fmt < 0 || fmt >= NUM_COL_FMTS)
105 /* Given a format number (as defined in packet.h), returns its
107 static const gchar *dlist[NUM_COL_FMTS] = {
108 "Number", /* COL_NUMBER */
109 "Time (format as specified)", /* COL_CLS_TIME */
110 "Relative time", /* COL_REL_TIME */
111 "Absolute time", /* COL_ABS_TIME */
112 "Absolute date and time", /* COL_ABS_DATE_TIME */
113 "Delta time", /* COL_DELTA_TIME */
114 "Source address", /* COL_DEF_SRC */
115 "Src addr (resolved)", /* COL_RES_SRC */
116 "Src addr (unresolved)", /* COL_UNRES_SRC */
117 "Hardware src addr", /* COL_DEF_DL_SRC */
118 "Hw src addr (resolved)", /* COL_RES_DL_SRC*/
119 "Hw src addr (unresolved)", /* COL_UNRES_DL_SRC */
120 "Network src addr", /* COL_DEF_NET_SRC */
121 "Net src addr (resolved)", /* COL_RES_NET_SRC */
122 "Net src addr (unresolved)", /* COL_UNRES_NET_SRC */
123 "Destination address", /* COL_DEF_DST */
124 "Dest addr (resolved)", /* COL_RES_DST */
125 "Dest addr (unresolved)", /* COL_UNRES_DST */
126 "Hardware dest addr", /* COL_DEF_DL_DST */
127 "Hw dest addr (resolved)", /* COL_RES_DL_DST */
128 "Hw dest addr (unresolved)", /* COL_UNRES_DL_DST */
129 "Network dest addr", /* COL_DEF_NET_DST */
130 "Net dest addr (resolved)", /* COL_RES_NET_DST */
131 "Net dest addr (unresolved)", /* COL_UNRES_NET_DST */
132 "Source port", /* COL_DEF_SRC_PORT */
133 "Src port (resolved)", /* COL_RES_SRC_PORT */
134 "Src port (unresolved)", /* COL_UNRES_SRC_PORT */
135 "Destination port", /* COL_DEF_DST_PORT */
136 "Dest port (resolved)", /* COL_RES_DST_PORT */
137 "Dest port (unresolved)", /* COL_UNRES_DST_PORT */
138 "Protocol", /* COL_PROTOCOL */
139 "Information", /* COL_INFO */
140 "Packet length (bytes)" , /* COL_PACKET_LENGTH */
141 "Cumulative Bytes" , /* COL_CUMULATIVE_BYTES */
142 "Fibre Channel OXID", /* COL_OXID */
143 "Fibre Channel RXID", /* COL_RXID */
144 "FW-1 monitor if/direction", /* COL_IF_DIR */
145 "Circuit ID", /* COL_CIRCUIT_ID */
146 "Cisco Src PortIdx", /* COL_SRCIDX */
147 "Cisco Dst PortIdx", /* COL_DSTIDX */
148 "Cisco VSAN", /* COL_VSAN */
149 "IEEE 802.11 TX rate", /* COL_TX_RATE */
150 "IEEE 802.11 RSSI", /* COL_RSSI */
151 "HP-UX Subsystem", /* COL_HPUX_SUBSYS */
152 "HP-UX Device ID", /* COL_HPUX_DEVID */
153 "DCE/RPC call (cn_call_id / dg_seqnum)", /* COL_DCE_CALL */
154 "DCE/RPC context ID (cn_ctx_id)", /* COL_DCE_CTX */
155 "802.1Q VLAN id", /* COL_8021Q_VLAN_ID */
156 "TEI", /* XXX - why is it missing in column_utils.c and elsewhere? */
160 col_format_desc(gint fmt) {
161 g_assert((fmt >= 0) && (fmt < NUM_COL_FMTS));
165 /* Marks each array element true if it can be substituted for the given
168 get_column_format_matches(gboolean *fmt_list, gint format) {
170 /* Get the obvious: the format itself */
171 if ((format >= 0) && (format < NUM_COL_FMTS))
172 fmt_list[format] = TRUE;
174 /* Get any formats lower down on the chain */
177 fmt_list[COL_RES_DL_SRC] = TRUE;
178 fmt_list[COL_RES_NET_SRC] = TRUE;
181 fmt_list[COL_RES_DL_SRC] = TRUE;
182 fmt_list[COL_RES_NET_SRC] = TRUE;
185 fmt_list[COL_UNRES_DL_SRC] = TRUE;
186 fmt_list[COL_UNRES_NET_SRC] = TRUE;
189 fmt_list[COL_RES_DL_DST] = TRUE;
190 fmt_list[COL_RES_NET_DST] = TRUE;
193 fmt_list[COL_RES_DL_DST] = TRUE;
194 fmt_list[COL_RES_NET_DST] = TRUE;
197 fmt_list[COL_UNRES_DL_DST] = TRUE;
198 fmt_list[COL_UNRES_NET_DST] = TRUE;
201 fmt_list[COL_RES_DL_SRC] = TRUE;
204 fmt_list[COL_RES_DL_DST] = TRUE;
206 case COL_DEF_NET_SRC:
207 fmt_list[COL_RES_NET_SRC] = TRUE;
209 case COL_DEF_NET_DST:
210 fmt_list[COL_RES_NET_DST] = TRUE;
212 case COL_DEF_SRC_PORT:
213 fmt_list[COL_RES_SRC_PORT] = TRUE;
215 case COL_DEF_DST_PORT:
216 fmt_list[COL_RES_DST_PORT] = TRUE;
219 fmt_list[COL_OXID] = TRUE;
222 fmt_list[COL_RXID] = TRUE;
225 fmt_list[COL_IF_DIR] = TRUE;
228 fmt_list[COL_CIRCUIT_ID] = TRUE;
231 fmt_list[COL_SRCIDX] = TRUE;
234 fmt_list[COL_DSTIDX] = TRUE;
237 fmt_list[COL_VSAN] = TRUE;
240 fmt_list[COL_TX_RATE] = TRUE;
243 fmt_list[COL_RSSI] = TRUE;
245 case COL_HPUX_SUBSYS:
246 fmt_list[COL_HPUX_SUBSYS] = TRUE;
249 fmt_list[COL_HPUX_DEVID] = TRUE;
252 fmt_list[COL_DCE_CALL] = TRUE;
255 fmt_list[COL_DCE_CTX] = TRUE;
257 case COL_8021Q_VLAN_ID:
258 fmt_list[COL_8021Q_VLAN_ID] = TRUE;
261 fmt_list[COL_TEI] = TRUE;
268 /* Returns a string representing the longest possible value for
269 a timestamp column type. */
271 get_timestamp_column_longest_string(gint type, gint precision)
275 case(TS_ABSOLUTE_WITH_DATE):
277 case(TS_PREC_AUTO_SEC):
278 case(TS_PREC_FIXED_SEC):
279 return "0000-00-00 00:00:00";
281 case(TS_PREC_AUTO_DSEC):
282 case(TS_PREC_FIXED_DSEC):
283 return "0000-00-00 00:00:00.0";
285 case(TS_PREC_AUTO_CSEC):
286 case(TS_PREC_FIXED_CSEC):
287 return "0000-00-00 00:00:00.00";
289 case(TS_PREC_AUTO_MSEC):
290 case(TS_PREC_FIXED_MSEC):
291 return "0000-00-00 00:00:00.000";
293 case(TS_PREC_AUTO_USEC):
294 case(TS_PREC_FIXED_USEC):
295 return "0000-00-00 00:00:00.000000";
297 case(TS_PREC_AUTO_NSEC):
298 case(TS_PREC_FIXED_NSEC):
299 return "0000-00-00 00:00:00.000000000";
302 g_assert_not_reached();
307 case(TS_PREC_AUTO_SEC):
308 case(TS_PREC_FIXED_SEC):
311 case(TS_PREC_AUTO_DSEC):
312 case(TS_PREC_FIXED_DSEC):
315 case(TS_PREC_AUTO_CSEC):
316 case(TS_PREC_FIXED_CSEC):
317 return "00:00:00.00";
319 case(TS_PREC_AUTO_MSEC):
320 case(TS_PREC_FIXED_MSEC):
321 return "00:00:00.000";
323 case(TS_PREC_AUTO_USEC):
324 case(TS_PREC_FIXED_USEC):
325 return "00:00:00.000000";
327 case(TS_PREC_AUTO_NSEC):
328 case(TS_PREC_FIXED_NSEC):
329 return "00:00:00.000000000";
332 g_assert_not_reached();
335 case(TS_RELATIVE): /* fallthrough */
338 case(TS_PREC_AUTO_SEC):
339 case(TS_PREC_FIXED_SEC):
342 case(TS_PREC_AUTO_DSEC):
343 case(TS_PREC_FIXED_DSEC):
346 case(TS_PREC_AUTO_CSEC):
347 case(TS_PREC_FIXED_CSEC):
350 case(TS_PREC_AUTO_MSEC):
351 case(TS_PREC_FIXED_MSEC):
354 case(TS_PREC_AUTO_USEC):
355 case(TS_PREC_FIXED_USEC):
356 return "0000.000000";
358 case(TS_PREC_AUTO_NSEC):
359 case(TS_PREC_FIXED_NSEC):
360 return "0000.000000000";
363 g_assert_not_reached();
367 return "0000.000000";
370 g_assert_not_reached();
373 /* never reached, satisfy compiler */
377 /* Returns a string representing the longest possible value for a
378 particular column type.
380 Except for the COL...SRC and COL...DST columns, these are used
381 only when a capture is being displayed while it's taking place;
382 they are arguably somewhat fragile, as changes to the code that
383 generates them don't cause these widths to change, but that's
384 probably not too big a problem, given that the sizes are
385 recomputed based on the actual data in the columns when the capture
386 is done, and given that the width for COL...SRC and COL...DST columns
387 is somewhat arbitrary in any case. We should probably clean
388 that up eventually, though. */
390 get_column_longest_string(gint format)
397 return get_timestamp_column_longest_string(timestamp_get_type(), timestamp_get_precision());
399 case COL_ABS_DATE_TIME:
400 return get_timestamp_column_longest_string(TS_ABSOLUTE_WITH_DATE, timestamp_get_precision());
403 return get_timestamp_column_longest_string(TS_ABSOLUTE, timestamp_get_precision());
406 return get_timestamp_column_longest_string(TS_RELATIVE, timestamp_get_precision());
409 return get_timestamp_column_longest_string(TS_DELTA, timestamp_get_precision());
416 case COL_UNRES_DL_SRC:
417 case COL_DEF_NET_SRC:
418 case COL_RES_NET_SRC:
419 case COL_UNRES_NET_SRC:
425 case COL_UNRES_DL_DST:
426 case COL_DEF_NET_DST:
427 case COL_RES_NET_DST:
428 case COL_UNRES_NET_DST:
429 return "00000000.000000000000"; /* IPX-style */
431 case COL_DEF_SRC_PORT:
432 case COL_RES_SRC_PORT:
433 case COL_UNRES_SRC_PORT:
434 case COL_DEF_DST_PORT:
435 case COL_RES_DST_PORT:
436 case COL_UNRES_DST_PORT:
440 return "Protocol"; /* not the longest, but the longest is too long */
442 case COL_PACKET_LENGTH:
445 case COL_CUMULATIVE_BYTES:
453 return "i 00000000 I";
471 case COL_HPUX_SUBSYS:
472 return "OTS9000-TRANSPORT";
483 case COL_8021Q_VLAN_ID:
489 default: /* COL_INFO */
490 return "Source port: kerberos-master Destination port: kerberos-master";
495 /* Returns the longest possible width, in characters, for a particular
498 get_column_char_width(gint format)
500 return strlen(get_column_longest_string(format));
506 #define DATE_TIME_ABS 3
518 get_column_format(gint col) {
519 GList *clp = g_list_nth(prefs.col_list, col);
522 cfmt = (fmt_data *) clp->data;
524 return(get_column_format_from_str(cfmt->fmt));
528 get_column_format_from_str(gchar *str) {
530 gint res_off = RES_DEF, addr_off = ADDR_DEF, time_off = TIME_DEF;
533 /* To do: Make this parse %-formatted strings "for real" */
534 while (*cptr != '\0') {
536 case 't': /* To do: fix for absolute and delta */
537 return COL_CLS_TIME + time_off;
543 if (prev_code == COL_OXID) {
547 return COL_DEF_SRC + res_off + addr_off;
551 if (prev_code == COL_OXID) {
555 return COL_DEF_DST + res_off + addr_off;
559 return COL_DEF_SRC_PORT + res_off;
562 return COL_DEF_DST_PORT + res_off;
583 if (prev_code == COL_OXID) {
594 time_off = DATE_TIME_ABS;
600 return COL_PACKET_LENGTH;
603 return COL_CUMULATIVE_BYTES;
606 prev_code = COL_OXID;
615 return COL_CIRCUIT_ID;
627 return COL_HPUX_SUBSYS;
630 return COL_HPUX_DEVID;
639 return COL_8021Q_VLAN_ID;
647 return -1; /* illegal */
651 get_column_title(gint col) {
652 GList *clp = g_list_nth(prefs.col_list, col);
655 cfmt = (fmt_data *) clp->data;