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[] = {
101 if (fmt < 0 || fmt >= NUM_COL_FMTS)
107 /* Given a format number (as defined in packet.h), returns its
109 static const gchar *dlist[NUM_COL_FMTS] = {
110 "Number", /* COL_NUMBER */
111 "Time (format as specified)", /* COL_CLS_TIME */
112 "Relative time", /* COL_REL_TIME */
113 "Absolute time", /* COL_ABS_TIME */
114 "Absolute date and time", /* COL_ABS_DATE_TIME */
115 "Delta time", /* COL_DELTA_TIME */
116 "Source address", /* COL_DEF_SRC */
117 "Src addr (resolved)", /* COL_RES_SRC */
118 "Src addr (unresolved)", /* COL_UNRES_SRC */
119 "Hardware src addr", /* COL_DEF_DL_SRC */
120 "Hw src addr (resolved)", /* COL_RES_DL_SRC*/
121 "Hw src addr (unresolved)", /* COL_UNRES_DL_SRC */
122 "Network src addr", /* COL_DEF_NET_SRC */
123 "Net src addr (resolved)", /* COL_RES_NET_SRC */
124 "Net src addr (unresolved)", /* COL_UNRES_NET_SRC */
125 "Destination address", /* COL_DEF_DST */
126 "Dest addr (resolved)", /* COL_RES_DST */
127 "Dest addr (unresolved)", /* COL_UNRES_DST */
128 "Hardware dest addr", /* COL_DEF_DL_DST */
129 "Hw dest addr (resolved)", /* COL_RES_DL_DST */
130 "Hw dest addr (unresolved)", /* COL_UNRES_DL_DST */
131 "Network dest addr", /* COL_DEF_NET_DST */
132 "Net dest addr (resolved)", /* COL_RES_NET_DST */
133 "Net dest addr (unresolved)", /* COL_UNRES_NET_DST */
134 "Source port", /* COL_DEF_SRC_PORT */
135 "Src port (resolved)", /* COL_RES_SRC_PORT */
136 "Src port (unresolved)", /* COL_UNRES_SRC_PORT */
137 "Destination port", /* COL_DEF_DST_PORT */
138 "Dest port (resolved)", /* COL_RES_DST_PORT */
139 "Dest port (unresolved)", /* COL_UNRES_DST_PORT */
140 "Protocol", /* COL_PROTOCOL */
141 "Information", /* COL_INFO */
142 "Packet length (bytes)" , /* COL_PACKET_LENGTH */
143 "Cumulative Bytes" , /* COL_CUMULATIVE_BYTES */
144 "Fibre Channel OXID", /* COL_OXID */
145 "Fibre Channel RXID", /* COL_RXID */
146 "FW-1 monitor if/direction", /* COL_IF_DIR */
147 "Circuit ID", /* COL_CIRCUIT_ID */
148 "Cisco Src PortIdx", /* COL_SRCIDX */
149 "Cisco Dst PortIdx", /* COL_DSTIDX */
150 "Cisco VSAN", /* COL_VSAN */
151 "IEEE 802.11 TX rate", /* COL_TX_RATE */
152 "IEEE 802.11 RSSI", /* COL_RSSI */
153 "HP-UX Subsystem", /* COL_HPUX_SUBSYS */
154 "HP-UX Device ID", /* COL_HPUX_DEVID */
155 "DCE/RPC call (cn_call_id / dg_seqnum)", /* COL_DCE_CALL */
156 "DCE/RPC context ID (cn_ctx_id)", /* COL_DCE_CTX */
157 "802.1Q VLAN id", /* COL_8021Q_VLAN_ID */
158 "TEI", /* XXX - why is it missing in column_utils.c and elsewhere? */
159 "Frame Relay DLCI", /* COL_FR_DLCI */
160 "GPRS BSSGP TLLI", /* COL_BSSGP_TLLI */
164 col_format_desc(gint fmt) {
165 g_assert((fmt >= 0) && (fmt < NUM_COL_FMTS));
169 /* Marks each array element true if it can be substituted for the given
172 get_column_format_matches(gboolean *fmt_list, gint format) {
174 /* Get the obvious: the format itself */
175 if ((format >= 0) && (format < NUM_COL_FMTS))
176 fmt_list[format] = TRUE;
178 /* Get any formats lower down on the chain */
181 fmt_list[COL_RES_DL_SRC] = TRUE;
182 fmt_list[COL_RES_NET_SRC] = TRUE;
185 fmt_list[COL_RES_DL_SRC] = TRUE;
186 fmt_list[COL_RES_NET_SRC] = TRUE;
189 fmt_list[COL_UNRES_DL_SRC] = TRUE;
190 fmt_list[COL_UNRES_NET_SRC] = TRUE;
193 fmt_list[COL_RES_DL_DST] = TRUE;
194 fmt_list[COL_RES_NET_DST] = TRUE;
197 fmt_list[COL_RES_DL_DST] = TRUE;
198 fmt_list[COL_RES_NET_DST] = TRUE;
201 fmt_list[COL_UNRES_DL_DST] = TRUE;
202 fmt_list[COL_UNRES_NET_DST] = TRUE;
205 fmt_list[COL_RES_DL_SRC] = TRUE;
208 fmt_list[COL_RES_DL_DST] = TRUE;
210 case COL_DEF_NET_SRC:
211 fmt_list[COL_RES_NET_SRC] = TRUE;
213 case COL_DEF_NET_DST:
214 fmt_list[COL_RES_NET_DST] = TRUE;
216 case COL_DEF_SRC_PORT:
217 fmt_list[COL_RES_SRC_PORT] = TRUE;
219 case COL_DEF_DST_PORT:
220 fmt_list[COL_RES_DST_PORT] = TRUE;
223 fmt_list[COL_OXID] = TRUE;
226 fmt_list[COL_RXID] = TRUE;
229 fmt_list[COL_IF_DIR] = TRUE;
232 fmt_list[COL_CIRCUIT_ID] = TRUE;
235 fmt_list[COL_SRCIDX] = TRUE;
238 fmt_list[COL_DSTIDX] = TRUE;
241 fmt_list[COL_VSAN] = TRUE;
244 fmt_list[COL_TX_RATE] = TRUE;
247 fmt_list[COL_RSSI] = TRUE;
249 case COL_HPUX_SUBSYS:
250 fmt_list[COL_HPUX_SUBSYS] = TRUE;
253 fmt_list[COL_HPUX_DEVID] = TRUE;
256 fmt_list[COL_DCE_CALL] = TRUE;
259 fmt_list[COL_DCE_CTX] = TRUE;
261 case COL_8021Q_VLAN_ID:
262 fmt_list[COL_8021Q_VLAN_ID] = TRUE;
265 fmt_list[COL_TEI] = TRUE;
268 fmt_list[COL_FR_DLCI] = TRUE;
271 fmt_list[COL_BSSGP_TLLI] = TRUE;
278 /* Returns a string representing the longest possible value for
279 a timestamp column type. */
281 get_timestamp_column_longest_string(gint type, gint precision)
285 case(TS_ABSOLUTE_WITH_DATE):
287 case(TS_PREC_AUTO_SEC):
288 case(TS_PREC_FIXED_SEC):
289 return "0000-00-00 00:00:00";
291 case(TS_PREC_AUTO_DSEC):
292 case(TS_PREC_FIXED_DSEC):
293 return "0000-00-00 00:00:00.0";
295 case(TS_PREC_AUTO_CSEC):
296 case(TS_PREC_FIXED_CSEC):
297 return "0000-00-00 00:00:00.00";
299 case(TS_PREC_AUTO_MSEC):
300 case(TS_PREC_FIXED_MSEC):
301 return "0000-00-00 00:00:00.000";
303 case(TS_PREC_AUTO_USEC):
304 case(TS_PREC_FIXED_USEC):
305 return "0000-00-00 00:00:00.000000";
307 case(TS_PREC_AUTO_NSEC):
308 case(TS_PREC_FIXED_NSEC):
309 return "0000-00-00 00:00:00.000000000";
312 g_assert_not_reached();
317 case(TS_PREC_AUTO_SEC):
318 case(TS_PREC_FIXED_SEC):
321 case(TS_PREC_AUTO_DSEC):
322 case(TS_PREC_FIXED_DSEC):
325 case(TS_PREC_AUTO_CSEC):
326 case(TS_PREC_FIXED_CSEC):
327 return "00:00:00.00";
329 case(TS_PREC_AUTO_MSEC):
330 case(TS_PREC_FIXED_MSEC):
331 return "00:00:00.000";
333 case(TS_PREC_AUTO_USEC):
334 case(TS_PREC_FIXED_USEC):
335 return "00:00:00.000000";
337 case(TS_PREC_AUTO_NSEC):
338 case(TS_PREC_FIXED_NSEC):
339 return "00:00:00.000000000";
342 g_assert_not_reached();
345 case(TS_RELATIVE): /* fallthrough */
348 case(TS_PREC_AUTO_SEC):
349 case(TS_PREC_FIXED_SEC):
352 case(TS_PREC_AUTO_DSEC):
353 case(TS_PREC_FIXED_DSEC):
356 case(TS_PREC_AUTO_CSEC):
357 case(TS_PREC_FIXED_CSEC):
360 case(TS_PREC_AUTO_MSEC):
361 case(TS_PREC_FIXED_MSEC):
364 case(TS_PREC_AUTO_USEC):
365 case(TS_PREC_FIXED_USEC):
366 return "0000.000000";
368 case(TS_PREC_AUTO_NSEC):
369 case(TS_PREC_FIXED_NSEC):
370 return "0000.000000000";
373 g_assert_not_reached();
377 return "0000.000000";
380 g_assert_not_reached();
383 /* never reached, satisfy compiler */
387 /* Returns a string representing the longest possible value for a
388 particular column type.
390 Except for the COL...SRC and COL...DST columns, these are used
391 only when a capture is being displayed while it's taking place;
392 they are arguably somewhat fragile, as changes to the code that
393 generates them don't cause these widths to change, but that's
394 probably not too big a problem, given that the sizes are
395 recomputed based on the actual data in the columns when the capture
396 is done, and given that the width for COL...SRC and COL...DST columns
397 is somewhat arbitrary in any case. We should probably clean
398 that up eventually, though. */
400 get_column_longest_string(gint format)
407 return get_timestamp_column_longest_string(timestamp_get_type(), timestamp_get_precision());
409 case COL_ABS_DATE_TIME:
410 return get_timestamp_column_longest_string(TS_ABSOLUTE_WITH_DATE, timestamp_get_precision());
413 return get_timestamp_column_longest_string(TS_ABSOLUTE, timestamp_get_precision());
416 return get_timestamp_column_longest_string(TS_RELATIVE, timestamp_get_precision());
419 return get_timestamp_column_longest_string(TS_DELTA, timestamp_get_precision());
426 case COL_UNRES_DL_SRC:
427 case COL_DEF_NET_SRC:
428 case COL_RES_NET_SRC:
429 case COL_UNRES_NET_SRC:
435 case COL_UNRES_DL_DST:
436 case COL_DEF_NET_DST:
437 case COL_RES_NET_DST:
438 case COL_UNRES_NET_DST:
439 return "00000000.000000000000"; /* IPX-style */
441 case COL_DEF_SRC_PORT:
442 case COL_RES_SRC_PORT:
443 case COL_UNRES_SRC_PORT:
444 case COL_DEF_DST_PORT:
445 case COL_RES_DST_PORT:
446 case COL_UNRES_DST_PORT:
450 return "Protocol"; /* not the longest, but the longest is too long */
452 case COL_PACKET_LENGTH:
455 case COL_CUMULATIVE_BYTES:
463 return "i 00000000 I";
481 case COL_HPUX_SUBSYS:
482 return "OTS9000-TRANSPORT";
493 case COL_8021Q_VLAN_ID:
505 default: /* COL_INFO */
506 return "Source port: kerberos-master Destination port: kerberos-master";
511 /* Returns the longest possible width, in characters, for a particular
514 get_column_char_width(gint format)
516 return strlen(get_column_longest_string(format));
522 #define DATE_TIME_ABS 3
534 get_column_format(gint col) {
535 GList *clp = g_list_nth(prefs.col_list, col);
538 cfmt = (fmt_data *) clp->data;
540 return(get_column_format_from_str(cfmt->fmt));
544 get_column_format_from_str(gchar *str) {
546 gint res_off = RES_DEF, addr_off = ADDR_DEF, time_off = TIME_DEF;
549 /* To do: Make this parse %-formatted strings "for real" */
550 while (*cptr != '\0') {
552 case 't': /* To do: fix for absolute and delta */
553 return COL_CLS_TIME + time_off;
559 if (prev_code == COL_OXID) {
563 return COL_DEF_SRC + res_off + addr_off;
567 if (prev_code == COL_OXID) {
571 return COL_DEF_DST + res_off + addr_off;
575 return COL_DEF_SRC_PORT + res_off;
578 return COL_DEF_DST_PORT + res_off;
599 if (prev_code == COL_OXID) {
610 time_off = DATE_TIME_ABS;
616 return COL_PACKET_LENGTH;
619 return COL_CUMULATIVE_BYTES;
622 prev_code = COL_OXID;
631 return COL_CIRCUIT_ID;
643 return COL_HPUX_SUBSYS;
646 return COL_HPUX_DEVID;
655 return COL_8021Q_VLAN_ID;
662 return COL_BSSGP_TLLI;
667 return -1; /* illegal */
671 get_column_title(gint col) {
672 GList *clp = g_list_nth(prefs.col_list, col);
675 cfmt = (fmt_data *) clp->data;