2 * Routines for column utilities.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
30 #include "column-utils.h"
31 #include "timestamp.h"
32 #include "sna-utils.h"
33 #include "atalk-utils.h"
35 #include "packet_info.h"
36 #include "wsutil/pint.h"
37 #include "addr_resolv.h"
38 #include "ipv6-utils.h"
39 #include "osi-utils.h"
40 #include "value_string.h"
41 #include "column-info.h"
44 #include <epan/strutil.h>
45 #include <epan/emem.h>
46 #include <epan/epan.h>
48 /* Allocate all the data structures for constructing column data, given
49 the number of columns. */
51 col_setup(column_info
*cinfo
, const gint num_cols
)
55 cinfo
->num_cols
= num_cols
;
56 cinfo
->col_fmt
= g_new(gint
, num_cols
);
57 cinfo
->fmt_matx
= g_new(gboolean
*, num_cols
);
58 cinfo
->col_first
= g_new(int, NUM_COL_FMTS
);
59 cinfo
->col_last
= g_new(int, NUM_COL_FMTS
);
60 cinfo
->col_title
= g_new(gchar
*, num_cols
);
61 cinfo
->col_custom_field
= g_new(gchar
*, num_cols
);
62 cinfo
->col_custom_occurrence
= g_new(gint
, num_cols
);
63 cinfo
->col_custom_field_id
= g_new(int, num_cols
);
64 cinfo
->col_custom_dfilter
= g_new(dfilter_t
*, num_cols
);
65 cinfo
->col_data
= g_new(const gchar
*, num_cols
);
66 cinfo
->col_buf
= g_new(gchar
*, num_cols
);
67 cinfo
->col_fence
= g_new(int, num_cols
);
68 cinfo
->col_expr
.col_expr
= g_new(const gchar
*, num_cols
+ 1);
69 cinfo
->col_expr
.col_expr_val
= g_new(gchar
*, num_cols
+ 1);
71 for (i
= 0; i
< NUM_COL_FMTS
; i
++) {
72 cinfo
->col_first
[i
] = -1;
73 cinfo
->col_last
[i
] = -1;
77 /* Cleanup all the data structures for constructing column data; undoes
78 the allocations that col_setup() does. */
80 col_cleanup(column_info
*cinfo
)
82 g_free(cinfo
->col_fmt
);
83 g_free(cinfo
->fmt_matx
);
84 g_free(cinfo
->col_first
);
85 g_free(cinfo
->col_last
);
86 g_free(cinfo
->col_title
);
87 g_free(cinfo
->col_custom_field
);
88 g_free(cinfo
->col_custom_occurrence
);
89 g_free(cinfo
->col_custom_field_id
);
90 g_free(cinfo
->col_custom_dfilter
);
92 * XXX - MSVC doesn't correctly handle the "const" qualifier; it thinks
93 * "const XXX **" means "pointer to const pointer to XXX", i.e. that
94 * it's a pointer to something that's "const"ant, not "pointer to
95 * pointer to const XXX", i.e. that it's a pointer to a pointer to
96 * something that's "const"ant. Cast its bogus complaints away.
98 g_free((gchar
**)cinfo
->col_data
);
99 g_free(cinfo
->col_buf
);
100 g_free(cinfo
->col_fence
);
101 /* XXX - see above */
102 g_free((gchar
**)cinfo
->col_expr
.col_expr
);
103 g_free(cinfo
->col_expr
.col_expr_val
);
106 /* Initialize the data structures for constructing column data. */
108 col_init(column_info
*cinfo
, const struct epan_session
*epan
)
115 for (i
= 0; i
< cinfo
->num_cols
; i
++) {
116 cinfo
->col_buf
[i
][0] = '\0';
117 cinfo
->col_data
[i
] = cinfo
->col_buf
[i
];
118 cinfo
->col_fence
[i
] = 0;
119 cinfo
->col_expr
.col_expr
[i
] = "";
120 cinfo
->col_expr
.col_expr_val
[i
][0] = '\0';
122 cinfo
->writable
= TRUE
;
126 #define COL_GET_WRITABLE(cinfo) (cinfo ? cinfo->writable : FALSE)
129 col_get_writable(column_info
*cinfo
)
131 return COL_GET_WRITABLE(cinfo
);
135 col_set_writable(column_info
*cinfo
, const gboolean writable
)
138 cinfo
->writable
= writable
;
141 /* Checks to see if a particular packet information element is needed for the packet list */
142 #define CHECK_COL(cinfo, el) \
143 /* We are constructing columns, and they're writable */ \
144 (COL_GET_WRITABLE(cinfo) && \
145 /* There is at least one column in that format */ \
146 ((cinfo)->col_first[el] >= 0))
148 /* Sets the fence for a column to be at the end of the column. */
150 col_set_fence(column_info
*cinfo
, const gint el
)
154 if (!CHECK_COL(cinfo
, el
))
157 for (i
= cinfo
->col_first
[el
]; i
<= cinfo
->col_last
[el
]; i
++) {
158 if (cinfo
->fmt_matx
[i
][el
]) {
159 cinfo
->col_fence
[i
] = (int)strlen(cinfo
->col_data
[i
]);
164 /* Gets the text of a column */
166 col_get_text(column_info
*cinfo
, const gint el
)
169 const gchar
* text
= NULL
;
171 if (!(cinfo
&& (cinfo
)->col_first
[el
] >= 0)) {
175 for (i
= cinfo
->col_first
[el
]; i
<= cinfo
->col_last
[el
]; i
++) {
176 if (cinfo
->fmt_matx
[i
][el
]) {
177 text
= (cinfo
->col_data
[i
]);
184 /* Use this to clear out a column, especially if you're going to be
185 appending to it later; at least on some platforms, it's more
186 efficient than using "col_add_str()" with a null string, and
187 more efficient than "col_set_str()" with a null string if you
188 later append to it, as the later append will cause a string
191 col_clear(column_info
*cinfo
, const gint el
)
196 if (!CHECK_COL(cinfo
, el
))
199 for (i
= cinfo
->col_first
[el
]; i
<= cinfo
->col_last
[el
]; i
++) {
200 if (cinfo
->fmt_matx
[i
][el
]) {
202 * At this point, either
204 * 1) col_data[i] is equal to col_buf[i], in which case we
205 * don't have to worry about copying col_data[i] to
208 * 2) col_data[i] isn't equal to col_buf[i], in which case
209 * the only thing that's been done to the column is
210 * "col_set_str()" calls and possibly "col_set_fence()"
211 * calls, in which case the fence is either unset and
212 * at the beginning of the string or set and at the end
213 * of the string - if it's at the beginning, we're just
214 * going to clear the column, and if it's at the end,
215 * we don't do anything.
217 fence
= cinfo
->col_fence
[i
];
218 if (cinfo
->col_buf
[i
] == cinfo
->col_data
[i
] || fence
== 0) {
220 * The fence isn't at the end of the column, or the column wasn't
221 * last set with "col_set_str()", so clear the column out.
223 cinfo
->col_buf
[i
][fence
] = '\0';
224 cinfo
->col_data
[i
] = cinfo
->col_buf
[i
];
226 cinfo
->col_expr
.col_expr
[i
] = "";
227 cinfo
->col_expr
.col_expr_val
[i
][0] = '\0';
232 #define COL_CHECK_APPEND(cinfo, i, max_len) \
233 if (cinfo->col_data[i] != cinfo->col_buf[i]) { \
234 /* This was set with "col_set_str()"; copy the string they \
235 set it to into the buffer, so we can append to it. */ \
236 g_strlcpy(cinfo->col_buf[i], cinfo->col_data[i], max_len); \
237 cinfo->col_data[i] = cinfo->col_buf[i]; \
240 #define COL_CHECK_REF_TIME(fd, buf) \
241 if (fd->flags.ref_time) { \
242 g_strlcpy(buf, "*REF*", COL_MAX_LEN ); \
246 /* The same as CHECK_COL(), but without the check to see if the column is writable. */
247 #define HAVE_CUSTOM_COLS(cinfo) ((cinfo) && (cinfo)->col_first[COL_CUSTOM] >= 0)
250 have_custom_cols(column_info
*cinfo
)
252 return HAVE_CUSTOM_COLS(cinfo
);
255 /* search in edt tree custom fields */
256 void col_custom_set_edt(epan_dissect_t
*edt
, column_info
*cinfo
)
260 if (!HAVE_CUSTOM_COLS(cinfo
))
263 for (i
= cinfo
->col_first
[COL_CUSTOM
];
264 i
<= cinfo
->col_last
[COL_CUSTOM
]; i
++) {
265 if (cinfo
->fmt_matx
[i
][COL_CUSTOM
] &&
266 cinfo
->col_custom_field
[i
] &&
267 cinfo
->col_custom_field_id
[i
] != -1) {
268 cinfo
->col_data
[i
] = cinfo
->col_buf
[i
];
269 cinfo
->col_expr
.col_expr
[i
] = epan_custom_set(edt
, cinfo
->col_custom_field_id
[i
],
270 cinfo
->col_custom_occurrence
[i
],
272 cinfo
->col_expr
.col_expr_val
[i
],
279 col_custom_prime_edt(epan_dissect_t
*edt
, column_info
*cinfo
)
283 if (!HAVE_CUSTOM_COLS(cinfo
))
286 for (i
= cinfo
->col_first
[COL_CUSTOM
];
287 i
<= cinfo
->col_last
[COL_CUSTOM
]; i
++) {
289 cinfo
->col_custom_field_id
[i
] = -1;
290 if (cinfo
->fmt_matx
[i
][COL_CUSTOM
] &&
291 cinfo
->col_custom_dfilter
[i
]) {
292 epan_dissect_prime_dfilter(edt
, cinfo
->col_custom_dfilter
[i
]);
293 if (cinfo
->col_custom_field
) {
294 header_field_info
* hfinfo
= proto_registrar_get_byname(cinfo
->col_custom_field
[i
]);
295 cinfo
->col_custom_field_id
[i
] = hfinfo
? hfinfo
->id
: -1;
301 /* Appends a vararg list to a packet info string.
302 * This function's code is duplicated in col_append_sep_fstr() below because
303 * the for() loop below requires us to call va_start/va_end so intermediate
304 * functions are a problem.
307 col_append_fstr(column_info
*cinfo
, const gint el
, const gchar
*format
, ...)
313 if (!CHECK_COL(cinfo
, el
))
317 max_len
= COL_MAX_INFO_LEN
;
319 max_len
= COL_MAX_LEN
;
321 for (i
= cinfo
->col_first
[el
]; i
<= cinfo
->col_last
[el
]; i
++) {
322 if (cinfo
->fmt_matx
[i
][el
]) {
324 * First arrange that we can append, if necessary.
326 COL_CHECK_APPEND(cinfo
, i
, max_len
);
328 len
= (int) strlen(cinfo
->col_buf
[i
]);
330 va_start(ap
, format
);
331 g_vsnprintf(&cinfo
->col_buf
[i
][len
], max_len
- len
, format
, ap
);
338 /* Appends a vararg list to a packet info string.
339 * Prefixes it with the given separator if the column is not empty.
340 * Code is duplicated from col_append_fstr above().
343 col_append_sep_fstr(column_info
*cinfo
, const gint el
, const gchar
*separator
,
344 const gchar
*format
, ...)
347 int len
, max_len
, sep_len
;
350 if (!CHECK_COL(cinfo
, el
))
353 if (separator
== NULL
)
354 separator
= ", "; /* default */
356 sep_len
= (int) strlen(separator
);
359 max_len
= COL_MAX_INFO_LEN
;
361 max_len
= COL_MAX_LEN
;
363 for (i
= cinfo
->col_first
[el
]; i
<= cinfo
->col_last
[el
]; i
++) {
364 if (cinfo
->fmt_matx
[i
][el
]) {
366 * First arrange that we can append, if necessary.
368 COL_CHECK_APPEND(cinfo
, i
, max_len
);
370 len
= (int) strlen(cinfo
->col_buf
[i
]);
373 * If we have a separator, append it if the column isn't empty.
377 g_strlcat(cinfo
->col_buf
[i
], separator
, max_len
);
381 va_start(ap
, format
);
382 g_vsnprintf(&cinfo
->col_buf
[i
][len
], max_len
- len
, format
, ap
);
388 /* Prepends a vararg list to a packet info string. */
389 #define COL_BUF_MAX_LEN (((COL_MAX_INFO_LEN) > (COL_MAX_LEN)) ? \
390 (COL_MAX_INFO_LEN) : (COL_MAX_LEN))
392 col_prepend_fstr(column_info
*cinfo
, const gint el
, const gchar
*format
, ...)
396 char orig_buf
[COL_BUF_MAX_LEN
];
400 if (!CHECK_COL(cinfo
, el
))
404 max_len
= COL_MAX_INFO_LEN
;
406 max_len
= COL_MAX_LEN
;
408 for (i
= cinfo
->col_first
[el
]; i
<= cinfo
->col_last
[el
]; i
++) {
409 if (cinfo
->fmt_matx
[i
][el
]) {
410 if (cinfo
->col_data
[i
] != cinfo
->col_buf
[i
]) {
411 /* This was set with "col_set_str()"; which is effectively const */
412 orig
= cinfo
->col_data
[i
];
414 g_strlcpy(orig_buf
, cinfo
->col_buf
[i
], max_len
);
417 va_start(ap
, format
);
418 g_vsnprintf(cinfo
->col_buf
[i
], max_len
, format
, ap
);
422 * Move the fence, unless it's at the beginning of the string.
424 if (cinfo
->col_fence
[i
] > 0)
425 cinfo
->col_fence
[i
] += (int) strlen(cinfo
->col_buf
[i
]);
427 g_strlcat(cinfo
->col_buf
[i
], orig
, max_len
);
428 cinfo
->col_data
[i
] = cinfo
->col_buf
[i
];
433 col_prepend_fence_fstr(column_info
*cinfo
, const gint el
, const gchar
*format
, ...)
437 char orig_buf
[COL_BUF_MAX_LEN
];
441 if (!CHECK_COL(cinfo
, el
))
445 max_len
= COL_MAX_INFO_LEN
;
447 max_len
= COL_MAX_LEN
;
449 for (i
= cinfo
->col_first
[el
]; i
<= cinfo
->col_last
[el
]; i
++) {
450 if (cinfo
->fmt_matx
[i
][el
]) {
451 if (cinfo
->col_data
[i
] != cinfo
->col_buf
[i
]) {
452 /* This was set with "col_set_str()"; which is effectively const */
453 orig
= cinfo
->col_data
[i
];
455 g_strlcpy(orig_buf
, cinfo
->col_buf
[i
], max_len
);
458 va_start(ap
, format
);
459 g_vsnprintf(cinfo
->col_buf
[i
], max_len
, format
, ap
);
463 * Move the fence if it exists, else create a new fence at the
464 * end of the prepended data.
466 if (cinfo
->col_fence
[i
] > 0) {
467 cinfo
->col_fence
[i
] += (int) strlen(cinfo
->col_buf
[i
]);
469 cinfo
->col_fence
[i
] = (int) strlen(cinfo
->col_buf
[i
]);
471 g_strlcat(cinfo
->col_buf
[i
], orig
, max_len
);
472 cinfo
->col_data
[i
] = cinfo
->col_buf
[i
];
477 /* Use this if "str" points to something that won't stay around (and
478 must thus be copied). */
480 col_add_str(column_info
*cinfo
, const gint el
, const gchar
* str
)
486 if (!CHECK_COL(cinfo
, el
))
490 max_len
= COL_MAX_INFO_LEN
;
492 max_len
= COL_MAX_LEN
;
494 for (i
= cinfo
->col_first
[el
]; i
<= cinfo
->col_last
[el
]; i
++) {
495 if (cinfo
->fmt_matx
[i
][el
]) {
496 fence
= cinfo
->col_fence
[i
];
499 * We will append the string after the fence.
500 * First arrange that we can append, if necessary.
502 COL_CHECK_APPEND(cinfo
, i
, max_len
);
505 * There's no fence, so we can just write to the string.
507 cinfo
->col_data
[i
] = cinfo
->col_buf
[i
];
509 g_strlcpy(&cinfo
->col_buf
[i
][fence
], str
, max_len
- fence
);
514 /* Use this if "str" points to something that will stay around (and thus
515 needn't be copied). */
517 col_set_str(column_info
*cinfo
, const gint el
, const gchar
* str
)
523 DISSECTOR_ASSERT(str
);
525 /* The caller is expected to pass in something that 'will stay around' and
526 * something from the ephemeral pool certainly doesn't fit the bill. */
527 DISSECTOR_ASSERT(!ep_verify_pointer(str
));
529 if (!CHECK_COL(cinfo
, el
))
533 max_len
= COL_MAX_INFO_LEN
;
535 max_len
= COL_MAX_LEN
;
537 for (i
= cinfo
->col_first
[el
]; i
<= cinfo
->col_last
[el
]; i
++) {
538 if (cinfo
->fmt_matx
[i
][el
]) {
539 fence
= cinfo
->col_fence
[i
];
542 * We will append the string after the fence.
543 * First arrange that we can append, if necessary.
545 COL_CHECK_APPEND(cinfo
, i
, max_len
);
547 g_strlcpy(&cinfo
->col_buf
[i
][fence
], str
, max_len
- fence
);
550 * There's no fence, so we can just set the column to point
553 cinfo
->col_data
[i
] = str
;
559 /* Adds a vararg list to a packet info string. */
561 col_add_fstr(column_info
*cinfo
, const gint el
, const gchar
*format
, ...) {
567 if (!CHECK_COL(cinfo
, el
))
571 max_len
= COL_MAX_INFO_LEN
;
573 max_len
= COL_MAX_LEN
;
575 for (i
= cinfo
->col_first
[el
]; i
<= cinfo
->col_last
[el
]; i
++) {
576 if (cinfo
->fmt_matx
[i
][el
]) {
577 fence
= cinfo
->col_fence
[i
];
580 * We will append the string after the fence.
581 * First arrange that we can append, if necessary.
583 COL_CHECK_APPEND(cinfo
, i
, max_len
);
586 * There's no fence, so we can just write to the string.
588 cinfo
->col_data
[i
] = cinfo
->col_buf
[i
];
590 va_start(ap
, format
);
591 g_vsnprintf(&cinfo
->col_buf
[i
][fence
], max_len
- fence
, format
, ap
);
598 col_do_append_str(column_info
*cinfo
, const gint el
, const gchar
* separator
,
605 max_len
= COL_MAX_INFO_LEN
;
607 max_len
= COL_MAX_LEN
;
609 for (i
= cinfo
->col_first
[el
]; i
<= cinfo
->col_last
[el
]; i
++) {
610 if (cinfo
->fmt_matx
[i
][el
]) {
612 * First arrange that we can append, if necessary.
614 COL_CHECK_APPEND(cinfo
, i
, max_len
);
616 len
= cinfo
->col_buf
[i
][0];
619 * If we have a separator, append it if the column isn't empty.
621 if (separator
!= NULL
) {
623 g_strlcat(cinfo
->col_buf
[i
], separator
, max_len
);
626 g_strlcat(cinfo
->col_buf
[i
], str
, max_len
);
632 col_append_str(column_info
*cinfo
, const gint el
, const gchar
* str
)
634 if (!CHECK_COL(cinfo
, el
))
637 col_do_append_str(cinfo
, el
, NULL
, str
);
641 col_append_sep_str(column_info
*cinfo
, const gint el
, const gchar
* separator
,
644 if (!CHECK_COL(cinfo
, el
))
647 if (separator
== NULL
)
648 separator
= ", "; /* default */
650 col_do_append_str(cinfo
, el
, separator
, str
);
653 /* --------------------------------- */
655 col_has_time_fmt(column_info
*cinfo
, const gint col
)
657 return ((cinfo
->fmt_matx
[col
][COL_CLS_TIME
]) ||
658 (cinfo
->fmt_matx
[col
][COL_ABS_TIME
]) ||
659 (cinfo
->fmt_matx
[col
][COL_ABS_YMD_TIME
]) ||
660 (cinfo
->fmt_matx
[col
][COL_ABS_YDOY_TIME
]) ||
661 (cinfo
->fmt_matx
[col
][COL_UTC_TIME
]) ||
662 (cinfo
->fmt_matx
[col
][COL_UTC_YMD_TIME
]) ||
663 (cinfo
->fmt_matx
[col
][COL_UTC_YDOY_TIME
]) ||
664 (cinfo
->fmt_matx
[col
][COL_REL_TIME
]) ||
665 (cinfo
->fmt_matx
[col
][COL_DELTA_TIME
]) ||
666 (cinfo
->fmt_matx
[col
][COL_DELTA_TIME_DIS
]));
670 set_abs_ymd_time(const frame_data
*fd
, gchar
*buf
, gboolean local
)
675 if (fd
->flags
.has_ts
) {
676 then
= fd
->abs_ts
.secs
;
678 tmp
= localtime(&then
);
684 switch (timestamp_get_precision()) {
685 case TS_PREC_FIXED_SEC
:
686 case TS_PREC_AUTO_SEC
:
687 g_snprintf(buf
, COL_MAX_LEN
,"%04d-%02d-%02d %02d:%02d:%02d",
695 case TS_PREC_FIXED_DSEC
:
696 case TS_PREC_AUTO_DSEC
:
697 g_snprintf(buf
, COL_MAX_LEN
,"%04d-%02d-%02d %02d:%02d:%02d.%01d",
704 fd
->abs_ts
.nsecs
/ 100000000);
706 case TS_PREC_FIXED_CSEC
:
707 case TS_PREC_AUTO_CSEC
:
708 g_snprintf(buf
, COL_MAX_LEN
,"%04d-%02d-%02d %02d:%02d:%02d.%02d",
715 fd
->abs_ts
.nsecs
/ 10000000);
717 case TS_PREC_FIXED_MSEC
:
718 case TS_PREC_AUTO_MSEC
:
719 g_snprintf(buf
, COL_MAX_LEN
, "%04d-%02d-%02d %02d:%02d:%02d.%03d",
726 fd
->abs_ts
.nsecs
/ 1000000);
728 case TS_PREC_FIXED_USEC
:
729 case TS_PREC_AUTO_USEC
:
730 g_snprintf(buf
, COL_MAX_LEN
, "%04d-%02d-%02d %02d:%02d:%02d.%06d",
737 fd
->abs_ts
.nsecs
/ 1000);
739 case TS_PREC_FIXED_NSEC
:
740 case TS_PREC_AUTO_NSEC
:
741 g_snprintf(buf
, COL_MAX_LEN
, "%04d-%02d-%02d %02d:%02d:%02d.%09d",
751 g_assert_not_reached();
759 col_set_abs_ymd_time(const frame_data
*fd
, column_info
*cinfo
, const int col
)
761 set_abs_ymd_time(fd
, cinfo
->col_buf
[col
], TRUE
);
762 cinfo
->col_expr
.col_expr
[col
] = "frame.time";
763 g_strlcpy(cinfo
->col_expr
.col_expr_val
[col
],cinfo
->col_buf
[col
],COL_MAX_LEN
);
765 cinfo
->col_data
[col
] = cinfo
->col_buf
[col
];
769 col_set_utc_ymd_time(const frame_data
*fd
, column_info
*cinfo
, const int col
)
771 set_abs_ymd_time(fd
, cinfo
->col_buf
[col
], FALSE
);
772 cinfo
->col_expr
.col_expr
[col
] = "frame.time";
773 g_strlcpy(cinfo
->col_expr
.col_expr_val
[col
],cinfo
->col_buf
[col
],COL_MAX_LEN
);
775 cinfo
->col_data
[col
] = cinfo
->col_buf
[col
];
779 set_abs_ydoy_time(const frame_data
*fd
, gchar
*buf
, gboolean local
)
784 if (fd
->flags
.has_ts
) {
785 then
= fd
->abs_ts
.secs
;
787 tmp
= localtime(&then
);
793 switch (timestamp_get_precision()) {
794 case TS_PREC_FIXED_SEC
:
795 case TS_PREC_AUTO_SEC
:
796 g_snprintf(buf
, COL_MAX_LEN
,"%04d/%03d %02d:%02d:%02d",
803 case TS_PREC_FIXED_DSEC
:
804 case TS_PREC_AUTO_DSEC
:
805 g_snprintf(buf
, COL_MAX_LEN
,"%04d/%03d %02d:%02d:%02d.%01d",
811 fd
->abs_ts
.nsecs
/ 100000000);
813 case TS_PREC_FIXED_CSEC
:
814 case TS_PREC_AUTO_CSEC
:
815 g_snprintf(buf
, COL_MAX_LEN
,"%04d/%03d %02d:%02d:%02d.%02d",
821 fd
->abs_ts
.nsecs
/ 10000000);
823 case TS_PREC_FIXED_MSEC
:
824 case TS_PREC_AUTO_MSEC
:
825 g_snprintf(buf
, COL_MAX_LEN
, "%04d/%03d %02d:%02d:%02d.%03d",
831 fd
->abs_ts
.nsecs
/ 1000000);
833 case TS_PREC_FIXED_USEC
:
834 case TS_PREC_AUTO_USEC
:
835 g_snprintf(buf
, COL_MAX_LEN
, "%04d/%03d %02d:%02d:%02d.%06d",
841 fd
->abs_ts
.nsecs
/ 1000);
843 case TS_PREC_FIXED_NSEC
:
844 case TS_PREC_AUTO_NSEC
:
845 g_snprintf(buf
, COL_MAX_LEN
, "%04d/%03d %02d:%02d:%02d.%09d",
854 g_assert_not_reached();
862 col_set_abs_ydoy_time(const frame_data
*fd
, column_info
*cinfo
, const int col
)
864 set_abs_ydoy_time(fd
, cinfo
->col_buf
[col
], TRUE
);
865 cinfo
->col_expr
.col_expr
[col
] = "frame.time";
866 g_strlcpy(cinfo
->col_expr
.col_expr_val
[col
],cinfo
->col_buf
[col
],COL_MAX_LEN
);
868 cinfo
->col_data
[col
] = cinfo
->col_buf
[col
];
872 col_set_utc_ydoy_time(const frame_data
*fd
, column_info
*cinfo
, const int col
)
874 set_abs_ydoy_time(fd
, cinfo
->col_buf
[col
], FALSE
);
875 cinfo
->col_expr
.col_expr
[col
] = "frame.time";
876 g_strlcpy(cinfo
->col_expr
.col_expr_val
[col
],cinfo
->col_buf
[col
],COL_MAX_LEN
);
878 cinfo
->col_data
[col
] = cinfo
->col_buf
[col
];
882 set_time_seconds(const nstime_t
*ts
, gchar
*buf
)
884 switch (timestamp_get_precision()) {
885 case TS_PREC_FIXED_SEC
:
886 case TS_PREC_AUTO_SEC
:
887 display_signed_time(buf
, COL_MAX_LEN
,
888 (gint32
) ts
->secs
, ts
->nsecs
/ 1000000000, TO_STR_TIME_RES_T_SECS
);
890 case TS_PREC_FIXED_DSEC
:
891 case TS_PREC_AUTO_DSEC
:
892 display_signed_time(buf
, COL_MAX_LEN
,
893 (gint32
) ts
->secs
, ts
->nsecs
/ 100000000, TO_STR_TIME_RES_T_DSECS
);
895 case TS_PREC_FIXED_CSEC
:
896 case TS_PREC_AUTO_CSEC
:
897 display_signed_time(buf
, COL_MAX_LEN
,
898 (gint32
) ts
->secs
, ts
->nsecs
/ 10000000, TO_STR_TIME_RES_T_CSECS
);
900 case TS_PREC_FIXED_MSEC
:
901 case TS_PREC_AUTO_MSEC
:
902 display_signed_time(buf
, COL_MAX_LEN
,
903 (gint32
) ts
->secs
, ts
->nsecs
/ 1000000, TO_STR_TIME_RES_T_MSECS
);
905 case TS_PREC_FIXED_USEC
:
906 case TS_PREC_AUTO_USEC
:
907 display_signed_time(buf
, COL_MAX_LEN
,
908 (gint32
) ts
->secs
, ts
->nsecs
/ 1000, TO_STR_TIME_RES_T_USECS
);
910 case TS_PREC_FIXED_NSEC
:
911 case TS_PREC_AUTO_NSEC
:
912 display_signed_time(buf
, COL_MAX_LEN
,
913 (gint32
) ts
->secs
, ts
->nsecs
, TO_STR_TIME_RES_T_NSECS
);
916 g_assert_not_reached();
921 set_time_hour_min_sec(const nstime_t
*ts
, gchar
*buf
)
923 time_t secs
= ts
->secs
;
924 long nsecs
= (long) ts
->nsecs
;
925 gboolean negative
= FALSE
;
936 switch (timestamp_get_precision()) {
937 case TS_PREC_FIXED_SEC
:
938 case TS_PREC_AUTO_SEC
:
939 if (secs
>= (60*60)) {
940 g_snprintf(buf
, COL_MAX_LEN
, "%s%dh %2dm %2ds",
941 negative
? "- " : "",
942 (gint32
) secs
/ (60 * 60),
943 (gint32
) (secs
/ 60) % 60,
945 } else if (secs
>= 60) {
946 g_snprintf(buf
, COL_MAX_LEN
, "%s%dm %2ds",
947 negative
? "- " : "",
951 g_snprintf(buf
, COL_MAX_LEN
, "%s%ds",
952 negative
? "- " : "",
956 case TS_PREC_FIXED_DSEC
:
957 case TS_PREC_AUTO_DSEC
:
958 if (secs
>= (60*60)) {
959 g_snprintf(buf
, COL_MAX_LEN
, "%s%dh %2dm %2d.%01lds",
960 negative
? "- " : "",
961 (gint32
) secs
/ (60 * 60),
962 (gint32
) (secs
/ 60) % 60,
965 } else if (secs
>= 60) {
966 g_snprintf(buf
, COL_MAX_LEN
, "%s%dm %2d.%01lds",
967 negative
? "- " : "",
972 g_snprintf(buf
, COL_MAX_LEN
, "%s%d.%01lds",
973 negative
? "- " : "",
978 case TS_PREC_FIXED_CSEC
:
979 case TS_PREC_AUTO_CSEC
:
980 if (secs
>= (60*60)) {
981 g_snprintf(buf
, COL_MAX_LEN
, "%s%dh %2dm %2d.%02lds",
982 negative
? "- " : "",
983 (gint32
) secs
/ (60 * 60),
984 (gint32
) (secs
/ 60) % 60,
987 } else if (secs
>= 60) {
988 g_snprintf(buf
, COL_MAX_LEN
, "%s%dm %2d.%02lds",
989 negative
? "- " : "",
994 g_snprintf(buf
, COL_MAX_LEN
, "%s%d.%02lds",
995 negative
? "- " : "",
1000 case TS_PREC_FIXED_MSEC
:
1001 case TS_PREC_AUTO_MSEC
:
1002 if (secs
>= (60*60)) {
1003 g_snprintf(buf
, COL_MAX_LEN
, "%s%dh %2dm %2d.%03lds",
1004 negative
? "- " : "",
1005 (gint32
) secs
/ (60 * 60),
1006 (gint32
) (secs
/ 60) % 60,
1009 } else if (secs
>= 60) {
1010 g_snprintf(buf
, COL_MAX_LEN
, "%s%dm %2d.%03lds",
1011 negative
? "- " : "",
1016 g_snprintf(buf
, COL_MAX_LEN
, "%s%d.%03lds",
1017 negative
? "- " : "",
1022 case TS_PREC_FIXED_USEC
:
1023 case TS_PREC_AUTO_USEC
:
1024 if (secs
>= (60*60)) {
1025 g_snprintf(buf
, COL_MAX_LEN
, "%s%dh %2dm %2d.%06lds",
1026 negative
? "- " : "",
1027 (gint32
) secs
/ (60 * 60),
1028 (gint32
) (secs
/ 60) % 60,
1031 } else if (secs
>= 60) {
1032 g_snprintf(buf
, COL_MAX_LEN
, "%s%dm %2d.%06lds",
1033 negative
? "- " : "",
1038 g_snprintf(buf
, COL_MAX_LEN
, "%s%d.%06lds",
1039 negative
? "- " : "",
1044 case TS_PREC_FIXED_NSEC
:
1045 case TS_PREC_AUTO_NSEC
:
1046 if (secs
>= (60*60)) {
1047 g_snprintf(buf
, COL_MAX_LEN
, "%s%dh %2dm %2d.%09lds",
1048 negative
? "- " : "",
1049 (gint32
) secs
/ (60 * 60),
1050 (gint32
) (secs
/ 60) % 60,
1053 } else if (secs
>= 60) {
1054 g_snprintf(buf
, COL_MAX_LEN
, "%s%dm %2d.%09lds",
1055 negative
? "- " : "",
1060 g_snprintf(buf
, COL_MAX_LEN
, "%s%d.%09lds",
1061 negative
? "- " : "",
1067 g_assert_not_reached();
1072 col_set_rel_time(const frame_data
*fd
, column_info
*cinfo
, const int col
)
1074 nstime_t del_rel_ts
;
1076 if (!fd
->flags
.has_ts
) {
1077 cinfo
->col_buf
[col
][0] = '\0';
1081 frame_delta_abs_time(cinfo
->epan
, fd
, fd
->frame_ref_num
, &del_rel_ts
);
1083 switch (timestamp_get_seconds_type()) {
1084 case TS_SECONDS_DEFAULT
:
1085 set_time_seconds(&del_rel_ts
, cinfo
->col_buf
[col
]);
1086 cinfo
->col_expr
.col_expr
[col
] = "frame.time_relative";
1087 g_strlcpy(cinfo
->col_expr
.col_expr_val
[col
],cinfo
->col_buf
[col
],COL_MAX_LEN
);
1089 case TS_SECONDS_HOUR_MIN_SEC
:
1090 set_time_hour_min_sec(&del_rel_ts
, cinfo
->col_buf
[col
]);
1091 cinfo
->col_expr
.col_expr
[col
] = "frame.time_relative";
1092 set_time_seconds(&del_rel_ts
, cinfo
->col_expr
.col_expr_val
[col
]);
1095 g_assert_not_reached();
1097 cinfo
->col_data
[col
] = cinfo
->col_buf
[col
];
1101 col_set_delta_time(const frame_data
*fd
, column_info
*cinfo
, const int col
)
1103 nstime_t del_cap_ts
;
1105 frame_delta_abs_time(cinfo
->epan
, fd
, fd
->num
- 1, &del_cap_ts
);
1107 switch (timestamp_get_seconds_type()) {
1108 case TS_SECONDS_DEFAULT
:
1109 set_time_seconds(&del_cap_ts
, cinfo
->col_buf
[col
]);
1110 cinfo
->col_expr
.col_expr
[col
] = "frame.time_delta";
1111 g_strlcpy(cinfo
->col_expr
.col_expr_val
[col
],cinfo
->col_buf
[col
],COL_MAX_LEN
);
1113 case TS_SECONDS_HOUR_MIN_SEC
:
1114 set_time_hour_min_sec(&del_cap_ts
, cinfo
->col_buf
[col
]);
1115 cinfo
->col_expr
.col_expr
[col
] = "frame.time_delta";
1116 set_time_seconds(&del_cap_ts
, cinfo
->col_expr
.col_expr_val
[col
]);
1119 g_assert_not_reached();
1122 cinfo
->col_data
[col
] = cinfo
->col_buf
[col
];
1126 col_set_delta_time_dis(const frame_data
*fd
, column_info
*cinfo
, const int col
)
1128 nstime_t del_dis_ts
;
1130 if (!fd
->flags
.has_ts
) {
1131 cinfo
->col_buf
[col
][0] = '\0';
1135 frame_delta_abs_time(cinfo
->epan
, fd
, fd
->prev_dis_num
, &del_dis_ts
);
1137 switch (timestamp_get_seconds_type()) {
1138 case TS_SECONDS_DEFAULT
:
1139 set_time_seconds(&del_dis_ts
, cinfo
->col_buf
[col
]);
1140 cinfo
->col_expr
.col_expr
[col
] = "frame.time_delta_displayed";
1141 g_strlcpy(cinfo
->col_expr
.col_expr_val
[col
],cinfo
->col_buf
[col
],COL_MAX_LEN
);
1143 case TS_SECONDS_HOUR_MIN_SEC
:
1144 set_time_hour_min_sec(&del_dis_ts
, cinfo
->col_buf
[col
]);
1145 cinfo
->col_expr
.col_expr
[col
] = "frame.time_delta_displayed";
1146 set_time_seconds(&del_dis_ts
, cinfo
->col_expr
.col_expr_val
[col
]);
1149 g_assert_not_reached();
1152 cinfo
->col_data
[col
] = cinfo
->col_buf
[col
];
1156 set_abs_time(const frame_data
*fd
, gchar
*buf
, gboolean local
)
1161 if (fd
->flags
.has_ts
) {
1162 then
= fd
->abs_ts
.secs
;
1164 tmp
= localtime(&then
);
1166 tmp
= gmtime(&then
);
1170 switch (timestamp_get_precision()) {
1171 case TS_PREC_FIXED_SEC
:
1172 case TS_PREC_AUTO_SEC
:
1173 g_snprintf(buf
, COL_MAX_LEN
,"%02d:%02d:%02d",
1178 case TS_PREC_FIXED_DSEC
:
1179 case TS_PREC_AUTO_DSEC
:
1180 g_snprintf(buf
, COL_MAX_LEN
,"%02d:%02d:%02d.%01d",
1184 fd
->abs_ts
.nsecs
/ 100000000);
1186 case TS_PREC_FIXED_CSEC
:
1187 case TS_PREC_AUTO_CSEC
:
1188 g_snprintf(buf
, COL_MAX_LEN
,"%02d:%02d:%02d.%02d",
1192 fd
->abs_ts
.nsecs
/ 10000000);
1194 case TS_PREC_FIXED_MSEC
:
1195 case TS_PREC_AUTO_MSEC
:
1196 g_snprintf(buf
, COL_MAX_LEN
,"%02d:%02d:%02d.%03d",
1200 fd
->abs_ts
.nsecs
/ 1000000);
1202 case TS_PREC_FIXED_USEC
:
1203 case TS_PREC_AUTO_USEC
:
1204 g_snprintf(buf
, COL_MAX_LEN
,"%02d:%02d:%02d.%06d",
1208 fd
->abs_ts
.nsecs
/ 1000);
1210 case TS_PREC_FIXED_NSEC
:
1211 case TS_PREC_AUTO_NSEC
:
1212 g_snprintf(buf
, COL_MAX_LEN
, "%02d:%02d:%02d.%09d",
1219 g_assert_not_reached();
1228 col_set_abs_time(const frame_data
*fd
, column_info
*cinfo
, const int col
)
1230 set_abs_time(fd
, cinfo
->col_buf
[col
], TRUE
);
1231 cinfo
->col_expr
.col_expr
[col
] = "frame.time";
1232 g_strlcpy(cinfo
->col_expr
.col_expr_val
[col
],cinfo
->col_buf
[col
],COL_MAX_LEN
);
1234 cinfo
->col_data
[col
] = cinfo
->col_buf
[col
];
1238 col_set_utc_time(const frame_data
*fd
, column_info
*cinfo
, const int col
)
1240 set_abs_time(fd
, cinfo
->col_buf
[col
], FALSE
);
1241 cinfo
->col_expr
.col_expr
[col
] = "frame.time";
1242 g_strlcpy(cinfo
->col_expr
.col_expr_val
[col
],cinfo
->col_buf
[col
],COL_MAX_LEN
);
1244 cinfo
->col_data
[col
] = cinfo
->col_buf
[col
];
1248 set_epoch_time(const frame_data
*fd
, gchar
*buf
)
1250 if (!fd
->flags
.has_ts
) {
1254 switch (timestamp_get_precision()) {
1255 case TS_PREC_FIXED_SEC
:
1256 case TS_PREC_AUTO_SEC
:
1257 display_epoch_time(buf
, COL_MAX_LEN
,
1258 fd
->abs_ts
.secs
, fd
->abs_ts
.nsecs
/ 1000000000, TO_STR_TIME_RES_T_SECS
);
1260 case TS_PREC_FIXED_DSEC
:
1261 case TS_PREC_AUTO_DSEC
:
1262 display_epoch_time(buf
, COL_MAX_LEN
,
1263 fd
->abs_ts
.secs
, fd
->abs_ts
.nsecs
/ 100000000, TO_STR_TIME_RES_T_DSECS
);
1265 case TS_PREC_FIXED_CSEC
:
1266 case TS_PREC_AUTO_CSEC
:
1267 display_epoch_time(buf
, COL_MAX_LEN
,
1268 fd
->abs_ts
.secs
, fd
->abs_ts
.nsecs
/ 10000000, TO_STR_TIME_RES_T_CSECS
);
1270 case TS_PREC_FIXED_MSEC
:
1271 case TS_PREC_AUTO_MSEC
:
1272 display_epoch_time(buf
, COL_MAX_LEN
,
1273 fd
->abs_ts
.secs
, fd
->abs_ts
.nsecs
/ 1000000, TO_STR_TIME_RES_T_MSECS
);
1275 case TS_PREC_FIXED_USEC
:
1276 case TS_PREC_AUTO_USEC
:
1277 display_epoch_time(buf
, COL_MAX_LEN
,
1278 fd
->abs_ts
.secs
, fd
->abs_ts
.nsecs
/ 1000, TO_STR_TIME_RES_T_USECS
);
1280 case TS_PREC_FIXED_NSEC
:
1281 case TS_PREC_AUTO_NSEC
:
1282 display_epoch_time(buf
, COL_MAX_LEN
,
1283 fd
->abs_ts
.secs
, fd
->abs_ts
.nsecs
, TO_STR_TIME_RES_T_NSECS
);
1286 g_assert_not_reached();
1292 col_set_epoch_time(const frame_data
*fd
, column_info
*cinfo
, const int col
)
1294 if (set_epoch_time(fd
, cinfo
->col_buf
[col
])) {
1295 cinfo
->col_expr
.col_expr
[col
] = "frame.time_delta";
1296 g_strlcpy(cinfo
->col_expr
.col_expr_val
[col
],cinfo
->col_buf
[col
],COL_MAX_LEN
);
1298 cinfo
->col_data
[col
] = cinfo
->col_buf
[col
];
1302 set_fd_time(const epan_t
*epan
, frame_data
*fd
, gchar
*buf
)
1305 switch (timestamp_get_type()) {
1307 set_abs_time(fd
, buf
, TRUE
);
1310 case TS_ABSOLUTE_WITH_YMD
:
1311 set_abs_ymd_time(fd
, buf
, TRUE
);
1314 case TS_ABSOLUTE_WITH_YDOY
:
1315 set_abs_ydoy_time(fd
, buf
, TRUE
);
1319 if (fd
->flags
.has_ts
) {
1320 nstime_t del_rel_ts
;
1322 frame_delta_abs_time(epan
, fd
, fd
->frame_ref_num
, &del_rel_ts
);
1324 switch (timestamp_get_seconds_type()) {
1325 case TS_SECONDS_DEFAULT
:
1326 set_time_seconds(&del_rel_ts
, buf
);
1328 case TS_SECONDS_HOUR_MIN_SEC
:
1329 set_time_seconds(&del_rel_ts
, buf
);
1332 g_assert_not_reached();
1340 if (fd
->flags
.has_ts
) {
1341 nstime_t del_cap_ts
;
1343 frame_delta_abs_time(epan
, fd
, fd
->num
- 1, &del_cap_ts
);
1345 switch (timestamp_get_seconds_type()) {
1346 case TS_SECONDS_DEFAULT
:
1347 set_time_seconds(&del_cap_ts
, buf
);
1349 case TS_SECONDS_HOUR_MIN_SEC
:
1350 set_time_hour_min_sec(&del_cap_ts
, buf
);
1353 g_assert_not_reached();
1361 if (fd
->flags
.has_ts
) {
1362 nstime_t del_dis_ts
;
1364 frame_delta_abs_time(epan
, fd
, fd
->prev_dis_num
, &del_dis_ts
);
1366 switch (timestamp_get_seconds_type()) {
1367 case TS_SECONDS_DEFAULT
:
1368 set_time_seconds(&del_dis_ts
, buf
);
1370 case TS_SECONDS_HOUR_MIN_SEC
:
1371 set_time_hour_min_sec(&del_dis_ts
, buf
);
1374 g_assert_not_reached();
1382 set_epoch_time(fd
, buf
);
1386 set_abs_time(fd
, buf
, FALSE
);
1389 case TS_UTC_WITH_YMD
:
1390 set_abs_ymd_time(fd
, buf
, FALSE
);
1393 case TS_UTC_WITH_YDOY
:
1394 set_abs_ydoy_time(fd
, buf
, FALSE
);
1398 /* code is missing for this case, but I don't know which [jmayer20051219] */
1405 col_set_cls_time(const frame_data
*fd
, column_info
*cinfo
, const gint col
)
1407 switch (timestamp_get_type()) {
1409 col_set_abs_time(fd
, cinfo
, col
);
1412 case TS_ABSOLUTE_WITH_YMD
:
1413 col_set_abs_ymd_time(fd
, cinfo
, col
);
1416 case TS_ABSOLUTE_WITH_YDOY
:
1417 col_set_abs_ydoy_time(fd
, cinfo
, col
);
1421 col_set_rel_time(fd
, cinfo
, col
);
1425 col_set_delta_time(fd
, cinfo
, col
);
1429 col_set_delta_time_dis(fd
, cinfo
, col
);
1433 col_set_epoch_time(fd
, cinfo
, col
);
1437 col_set_utc_time(fd
, cinfo
, col
);
1440 case TS_UTC_WITH_YMD
:
1441 col_set_utc_ymd_time(fd
, cinfo
, col
);
1444 case TS_UTC_WITH_YDOY
:
1445 col_set_utc_ydoy_time(fd
, cinfo
, col
);
1449 /* code is missing for this case, but I don't know which [jmayer20051219] */
1450 g_assert_not_reached();
1455 /* Set the format of the variable time format. */
1457 col_set_fmt_time(const frame_data
*fd
, column_info
*cinfo
, const gint fmt
, const gint col
)
1459 COL_CHECK_REF_TIME(fd
, cinfo
->col_buf
[col
]);
1463 col_set_cls_time(fd
, cinfo
, col
);
1467 col_set_abs_time(fd
, cinfo
, col
);
1470 case COL_ABS_YMD_TIME
:
1471 col_set_abs_ymd_time(fd
, cinfo
, col
);
1474 case COL_ABS_YDOY_TIME
:
1475 col_set_abs_ydoy_time(fd
, cinfo
, col
);
1479 col_set_rel_time(fd
, cinfo
, col
);
1482 case COL_DELTA_TIME
:
1483 col_set_delta_time(fd
, cinfo
, col
);
1486 case COL_DELTA_TIME_DIS
:
1487 col_set_delta_time_dis(fd
, cinfo
, col
);
1491 col_set_utc_time(fd
, cinfo
, col
);
1494 case COL_UTC_YMD_TIME
:
1495 col_set_utc_ymd_time(fd
, cinfo
, col
);
1498 case COL_UTC_YDOY_TIME
:
1499 col_set_utc_ydoy_time(fd
, cinfo
, col
);
1503 g_assert_not_reached();
1508 /* --------------------------- */
1509 /* Set the given (relative) time to a column element.
1511 * Used by multiple dissectors to set the time in the column
1512 * COL_DELTA_CONV_TIME
1514 * @param cinfo the current packet row
1515 * @param el the column to use, e.g. COL_INFO
1516 * @param ts the time to set in the column
1517 * @param fieldname the fieldname to use for creating a filter (when
1518 * applying/preparing/copying as filter)
1521 col_set_time(column_info
*cinfo
, const gint el
, const nstime_t
*ts
, const char *fieldname
)
1525 if (!CHECK_COL(cinfo
, el
))
1528 /** @todo TODO: We don't respect fd->flags.ref_time (no way to access 'fd')
1529 COL_CHECK_REF_TIME(fd, buf);
1532 for (col
= cinfo
->col_first
[el
]; col
<= cinfo
->col_last
[el
]; col
++) {
1533 if (cinfo
->fmt_matx
[col
][el
]) {
1534 switch (timestamp_get_precision()) {
1535 case TS_PREC_FIXED_SEC
:
1536 case TS_PREC_AUTO_SEC
:
1537 display_signed_time(cinfo
->col_buf
[col
], COL_MAX_LEN
,
1538 (gint32
) ts
->secs
, ts
->nsecs
/ 1000000000, TO_STR_TIME_RES_T_SECS
);
1540 case TS_PREC_FIXED_DSEC
:
1541 case TS_PREC_AUTO_DSEC
:
1542 display_signed_time(cinfo
->col_buf
[col
], COL_MAX_LEN
,
1543 (gint32
) ts
->secs
, ts
->nsecs
/ 100000000, TO_STR_TIME_RES_T_DSECS
);
1545 case TS_PREC_FIXED_CSEC
:
1546 case TS_PREC_AUTO_CSEC
:
1547 display_signed_time(cinfo
->col_buf
[col
], COL_MAX_LEN
,
1548 (gint32
) ts
->secs
, ts
->nsecs
/ 10000000, TO_STR_TIME_RES_T_CSECS
);
1550 case TS_PREC_FIXED_MSEC
:
1551 case TS_PREC_AUTO_MSEC
:
1552 display_signed_time(cinfo
->col_buf
[col
], COL_MAX_LEN
,
1553 (gint32
) ts
->secs
, ts
->nsecs
/ 1000000, TO_STR_TIME_RES_T_MSECS
);
1555 case TS_PREC_FIXED_USEC
:
1556 case TS_PREC_AUTO_USEC
:
1557 display_signed_time(cinfo
->col_buf
[col
], COL_MAX_LEN
,
1558 (gint32
) ts
->secs
, ts
->nsecs
/ 1000, TO_STR_TIME_RES_T_USECS
);
1560 case TS_PREC_FIXED_NSEC
:
1561 case TS_PREC_AUTO_NSEC
:
1562 display_signed_time(cinfo
->col_buf
[col
], COL_MAX_LEN
,
1563 (gint32
) ts
->secs
, ts
->nsecs
, TO_STR_TIME_RES_T_NSECS
);
1566 g_assert_not_reached();
1568 cinfo
->col_data
[col
] = cinfo
->col_buf
[col
];
1569 cinfo
->col_expr
.col_expr
[col
] = fieldname
;
1570 g_strlcpy(cinfo
->col_expr
.col_expr_val
[col
],cinfo
->col_buf
[col
],COL_MAX_LEN
);
1576 col_set_addr(packet_info
*pinfo
, const int col
, const address
*addr
, const gboolean is_src
,
1577 const gboolean fill_col_exprs
, const gboolean res
)
1579 if (addr
->type
== AT_NONE
) {
1580 /* No address, nothing to do */
1585 pinfo
->cinfo
->col_data
[col
] = se_get_addr_name(addr
);
1587 pinfo
->cinfo
->col_data
[col
] = se_address_to_str(addr
);
1589 if (!fill_col_exprs
)
1592 switch (addr
->type
) {
1595 pinfo
->cinfo
->col_expr
.col_expr
[col
] = "ax25.src";
1597 pinfo
->cinfo
->col_expr
.col_expr
[col
] = "ax25.dst";
1598 g_strlcpy(pinfo
->cinfo
->col_expr
.col_expr_val
[col
], ax25_to_str((guint8
*)addr
->data
), COL_MAX_LEN
);
1603 pinfo
->cinfo
->col_expr
.col_expr
[col
] = "eth.src";
1605 pinfo
->cinfo
->col_expr
.col_expr
[col
] = "eth.dst";
1606 address_to_str_buf(addr
, pinfo
->cinfo
->col_expr
.col_expr_val
[col
], COL_MAX_LEN
);
1611 pinfo
->cinfo
->col_expr
.col_expr
[col
] = "ip.src";
1613 pinfo
->cinfo
->col_expr
.col_expr
[col
] = "ip.dst";
1614 ip_to_str_buf((guint8
*)addr
->data
, pinfo
->cinfo
->col_expr
.col_expr_val
[col
], COL_MAX_LEN
);
1619 pinfo
->cinfo
->col_expr
.col_expr
[col
] = "ipv6.src";
1621 pinfo
->cinfo
->col_expr
.col_expr
[col
] = "ipv6.dst";
1622 address_to_str_buf(addr
, pinfo
->cinfo
->col_expr
.col_expr_val
[col
], COL_MAX_LEN
);
1627 pinfo
->cinfo
->col_expr
.col_expr
[col
] = "ddp.src";
1629 pinfo
->cinfo
->col_expr
.col_expr
[col
] = "ddp.dst";
1630 g_strlcpy(pinfo
->cinfo
->col_expr
.col_expr_val
[col
], pinfo
->cinfo
->col_buf
[col
], COL_MAX_LEN
);
1635 pinfo
->cinfo
->col_expr
.col_expr
[col
] = "arcnet.src";
1637 pinfo
->cinfo
->col_expr
.col_expr
[col
] = "arcnet.dst";
1638 g_strlcpy(pinfo
->cinfo
->col_expr
.col_expr_val
[col
], pinfo
->cinfo
->col_buf
[col
], COL_MAX_LEN
);
1643 pinfo
->cinfo
->col_expr
.col_expr
[col
] = "uri.src";
1645 pinfo
->cinfo
->col_expr
.col_expr
[col
] = "uri.dst";
1646 address_to_str_buf(addr
, pinfo
->cinfo
->col_expr
.col_expr_val
[col
], COL_MAX_LEN
);
1653 /* Some addresses (e.g. ieee80211) use a standard format like AT_ETHER but
1654 * don't use the same hf_ value (and thus don't use the same filter string).
1655 * Such address can use the SET_ADDRESS_HF macro to pass in the specific hf_
1656 * value they use. If they did so, we overwrite the default filter string
1657 * with their specific one here. See bug #7728 for further discussion.
1658 * https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=7728 */
1659 if (addr
->hf
!= -1) {
1660 pinfo
->cinfo
->col_expr
.col_expr
[col
] = proto_registrar_get_nth(addr
->hf
)->abbrev
;
1665 /* ------------------------ */
1667 col_set_port(packet_info
*pinfo
, const int col
, const gboolean is_res
, const gboolean is_src
, const gboolean fill_col_exprs _U_
)
1672 port
= pinfo
->srcport
;
1674 port
= pinfo
->destport
;
1676 /* TODO: Use fill_col_exprs */
1678 switch (pinfo
->ptype
) {
1681 g_strlcpy(pinfo
->cinfo
->col_buf
[col
], get_sctp_port(port
), COL_MAX_LEN
);
1683 guint32_to_str_buf(port
, pinfo
->cinfo
->col_buf
[col
], COL_MAX_LEN
);
1687 guint32_to_str_buf(port
, pinfo
->cinfo
->col_expr
.col_expr_val
[col
], COL_MAX_LEN
);
1689 g_strlcpy(pinfo
->cinfo
->col_buf
[col
], get_tcp_port(port
), COL_MAX_LEN
);
1691 g_strlcpy(pinfo
->cinfo
->col_buf
[col
], pinfo
->cinfo
->col_expr
.col_expr_val
[col
], COL_MAX_LEN
);
1693 pinfo
->cinfo
->col_expr
.col_expr
[col
] = "tcp.srcport";
1695 pinfo
->cinfo
->col_expr
.col_expr
[col
] = "tcp.dstport";
1699 guint32_to_str_buf(port
, pinfo
->cinfo
->col_expr
.col_expr_val
[col
], COL_MAX_LEN
);
1701 g_strlcpy(pinfo
->cinfo
->col_buf
[col
], get_udp_port(port
), COL_MAX_LEN
);
1703 g_strlcpy(pinfo
->cinfo
->col_buf
[col
], pinfo
->cinfo
->col_expr
.col_expr_val
[col
], COL_MAX_LEN
);
1705 pinfo
->cinfo
->col_expr
.col_expr
[col
] = "udp.srcport";
1707 pinfo
->cinfo
->col_expr
.col_expr
[col
] = "udp.dstport";
1712 pinfo
->cinfo
->col_expr
.col_expr
[col
] = "ddp.src_socket";
1714 pinfo
->cinfo
->col_expr
.col_expr
[col
] = "ddp.dst_socket";
1715 guint32_to_str_buf(port
, pinfo
->cinfo
->col_expr
.col_expr_val
[col
], COL_MAX_LEN
);
1716 g_strlcpy(pinfo
->cinfo
->col_buf
[col
], pinfo
->cinfo
->col_expr
.col_expr_val
[col
], COL_MAX_LEN
);
1720 /* XXX - resolve IPX socket numbers */
1721 g_snprintf(pinfo
->cinfo
->col_buf
[col
], COL_MAX_LEN
, "0x%04x", port
);
1722 g_strlcpy(pinfo
->cinfo
->col_expr
.col_expr_val
[col
], pinfo
->cinfo
->col_buf
[col
],COL_MAX_LEN
);
1724 pinfo
->cinfo
->col_expr
.col_expr
[col
] = "ipx.src.socket";
1726 pinfo
->cinfo
->col_expr
.col_expr
[col
] = "ipx.dst.socket";
1730 /* XXX - resolve IDP socket numbers */
1731 g_snprintf(pinfo
->cinfo
->col_buf
[col
], COL_MAX_LEN
, "0x%04x", port
);
1732 g_strlcpy(pinfo
->cinfo
->col_expr
.col_expr_val
[col
], pinfo
->cinfo
->col_buf
[col
],COL_MAX_LEN
);
1734 pinfo
->cinfo
->col_expr
.col_expr
[col
] = "idp.src.socket";
1736 pinfo
->cinfo
->col_expr
.col_expr
[col
] = "idp.dst.socket";
1740 /* XXX - resolve USB endpoint numbers */
1741 g_snprintf(pinfo
->cinfo
->col_buf
[col
], COL_MAX_LEN
, "0x%08x", port
);
1742 g_strlcpy(pinfo
->cinfo
->col_expr
.col_expr_val
[col
], pinfo
->cinfo
->col_buf
[col
],COL_MAX_LEN
);
1744 pinfo
->cinfo
->col_expr
.col_expr
[col
] = "usb.src.endpoint";
1746 pinfo
->cinfo
->col_expr
.col_expr
[col
] = "usb.dst.endpoint";
1752 pinfo
->cinfo
->col_data
[col
] = pinfo
->cinfo
->col_buf
[col
];
1756 col_based_on_frame_data(column_info
*cinfo
, const gint col
)
1759 g_assert(col
< cinfo
->num_cols
);
1761 switch (cinfo
->col_fmt
[col
]) {
1765 case COL_ABS_YMD_TIME
:
1766 case COL_ABS_YDOY_TIME
:
1768 case COL_UTC_YMD_TIME
:
1769 case COL_UTC_YDOY_TIME
:
1771 case COL_DELTA_TIME
:
1772 case COL_DELTA_TIME_DIS
:
1773 case COL_PACKET_LENGTH
:
1774 case COL_CUMULATIVE_BYTES
:
1783 col_fill_in_frame_data(const frame_data
*fd
, column_info
*cinfo
, const gint col
, const gboolean fill_col_exprs
)
1785 switch (cinfo
->col_fmt
[col
]) {
1787 guint32_to_str_buf(fd
->num
, cinfo
->col_buf
[col
], COL_MAX_LEN
);
1788 cinfo
->col_data
[col
] = cinfo
->col_buf
[col
];
1793 case COL_ABS_YMD_TIME
:
1794 case COL_ABS_YDOY_TIME
:
1796 case COL_UTC_YMD_TIME
:
1797 case COL_UTC_YDOY_TIME
:
1799 case COL_DELTA_TIME
:
1800 case COL_DELTA_TIME_DIS
:
1801 /* TODO: Pass on fill_col_exprs */
1802 col_set_fmt_time(fd
, cinfo
, cinfo
->col_fmt
[col
], col
);
1805 case COL_PACKET_LENGTH
:
1806 guint32_to_str_buf(fd
->pkt_len
, cinfo
->col_buf
[col
], COL_MAX_LEN
);
1807 cinfo
->col_data
[col
] = cinfo
->col_buf
[col
];
1810 case COL_CUMULATIVE_BYTES
:
1811 guint32_to_str_buf(fd
->cum_bytes
, cinfo
->col_buf
[col
], COL_MAX_LEN
);
1812 cinfo
->col_data
[col
] = cinfo
->col_buf
[col
];
1819 if (!fill_col_exprs
)
1822 switch (cinfo
->col_fmt
[col
]) {
1824 cinfo
->col_expr
.col_expr
[col
] = "frame.number";
1825 g_strlcpy(cinfo
->col_expr
.col_expr_val
[col
], cinfo
->col_buf
[col
], COL_MAX_LEN
);
1830 case COL_ABS_YMD_TIME
:
1831 case COL_ABS_YDOY_TIME
:
1833 case COL_UTC_YMD_TIME
:
1834 case COL_UTC_YDOY_TIME
:
1836 case COL_DELTA_TIME
:
1837 case COL_DELTA_TIME_DIS
:
1838 /* Already handled above */
1841 case COL_PACKET_LENGTH
:
1842 cinfo
->col_expr
.col_expr
[col
] = "frame.len";
1843 g_strlcpy(cinfo
->col_expr
.col_expr_val
[col
], cinfo
->col_buf
[col
], COL_MAX_LEN
);
1846 case COL_CUMULATIVE_BYTES
:
1855 col_fill_in(packet_info
*pinfo
, const gboolean fill_col_exprs
, const gboolean fill_fd_colums
)
1862 for (i
= 0; i
< pinfo
->cinfo
->num_cols
; i
++) {
1863 switch (pinfo
->cinfo
->col_fmt
[i
]) {
1867 case COL_ABS_YMD_TIME
:
1868 case COL_ABS_YDOY_TIME
:
1870 case COL_UTC_YMD_TIME
:
1871 case COL_UTC_YDOY_TIME
:
1873 case COL_DELTA_TIME
:
1874 case COL_DELTA_TIME_DIS
:
1875 case COL_PACKET_LENGTH
:
1876 case COL_CUMULATIVE_BYTES
:
1878 col_fill_in_frame_data(pinfo
->fd
, pinfo
->cinfo
, i
, fill_col_exprs
);
1882 case COL_RES_SRC
: /* COL_DEF_SRC is currently just like COL_RES_SRC */
1883 col_set_addr(pinfo
, i
, &pinfo
->src
, TRUE
, fill_col_exprs
, TRUE
);
1887 col_set_addr(pinfo
, i
, &pinfo
->src
, TRUE
, fill_col_exprs
, FALSE
);
1890 case COL_DEF_DL_SRC
:
1891 case COL_RES_DL_SRC
:
1892 col_set_addr(pinfo
, i
, &pinfo
->dl_src
, TRUE
, fill_col_exprs
, TRUE
);
1895 case COL_UNRES_DL_SRC
:
1896 col_set_addr(pinfo
, i
, &pinfo
->dl_src
, TRUE
, fill_col_exprs
, FALSE
);
1899 case COL_DEF_NET_SRC
:
1900 case COL_RES_NET_SRC
:
1901 col_set_addr(pinfo
, i
, &pinfo
->net_src
, TRUE
, fill_col_exprs
, TRUE
);
1904 case COL_UNRES_NET_SRC
:
1905 col_set_addr(pinfo
, i
, &pinfo
->net_src
, TRUE
, fill_col_exprs
, FALSE
);
1909 case COL_RES_DST
: /* COL_DEF_DST is currently just like COL_RES_DST */
1910 col_set_addr(pinfo
, i
, &pinfo
->dst
, FALSE
, fill_col_exprs
, TRUE
);
1914 col_set_addr(pinfo
, i
, &pinfo
->dst
, FALSE
, fill_col_exprs
, FALSE
);
1917 case COL_DEF_DL_DST
:
1918 case COL_RES_DL_DST
:
1919 col_set_addr(pinfo
, i
, &pinfo
->dl_dst
, FALSE
, fill_col_exprs
, TRUE
);
1922 case COL_UNRES_DL_DST
:
1923 col_set_addr(pinfo
, i
, &pinfo
->dl_dst
, FALSE
, fill_col_exprs
, FALSE
);
1926 case COL_DEF_NET_DST
:
1927 case COL_RES_NET_DST
:
1928 col_set_addr(pinfo
, i
, &pinfo
->net_dst
, FALSE
, fill_col_exprs
, TRUE
);
1931 case COL_UNRES_NET_DST
:
1932 col_set_addr(pinfo
, i
, &pinfo
->net_dst
, FALSE
, fill_col_exprs
, FALSE
);
1935 case COL_DEF_SRC_PORT
:
1936 case COL_RES_SRC_PORT
: /* COL_DEF_SRC_PORT is currently just like COL_RES_SRC_PORT */
1937 col_set_port(pinfo
, i
, TRUE
, TRUE
, fill_col_exprs
);
1940 case COL_UNRES_SRC_PORT
:
1941 col_set_port(pinfo
, i
, FALSE
, TRUE
, fill_col_exprs
);
1944 case COL_DEF_DST_PORT
:
1945 case COL_RES_DST_PORT
: /* COL_DEF_DST_PORT is currently just like COL_RES_DST_PORT */
1946 col_set_port(pinfo
, i
, TRUE
, FALSE
, fill_col_exprs
);
1949 case COL_UNRES_DST_PORT
:
1950 col_set_port(pinfo
, i
, FALSE
, FALSE
, fill_col_exprs
);
1953 case NUM_COL_FMTS
: /* keep compiler happy - shouldn't get here */
1954 g_assert_not_reached();
1957 if (pinfo
->cinfo
->col_fmt
[i
] >= NUM_COL_FMTS
) {
1958 g_assert_not_reached();
1961 * Formatting handled by col_custom_set_edt() (COL_CUSTOM), expert.c
1962 * (COL_EXPERT), or individual dissectors.
1970 * Fill in columns if we got an error reading the packet.
1971 * We set most columns to "???", and set the Info column to an error
1975 col_fill_in_error(column_info
*cinfo
, frame_data
*fdata
, const gboolean fill_col_exprs
, const gboolean fill_fd_colums
)
1982 for (i
= 0; i
< cinfo
->num_cols
; i
++) {
1983 switch (cinfo
->col_fmt
[i
]) {
1987 case COL_ABS_YMD_TIME
:
1988 case COL_ABS_YDOY_TIME
:
1990 case COL_UTC_YMD_TIME
:
1991 case COL_UTC_YDOY_TIME
:
1993 case COL_DELTA_TIME
:
1994 case COL_DELTA_TIME_DIS
:
1995 case COL_PACKET_LENGTH
:
1996 case COL_CUMULATIVE_BYTES
:
1998 col_fill_in_frame_data(fdata
, cinfo
, i
, fill_col_exprs
);
2002 /* XXX - say more than this */
2003 cinfo
->col_data
[i
] = "Read error";
2006 case NUM_COL_FMTS
: /* keep compiler happy - shouldn't get here */
2007 g_assert_not_reached();
2010 if (cinfo
->col_fmt
[i
] >= NUM_COL_FMTS
) {
2011 g_assert_not_reached();
2014 * No dissection was done, and these columns are set as the
2015 * result of the dissection, so....
2017 cinfo
->col_data
[i
] = "???";
2029 * indent-tabs-mode: nil
2032 * ex: set shiftwidth=2 tabstop=8 expandtab:
2033 * :indentSize=2:tabSize=8:noTabs=true: