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/nstime.h>
41 #include <epan/dfilter/dfilter.h>
43 #include <epan/column.h>
44 #include <epan/packet.h>
46 /* Given a format number (as defined in column_info.h), returns its equivalent
49 col_format_to_string(gint fmt) {
50 const gchar *slist[] = {
51 "%q", /* 0) COL_8021Q_VLAN_ID */
52 "%Yt", /* 1) COL_ABS_DATE_TIME */
53 "%At", /* 2) COL_ABS_TIME */
54 "%c", /* 3) COL_CIRCUIT_ID */
55 "%Xd", /* 4) COL_DSTIDX */
56 "%Xs", /* 5) COL_SRCIDX */
57 "%V", /* 6) COL_VSAN */
58 "%B", /* 7) COL_CUMULATIVE_BYTES */
59 "%Cus", /* 8) COL_CUSTOM */
60 "%y", /* 9) COL_DCE_CALL */
61 "%z", /* 10) COL_DCE_CTX */
62 "%Tt", /* 11) COL_DELTA_TIME */
63 "%dct", /* 12) COL_DELTA_CONV_TIME */
64 "%Gt", /* 13) COL_DELTA_TIME_DIS */
65 "%rd", /* 14) COL_RES_DST */
66 "%ud", /* 15) COL_UNRES_DST */
67 "%rD", /* 16) COL_RES_DST_PORT */
68 "%uD", /* 17) COL_UNRES_DST_PORT */
69 "%d", /* 18) COL_DEF_DST */
70 "%D", /* 19) COL_DEF_DST_PORT */
71 "%a", /* 20) COL_EXPERT */
72 "%I", /* 21) COL_IF_DIR */
73 "%XO", /* 22) COL_OXID */
74 "%XR", /* 23) COL_RXID */
75 "%C", /* 24) COL_FR_DLCI */
76 "%F", /* 25) COL_FREQ_CHAN */
77 "%l", /* 26) COL_BSSGP_TLLI */
78 "%P", /* 27) COL_HPUX_DEVID */
79 "%H", /* 28) COL_HPUX_SUBSYS */
80 "%hd", /* 29) COL_DEF_DL_DST */
81 "%hs", /* 30) COL_DEF_DL_SRC */
82 "%rhd", /* 31) COL_RES_DL_DST */
83 "%uhd", /* 32) COL_UNRES_DL_DST */
84 "%rhs", /* 33) COL_RES_DL_SRC*/
85 "%uhs", /* 34) COL_UNRES_DL_SRC */
86 "%e", /* 35) COL_RSSI */
87 "%x", /* 36) COL_TX_RATE */
88 "%f", /* 37) COL_DSCP_VALUE */
89 "%i", /* 38) COL_INFO */
90 "%U", /* 39) COL_COS_VALUE */
91 "%rnd", /* 40) COL_RES_NET_DST */
92 "%und", /* 41) COL_UNRES_NET_DST */
93 "%rns", /* 42) COL_RES_NET_SRC */
94 "%uns", /* 43) COL_UNRES_NET_SRC */
95 "%nd", /* 44) COL_DEF_NET_DST */
96 "%ns", /* 45) COL_DEF_NET_SRC */
97 "%m", /* 46) COL_NUMBER */
98 "%L", /* 47) COL_PACKET_LENGTH */
99 "%p", /* 48) COL_PROTOCOL */
100 "%Rt", /* 49) COL_REL_TIME */
101 "%rct", /* 50) COL_REL_CONV_TIME */
102 "%s", /* 51) COL_DEF_SRC */
103 "%S", /* 52) COL_DEF_SRC_PORT */
104 "%rs", /* 53) COL_RES_SRC */
105 "%us", /* 54) COL_UNRES_SRC */
106 "%rS", /* 55) COL_RES_SRC_PORT */
107 "%uS", /* 56) COL_UNRES_SRC_PORT */
108 "%E", /* 57) COL_TEI */
109 "%t" /* 58) COL_CLS_TIME */
112 if (fmt < 0 || fmt >= NUM_COL_FMTS)
118 /* Given a format number (as defined in column_info.h), returns its
120 static const gchar *dlist[NUM_COL_FMTS] = {
121 "802.1Q VLAN id", /* 0) COL_8021Q_VLAN_ID */
122 "Absolute date and time", /* 1) COL_ABS_DATE_TIME */
123 "Absolute time", /* 2) COL_ABS_TIME */
124 "Circuit ID", /* 3) COL_CIRCUIT_ID */
125 "Cisco Dst PortIdx", /* 4) COL_DSTIDX */
126 "Cisco Src PortIdx", /* 5) COL_SRCIDX */
127 "Cisco VSAN", /* 6) COL_VSAN */
128 "Cumulative Bytes" , /* 7) COL_CUMULATIVE_BYTES */
129 "Custom", /* 8) COL_CUSTOM */
130 "DCE/RPC call (cn_call_id / dg_seqnum)", /* 9) COL_DCE_CALL */
131 "DCE/RPC context ID (cn_ctx_id)", /* 10) COL_DCE_CTX */
132 "Delta time", /* 11) COL_DELTA_TIME */
133 "Delta time (conversation)", /* 12) COL_DELTA_CONV_TIME */
134 "Delta time displayed", /* 13) COL_DELTA_TIME_DIS */
135 "Dest addr (resolved)", /* 14) COL_RES_DST */
136 "Dest addr (unresolved)", /* 15) COL_UNRES_DST */
137 "Dest port (resolved)", /* 16) COL_RES_DST_PORT */
138 "Dest port (unresolved)", /* 17) COL_UNRES_DST_PORT */
139 "Destination address", /* 18) COL_DEF_DST */
140 "Destination port", /* 19) COL_DEF_DST_PORT */
141 "Expert Info Severity", /* 20) COL_EXPERT */
142 "FW-1 monitor if/direction", /* 21) COL_IF_DIR */
143 "Fibre Channel OXID", /* 22) COL_OXID */
144 "Fibre Channel RXID", /* 23) COL_RXID */
145 "Frame Relay DLCI", /* 24) COL_FR_DLCI */
146 "Frequency/Channel", /* 25) COL_FREQ_CHAN */
147 "GPRS BSSGP TLLI", /* 26) COL_BSSGP_TLLI */
148 "HP-UX Device ID", /* 27) COL_HPUX_DEVID */
149 "HP-UX Subsystem", /* 28) COL_HPUX_SUBSYS */
150 "Hardware dest addr", /* 29) COL_DEF_DL_DST */
151 "Hardware src addr", /* 30) COL_DEF_DL_SRC */
152 "Hw dest addr (resolved)", /* 31) COL_RES_DL_DST */
153 "Hw dest addr (unresolved)", /* 32) COL_UNRES_DL_DST */
154 "Hw src addr (resolved)", /* 33) COL_RES_DL_SRC*/
155 "Hw src addr (unresolved)", /* 34) COL_UNRES_DL_SRC */
156 "IEEE 802.11 RSSI", /* 35) COL_RSSI */
157 "IEEE 802.11 TX rate", /* 36) COL_TX_RATE */
158 "IP DSCP Value", /* 37) COL_DSCP_VALUE */
159 "Information", /* 38) COL_INFO */
160 "L2 COS Value (802.1p)", /* 39) COL_COS_VALUE */
161 "Net dest addr (resolved)", /* 40) COL_RES_NET_DST */
162 "Net dest addr (unresolved)", /* 41) COL_UNRES_NET_DST */
163 "Net src addr (resolved)", /* 42) COL_RES_NET_SRC */
164 "Net src addr (unresolved)", /* 43) COL_UNRES_NET_SRC */
165 "Network dest addr", /* 44) COL_DEF_NET_DST */
166 "Network src addr", /* 45) COL_DEF_NET_SRC */
167 "Number", /* 46) COL_NUMBER */
168 "Packet length (bytes)" , /* 47) COL_PACKET_LENGTH */
169 "Protocol", /* 48) COL_PROTOCOL */
170 "Relative time", /* 49) COL_REL_TIME */
171 "Relative time (conversation)", /* 50) COL_REL_CONV_TIME */
172 "Source address", /* 51) COL_DEF_SRC */
173 "Source port", /* 52) COL_DEF_SRC_PORT */
174 "Src addr (resolved)", /* 53) COL_RES_SRC */
175 "Src addr (unresolved)", /* 54) COL_UNRES_SRC */
176 "Src port (resolved)", /* 55) COL_RES_SRC_PORT */
177 "Src port (unresolved)", /* 56) COL_UNRES_SRC_PORT */
178 "TEI", /* 57) COL_TEI */
179 "Time (format as specified)" /* 58) COL_CLS_TIME */
183 col_format_desc(gint fmt) {
184 g_assert((fmt >= 0) && (fmt < NUM_COL_FMTS));
188 /* Marks each array element true if it can be substituted for the given
191 get_column_format_matches(gboolean *fmt_list, gint format) {
193 /* Get the obvious: the format itself */
194 if ((format >= 0) && (format < NUM_COL_FMTS))
195 fmt_list[format] = TRUE;
197 /* Get any formats lower down on the chain */
200 fmt_list[COL_RES_DL_SRC] = TRUE;
201 fmt_list[COL_RES_NET_SRC] = TRUE;
204 fmt_list[COL_RES_DL_SRC] = TRUE;
205 fmt_list[COL_RES_NET_SRC] = TRUE;
208 fmt_list[COL_UNRES_DL_SRC] = TRUE;
209 fmt_list[COL_UNRES_NET_SRC] = TRUE;
212 fmt_list[COL_RES_DL_DST] = TRUE;
213 fmt_list[COL_RES_NET_DST] = TRUE;
216 fmt_list[COL_RES_DL_DST] = TRUE;
217 fmt_list[COL_RES_NET_DST] = TRUE;
220 fmt_list[COL_UNRES_DL_DST] = TRUE;
221 fmt_list[COL_UNRES_NET_DST] = TRUE;
224 fmt_list[COL_RES_DL_SRC] = TRUE;
227 fmt_list[COL_RES_DL_DST] = TRUE;
229 case COL_DEF_NET_SRC:
230 fmt_list[COL_RES_NET_SRC] = TRUE;
232 case COL_DEF_NET_DST:
233 fmt_list[COL_RES_NET_DST] = TRUE;
235 case COL_DEF_SRC_PORT:
236 fmt_list[COL_RES_SRC_PORT] = TRUE;
238 case COL_DEF_DST_PORT:
239 fmt_list[COL_RES_DST_PORT] = TRUE;
242 fmt_list[COL_OXID] = TRUE;
245 fmt_list[COL_RXID] = TRUE;
248 fmt_list[COL_IF_DIR] = TRUE;
251 fmt_list[COL_CIRCUIT_ID] = TRUE;
254 fmt_list[COL_SRCIDX] = TRUE;
257 fmt_list[COL_DSTIDX] = TRUE;
260 fmt_list[COL_VSAN] = TRUE;
263 fmt_list[COL_TX_RATE] = TRUE;
266 fmt_list[COL_RSSI] = TRUE;
268 case COL_HPUX_SUBSYS:
269 fmt_list[COL_HPUX_SUBSYS] = TRUE;
272 fmt_list[COL_HPUX_DEVID] = TRUE;
275 fmt_list[COL_DCE_CALL] = TRUE;
278 fmt_list[COL_DCE_CTX] = TRUE;
280 case COL_8021Q_VLAN_ID:
281 fmt_list[COL_8021Q_VLAN_ID] = TRUE;
284 fmt_list[COL_DSCP_VALUE] = TRUE;
287 fmt_list[COL_COS_VALUE] = TRUE;
290 fmt_list[COL_TEI] = TRUE;
293 fmt_list[COL_FR_DLCI] = TRUE;
296 fmt_list[COL_BSSGP_TLLI] = TRUE;
299 fmt_list[COL_EXPERT] = TRUE;
302 fmt_list[COL_FREQ_CHAN] = TRUE;
305 fmt_list[COL_CUSTOM] = TRUE;
312 /* Returns a string representing the longest possible value for
313 a timestamp column type. */
315 get_timestamp_column_longest_string(gint type, gint precision)
319 case(TS_ABSOLUTE_WITH_DATE):
321 case(TS_PREC_AUTO_SEC):
322 case(TS_PREC_FIXED_SEC):
323 return "0000-00-00 00:00:00";
325 case(TS_PREC_AUTO_DSEC):
326 case(TS_PREC_FIXED_DSEC):
327 return "0000-00-00 00:00:00.0";
329 case(TS_PREC_AUTO_CSEC):
330 case(TS_PREC_FIXED_CSEC):
331 return "0000-00-00 00:00:00.00";
333 case(TS_PREC_AUTO_MSEC):
334 case(TS_PREC_FIXED_MSEC):
335 return "0000-00-00 00:00:00.000";
337 case(TS_PREC_AUTO_USEC):
338 case(TS_PREC_FIXED_USEC):
339 return "0000-00-00 00:00:00.000000";
341 case(TS_PREC_AUTO_NSEC):
342 case(TS_PREC_FIXED_NSEC):
343 return "0000-00-00 00:00:00.000000000";
346 g_assert_not_reached();
351 case(TS_PREC_AUTO_SEC):
352 case(TS_PREC_FIXED_SEC):
355 case(TS_PREC_AUTO_DSEC):
356 case(TS_PREC_FIXED_DSEC):
359 case(TS_PREC_AUTO_CSEC):
360 case(TS_PREC_FIXED_CSEC):
361 return "00:00:00.00";
363 case(TS_PREC_AUTO_MSEC):
364 case(TS_PREC_FIXED_MSEC):
365 return "00:00:00.000";
367 case(TS_PREC_AUTO_USEC):
368 case(TS_PREC_FIXED_USEC):
369 return "00:00:00.000000";
371 case(TS_PREC_AUTO_NSEC):
372 case(TS_PREC_FIXED_NSEC):
373 return "00:00:00.000000000";
376 g_assert_not_reached();
379 case(TS_RELATIVE): /* fallthrough */
383 case(TS_PREC_AUTO_SEC):
384 case(TS_PREC_FIXED_SEC):
387 case(TS_PREC_AUTO_DSEC):
388 case(TS_PREC_FIXED_DSEC):
391 case(TS_PREC_AUTO_CSEC):
392 case(TS_PREC_FIXED_CSEC):
395 case(TS_PREC_AUTO_MSEC):
396 case(TS_PREC_FIXED_MSEC):
399 case(TS_PREC_AUTO_USEC):
400 case(TS_PREC_FIXED_USEC):
401 return "0000.000000";
403 case(TS_PREC_AUTO_NSEC):
404 case(TS_PREC_FIXED_NSEC):
405 return "0000.000000000";
408 g_assert_not_reached();
412 /* This is enough to represent 2^63 (signed 64-bit integer) + fractions */
414 case(TS_PREC_AUTO_SEC):
415 case(TS_PREC_FIXED_SEC):
416 return "0000000000000000000";
418 case(TS_PREC_AUTO_DSEC):
419 case(TS_PREC_FIXED_DSEC):
420 return "0000000000000000000.0";
422 case(TS_PREC_AUTO_CSEC):
423 case(TS_PREC_FIXED_CSEC):
424 return "0000000000000000000.00";
426 case(TS_PREC_AUTO_MSEC):
427 case(TS_PREC_FIXED_MSEC):
428 return "0000000000000000000.000";
430 case(TS_PREC_AUTO_USEC):
431 case(TS_PREC_FIXED_USEC):
432 return "0000000000000000000.000000";
434 case(TS_PREC_AUTO_NSEC):
435 case(TS_PREC_FIXED_NSEC):
436 return "0000000000000000000.000000000";
439 g_assert_not_reached();
443 return "0000.000000";
446 g_assert_not_reached();
449 /* never reached, satisfy compiler */
453 /* Returns the longer string of the column title or the hard-coded width of
454 * its contents for building the packet list layout. */
456 get_column_width_string(gint format, gint col)
458 if(strlen(get_column_longest_string(format)) >
459 strlen(get_column_title(col)))
460 return get_column_longest_string(format);
462 return get_column_title(col);
465 /* Returns a string representing the longest possible value for a
466 particular column type. See also get_column_width_string() above.
468 Except for the COL...SRC and COL...DST columns, these are used
469 only when a capture is being displayed while it's taking place;
470 they are arguably somewhat fragile, as changes to the code that
471 generates them don't cause these widths to change, but that's
472 probably not too big a problem, given that the sizes are
473 recomputed based on the actual data in the columns when the capture
474 is done, and given that the width for COL...SRC and COL...DST columns
475 is somewhat arbitrary in any case. We should probably clean
476 that up eventually, though. */
478 get_column_longest_string(gint format)
485 return get_timestamp_column_longest_string(timestamp_get_type(), timestamp_get_precision());
487 case COL_ABS_DATE_TIME:
488 return get_timestamp_column_longest_string(TS_ABSOLUTE_WITH_DATE, timestamp_get_precision());
491 return get_timestamp_column_longest_string(TS_ABSOLUTE, timestamp_get_precision());
494 return get_timestamp_column_longest_string(TS_RELATIVE, timestamp_get_precision());
497 return get_timestamp_column_longest_string(TS_DELTA, timestamp_get_precision());
499 case COL_DELTA_TIME_DIS:
500 return get_timestamp_column_longest_string(TS_DELTA_DIS, timestamp_get_precision());
502 case COL_REL_CONV_TIME: /* 'abuse' TS_RELATIVE to set the time format */
503 case COL_DELTA_CONV_TIME: /* for the conversation related time columns */
504 return get_timestamp_column_longest_string(TS_RELATIVE, timestamp_get_precision());
511 case COL_UNRES_DL_SRC:
512 case COL_DEF_NET_SRC:
513 case COL_RES_NET_SRC:
514 case COL_UNRES_NET_SRC:
520 case COL_UNRES_DL_DST:
521 case COL_DEF_NET_DST:
522 case COL_RES_NET_DST:
523 case COL_UNRES_NET_DST:
524 return "00000000.000000000000"; /* IPX-style */
526 case COL_DEF_SRC_PORT:
527 case COL_RES_SRC_PORT:
528 case COL_UNRES_SRC_PORT:
529 case COL_DEF_DST_PORT:
530 case COL_RES_DST_PORT:
531 case COL_UNRES_DST_PORT:
535 return "Protocol"; /* not the longest, but the longest is too long */
537 case COL_PACKET_LENGTH:
540 case COL_CUMULATIVE_BYTES:
548 return "i 00000000 I";
566 case COL_HPUX_SUBSYS:
567 return "OTS9000-TRANSPORT";
578 case COL_8021Q_VLAN_ID:
600 return "9999 MHz [A 999]";
603 return "0000000000"; /* not the longest, but the longest is too long */
605 default: /* COL_INFO */
606 return "Source port: kerberos-master Destination port: kerberos-master";
611 /* Returns the longest possible width, in characters, for a particular
614 get_column_char_width(gint format)
616 return strlen(get_column_longest_string(format));
620 get_column_format(gint col) {
621 GList *clp = g_list_nth(prefs.col_list, col);
624 cfmt = (fmt_data *) clp->data;
626 return(get_column_format_from_str(cfmt->fmt));
630 get_column_format_from_str(gchar *str) {
633 for (i = 0; i < NUM_COL_FMTS; i++) {
634 if (strcmp(str, col_format_to_string(i)) == 0)
637 return -1; /* illegal */
641 get_column_title(gint col) {
642 GList *clp = g_list_nth(prefs.col_list, col);
645 cfmt = (fmt_data *) clp->data;
651 get_column_custom_field(gint col) {
652 GList *clp = g_list_nth(prefs.col_list, col);
655 cfmt = (fmt_data *) clp->data;
657 return(cfmt->custom_field);
661 build_column_format_array(capture_file *cfile, gboolean reset_fences)
665 col_setup(&cfile->cinfo, prefs.num_cols);
667 for (i = 0; i < cfile->cinfo.num_cols; i++) {
668 cfile->cinfo.col_fmt[i] = get_column_format(i);
669 cfile->cinfo.col_title[i] = g_strdup(get_column_title(i));
670 if (cfile->cinfo.col_fmt[i] == COL_CUSTOM) {
671 cfile->cinfo.col_custom_field[i] = g_strdup(get_column_custom_field(i));
673 cfile->cinfo.col_custom_field[i] = NULL;
675 cfile->cinfo.fmt_matx[i] = (gboolean *) g_malloc0(sizeof(gboolean) *
677 get_column_format_matches(cfile->cinfo.fmt_matx[i],
678 cfile->cinfo.col_fmt[i]);
679 cfile->cinfo.col_data[i] = NULL;
681 if (cfile->cinfo.col_fmt[i] == COL_INFO)
682 cfile->cinfo.col_buf[i] = (gchar *) g_malloc(sizeof(gchar) *
685 cfile->cinfo.col_buf[i] = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN);
688 cfile->cinfo.col_fence[i] = 0;
690 cfile->cinfo.col_expr.col_expr[i] = (gchar *) g_malloc(sizeof(gchar) *
692 cfile->cinfo.col_expr.col_expr_val[i] = (gchar *) g_malloc(sizeof(gchar) *
696 for (i = 0; i < cfile->cinfo.num_cols; i++) {
697 for (j = 0; j < NUM_COL_FMTS; j++) {
698 if (!cfile->cinfo.fmt_matx[i][j])
701 if (cfile->cinfo.col_first[j] == -1)
702 cfile->cinfo.col_first[j] = i;
704 cfile->cinfo.col_last[j] = i;