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(struct epan_dfilter*, 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 /* Clear the fence for a column. */
166 col_clear_fence(column_info *cinfo, const gint el)
170 if (!CHECK_COL(cinfo, el))
173 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
174 if (cinfo->fmt_matx[i][el]) {
175 cinfo->col_fence[i] = 0;
180 /* Gets the text of a column */
182 col_get_text(column_info *cinfo, const gint el)
185 const gchar* text = NULL;
187 if (!(cinfo && (cinfo)->col_first[el] >= 0)) {
191 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
192 if (cinfo->fmt_matx[i][el]) {
193 text = (cinfo->col_data[i]);
200 /* Use this to clear out a column, especially if you're going to be
201 appending to it later; at least on some platforms, it's more
202 efficient than using "col_add_str()" with a null string, and
203 more efficient than "col_set_str()" with a null string if you
204 later append to it, as the later append will cause a string
207 col_clear(column_info *cinfo, const gint el)
212 if (!CHECK_COL(cinfo, el))
215 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
216 if (cinfo->fmt_matx[i][el]) {
218 * At this point, either
220 * 1) col_data[i] is equal to col_buf[i], in which case we
221 * don't have to worry about copying col_data[i] to
224 * 2) col_data[i] isn't equal to col_buf[i], in which case
225 * the only thing that's been done to the column is
226 * "col_set_str()" calls and possibly "col_set_fence()"
227 * calls, in which case the fence is either unset and
228 * at the beginning of the string or set and at the end
229 * of the string - if it's at the beginning, we're just
230 * going to clear the column, and if it's at the end,
231 * we don't do anything.
233 fence = cinfo->col_fence[i];
234 if (cinfo->col_buf[i] == cinfo->col_data[i] || fence == 0) {
236 * The fence isn't at the end of the column, or the column wasn't
237 * last set with "col_set_str()", so clear the column out.
239 cinfo->col_buf[i][fence] = '\0';
240 cinfo->col_data[i] = cinfo->col_buf[i];
242 cinfo->col_expr.col_expr[i] = "";
243 cinfo->col_expr.col_expr_val[i][0] = '\0';
248 #define COL_CHECK_APPEND(cinfo, i, max_len) \
249 if (cinfo->col_data[i] != cinfo->col_buf[i]) { \
250 /* This was set with "col_set_str()"; copy the string they \
251 set it to into the buffer, so we can append to it. */ \
252 g_strlcpy(cinfo->col_buf[i], cinfo->col_data[i], max_len); \
253 cinfo->col_data[i] = cinfo->col_buf[i]; \
256 #define COL_CHECK_REF_TIME(fd, buf) \
257 if (fd->flags.ref_time) { \
258 g_strlcpy(buf, "*REF*", COL_MAX_LEN ); \
262 /* The same as CHECK_COL(), but without the check to see if the column is writable. */
263 #define HAVE_CUSTOM_COLS(cinfo) ((cinfo) && (cinfo)->col_first[COL_CUSTOM] >= 0)
266 have_custom_cols(column_info *cinfo)
268 return HAVE_CUSTOM_COLS(cinfo);
271 /* search in edt tree custom fields */
272 void col_custom_set_edt(epan_dissect_t *edt, column_info *cinfo)
276 if (!HAVE_CUSTOM_COLS(cinfo))
279 for (i = cinfo->col_first[COL_CUSTOM];
280 i <= cinfo->col_last[COL_CUSTOM]; i++) {
281 if (cinfo->fmt_matx[i][COL_CUSTOM] &&
282 cinfo->col_custom_field[i] &&
283 cinfo->col_custom_field_id[i] != -1) {
284 cinfo->col_data[i] = cinfo->col_buf[i];
285 cinfo->col_expr.col_expr[i] = epan_custom_set(edt, cinfo->col_custom_field_id[i],
286 cinfo->col_custom_occurrence[i],
288 cinfo->col_expr.col_expr_val[i],
295 col_custom_prime_edt(epan_dissect_t *edt, column_info *cinfo)
299 if (!HAVE_CUSTOM_COLS(cinfo))
302 for (i = cinfo->col_first[COL_CUSTOM];
303 i <= cinfo->col_last[COL_CUSTOM]; i++) {
305 cinfo->col_custom_field_id[i] = -1;
306 if (cinfo->fmt_matx[i][COL_CUSTOM] &&
307 cinfo->col_custom_dfilter[i]) {
308 epan_dissect_prime_dfilter(edt, cinfo->col_custom_dfilter[i]);
309 if (cinfo->col_custom_field) {
310 header_field_info* hfinfo = proto_registrar_get_byname(cinfo->col_custom_field[i]);
311 cinfo->col_custom_field_id[i] = hfinfo ? hfinfo->id : -1;
317 /* Appends a vararg list to a packet info string.
318 * This function's code is duplicated in col_append_sep_fstr() below because
319 * the for() loop below requires us to call va_start/va_end so intermediate
320 * functions are a problem.
323 col_append_fstr(column_info *cinfo, const gint el, const gchar *format, ...)
329 if (!CHECK_COL(cinfo, el))
333 max_len = COL_MAX_INFO_LEN;
335 max_len = COL_MAX_LEN;
337 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
338 if (cinfo->fmt_matx[i][el]) {
340 * First arrange that we can append, if necessary.
342 COL_CHECK_APPEND(cinfo, i, max_len);
344 len = (int) strlen(cinfo->col_buf[i]);
346 va_start(ap, format);
347 g_vsnprintf(&cinfo->col_buf[i][len], max_len - len, format, ap);
354 /* Appends a vararg list to a packet info string.
355 * Prefixes it with the given separator if the column is not empty.
356 * Code is duplicated from col_append_fstr above().
359 col_append_sep_fstr(column_info *cinfo, const gint el, const gchar *separator,
360 const gchar *format, ...)
363 int len, max_len, sep_len;
366 if (!CHECK_COL(cinfo, el))
369 if (separator == NULL)
370 separator = ", "; /* default */
372 sep_len = (int) strlen(separator);
375 max_len = COL_MAX_INFO_LEN;
377 max_len = COL_MAX_LEN;
379 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
380 if (cinfo->fmt_matx[i][el]) {
382 * First arrange that we can append, if necessary.
384 COL_CHECK_APPEND(cinfo, i, max_len);
386 len = (int) strlen(cinfo->col_buf[i]);
389 * If we have a separator, append it if the column isn't empty.
393 g_strlcat(cinfo->col_buf[i], separator, max_len);
397 va_start(ap, format);
398 g_vsnprintf(&cinfo->col_buf[i][len], max_len - len, format, ap);
404 /* Prepends a vararg list to a packet info string. */
405 #define COL_BUF_MAX_LEN (((COL_MAX_INFO_LEN) > (COL_MAX_LEN)) ? \
406 (COL_MAX_INFO_LEN) : (COL_MAX_LEN))
408 col_prepend_fstr(column_info *cinfo, const gint el, const gchar *format, ...)
412 char orig_buf[COL_BUF_MAX_LEN];
416 if (!CHECK_COL(cinfo, el))
420 max_len = COL_MAX_INFO_LEN;
422 max_len = COL_MAX_LEN;
424 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
425 if (cinfo->fmt_matx[i][el]) {
426 if (cinfo->col_data[i] != cinfo->col_buf[i]) {
427 /* This was set with "col_set_str()"; which is effectively const */
428 orig = cinfo->col_data[i];
430 g_strlcpy(orig_buf, cinfo->col_buf[i], max_len);
433 va_start(ap, format);
434 g_vsnprintf(cinfo->col_buf[i], max_len, format, ap);
438 * Move the fence, unless it's at the beginning of the string.
440 if (cinfo->col_fence[i] > 0)
441 cinfo->col_fence[i] += (int) strlen(cinfo->col_buf[i]);
443 g_strlcat(cinfo->col_buf[i], orig, max_len);
444 cinfo->col_data[i] = cinfo->col_buf[i];
449 col_prepend_fence_fstr(column_info *cinfo, const gint el, const gchar *format, ...)
453 char orig_buf[COL_BUF_MAX_LEN];
457 if (!CHECK_COL(cinfo, el))
461 max_len = COL_MAX_INFO_LEN;
463 max_len = COL_MAX_LEN;
465 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
466 if (cinfo->fmt_matx[i][el]) {
467 if (cinfo->col_data[i] != cinfo->col_buf[i]) {
468 /* This was set with "col_set_str()"; which is effectively const */
469 orig = cinfo->col_data[i];
471 g_strlcpy(orig_buf, cinfo->col_buf[i], max_len);
474 va_start(ap, format);
475 g_vsnprintf(cinfo->col_buf[i], max_len, format, ap);
479 * Move the fence if it exists, else create a new fence at the
480 * end of the prepended data.
482 if (cinfo->col_fence[i] > 0) {
483 cinfo->col_fence[i] += (int) strlen(cinfo->col_buf[i]);
485 cinfo->col_fence[i] = (int) strlen(cinfo->col_buf[i]);
487 g_strlcat(cinfo->col_buf[i], orig, max_len);
488 cinfo->col_data[i] = cinfo->col_buf[i];
493 /* Use this if "str" points to something that won't stay around (and
494 must thus be copied). */
496 col_add_str(column_info *cinfo, const gint el, const gchar* str)
502 if (!CHECK_COL(cinfo, el))
506 max_len = COL_MAX_INFO_LEN;
508 max_len = COL_MAX_LEN;
510 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
511 if (cinfo->fmt_matx[i][el]) {
512 fence = cinfo->col_fence[i];
515 * We will append the string after the fence.
516 * First arrange that we can append, if necessary.
518 COL_CHECK_APPEND(cinfo, i, max_len);
521 * There's no fence, so we can just write to the string.
523 cinfo->col_data[i] = cinfo->col_buf[i];
525 g_strlcpy(&cinfo->col_buf[i][fence], str, max_len - fence);
530 /* Use this if "str" points to something that will stay around (and thus
531 needn't be copied). */
533 col_set_str(column_info *cinfo, const gint el, const gchar* str)
539 DISSECTOR_ASSERT(str);
541 /* The caller is expected to pass in something that 'will stay around' and
542 * something from the ephemeral pool certainly doesn't fit the bill. */
543 DISSECTOR_ASSERT(!ep_verify_pointer(str));
545 if (!CHECK_COL(cinfo, el))
549 max_len = COL_MAX_INFO_LEN;
551 max_len = COL_MAX_LEN;
553 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
554 if (cinfo->fmt_matx[i][el]) {
555 fence = cinfo->col_fence[i];
558 * We will append the string after the fence.
559 * First arrange that we can append, if necessary.
561 COL_CHECK_APPEND(cinfo, i, max_len);
563 g_strlcpy(&cinfo->col_buf[i][fence], str, max_len - fence);
566 * There's no fence, so we can just set the column to point
569 cinfo->col_data[i] = str;
575 /* Adds a vararg list to a packet info string. */
577 col_add_fstr(column_info *cinfo, const gint el, const gchar *format, ...) {
583 if (!CHECK_COL(cinfo, el))
587 max_len = COL_MAX_INFO_LEN;
589 max_len = COL_MAX_LEN;
591 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
592 if (cinfo->fmt_matx[i][el]) {
593 fence = cinfo->col_fence[i];
596 * We will append the string after the fence.
597 * First arrange that we can append, if necessary.
599 COL_CHECK_APPEND(cinfo, i, max_len);
602 * There's no fence, so we can just write to the string.
604 cinfo->col_data[i] = cinfo->col_buf[i];
606 va_start(ap, format);
607 g_vsnprintf(&cinfo->col_buf[i][fence], max_len - fence, format, ap);
614 col_do_append_str(column_info *cinfo, const gint el, const gchar* separator,
621 max_len = COL_MAX_INFO_LEN;
623 max_len = COL_MAX_LEN;
625 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
626 if (cinfo->fmt_matx[i][el]) {
628 * First arrange that we can append, if necessary.
630 COL_CHECK_APPEND(cinfo, i, max_len);
632 len = cinfo->col_buf[i][0];
635 * If we have a separator, append it if the column isn't empty.
637 if (separator != NULL) {
639 g_strlcat(cinfo->col_buf[i], separator, max_len);
642 g_strlcat(cinfo->col_buf[i], str, max_len);
648 col_append_str(column_info *cinfo, const gint el, const gchar* str)
650 if (!CHECK_COL(cinfo, el))
653 col_do_append_str(cinfo, el, NULL, str);
657 col_append_sep_str(column_info *cinfo, const gint el, const gchar* separator,
660 if (!CHECK_COL(cinfo, el))
663 if (separator == NULL)
664 separator = ", "; /* default */
666 col_do_append_str(cinfo, el, separator, str);
669 /* --------------------------------- */
671 col_has_time_fmt(column_info *cinfo, const gint col)
673 return ((cinfo->fmt_matx[col][COL_CLS_TIME]) ||
674 (cinfo->fmt_matx[col][COL_ABS_TIME]) ||
675 (cinfo->fmt_matx[col][COL_ABS_YMD_TIME]) ||
676 (cinfo->fmt_matx[col][COL_ABS_YDOY_TIME]) ||
677 (cinfo->fmt_matx[col][COL_UTC_TIME]) ||
678 (cinfo->fmt_matx[col][COL_UTC_YMD_TIME]) ||
679 (cinfo->fmt_matx[col][COL_UTC_YDOY_TIME]) ||
680 (cinfo->fmt_matx[col][COL_REL_TIME]) ||
681 (cinfo->fmt_matx[col][COL_DELTA_TIME]) ||
682 (cinfo->fmt_matx[col][COL_DELTA_TIME_DIS]));
686 set_abs_ymd_time(const frame_data *fd, gchar *buf, gboolean local)
691 if (fd->flags.has_ts) {
692 then = fd->abs_ts.secs;
694 tmp = localtime(&then);
700 switch (timestamp_get_precision()) {
701 case TS_PREC_FIXED_SEC:
702 case TS_PREC_AUTO_SEC:
703 g_snprintf(buf, COL_MAX_LEN,"%04d-%02d-%02d %02d:%02d:%02d",
711 case TS_PREC_FIXED_DSEC:
712 case TS_PREC_AUTO_DSEC:
713 g_snprintf(buf, COL_MAX_LEN,"%04d-%02d-%02d %02d:%02d:%02d.%01d",
720 fd->abs_ts.nsecs / 100000000);
722 case TS_PREC_FIXED_CSEC:
723 case TS_PREC_AUTO_CSEC:
724 g_snprintf(buf, COL_MAX_LEN,"%04d-%02d-%02d %02d:%02d:%02d.%02d",
731 fd->abs_ts.nsecs / 10000000);
733 case TS_PREC_FIXED_MSEC:
734 case TS_PREC_AUTO_MSEC:
735 g_snprintf(buf, COL_MAX_LEN, "%04d-%02d-%02d %02d:%02d:%02d.%03d",
742 fd->abs_ts.nsecs / 1000000);
744 case TS_PREC_FIXED_USEC:
745 case TS_PREC_AUTO_USEC:
746 g_snprintf(buf, COL_MAX_LEN, "%04d-%02d-%02d %02d:%02d:%02d.%06d",
753 fd->abs_ts.nsecs / 1000);
755 case TS_PREC_FIXED_NSEC:
756 case TS_PREC_AUTO_NSEC:
757 g_snprintf(buf, COL_MAX_LEN, "%04d-%02d-%02d %02d:%02d:%02d.%09d",
767 g_assert_not_reached();
775 col_set_abs_ymd_time(const frame_data *fd, column_info *cinfo, const int col)
777 set_abs_ymd_time(fd, cinfo->col_buf[col], TRUE);
778 cinfo->col_expr.col_expr[col] = "frame.time";
779 g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->col_buf[col],COL_MAX_LEN);
781 cinfo->col_data[col] = cinfo->col_buf[col];
785 col_set_utc_ymd_time(const frame_data *fd, column_info *cinfo, const int col)
787 set_abs_ymd_time(fd, cinfo->col_buf[col], FALSE);
788 cinfo->col_expr.col_expr[col] = "frame.time";
789 g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->col_buf[col],COL_MAX_LEN);
791 cinfo->col_data[col] = cinfo->col_buf[col];
795 set_abs_ydoy_time(const frame_data *fd, gchar *buf, gboolean local)
800 if (fd->flags.has_ts) {
801 then = fd->abs_ts.secs;
803 tmp = localtime(&then);
809 switch (timestamp_get_precision()) {
810 case TS_PREC_FIXED_SEC:
811 case TS_PREC_AUTO_SEC:
812 g_snprintf(buf, COL_MAX_LEN,"%04d/%03d %02d:%02d:%02d",
819 case TS_PREC_FIXED_DSEC:
820 case TS_PREC_AUTO_DSEC:
821 g_snprintf(buf, COL_MAX_LEN,"%04d/%03d %02d:%02d:%02d.%01d",
827 fd->abs_ts.nsecs / 100000000);
829 case TS_PREC_FIXED_CSEC:
830 case TS_PREC_AUTO_CSEC:
831 g_snprintf(buf, COL_MAX_LEN,"%04d/%03d %02d:%02d:%02d.%02d",
837 fd->abs_ts.nsecs / 10000000);
839 case TS_PREC_FIXED_MSEC:
840 case TS_PREC_AUTO_MSEC:
841 g_snprintf(buf, COL_MAX_LEN, "%04d/%03d %02d:%02d:%02d.%03d",
847 fd->abs_ts.nsecs / 1000000);
849 case TS_PREC_FIXED_USEC:
850 case TS_PREC_AUTO_USEC:
851 g_snprintf(buf, COL_MAX_LEN, "%04d/%03d %02d:%02d:%02d.%06d",
857 fd->abs_ts.nsecs / 1000);
859 case TS_PREC_FIXED_NSEC:
860 case TS_PREC_AUTO_NSEC:
861 g_snprintf(buf, COL_MAX_LEN, "%04d/%03d %02d:%02d:%02d.%09d",
870 g_assert_not_reached();
878 col_set_abs_ydoy_time(const frame_data *fd, column_info *cinfo, const int col)
880 set_abs_ydoy_time(fd, cinfo->col_buf[col], TRUE);
881 cinfo->col_expr.col_expr[col] = "frame.time";
882 g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->col_buf[col],COL_MAX_LEN);
884 cinfo->col_data[col] = cinfo->col_buf[col];
888 col_set_utc_ydoy_time(const frame_data *fd, column_info *cinfo, const int col)
890 set_abs_ydoy_time(fd, cinfo->col_buf[col], FALSE);
891 cinfo->col_expr.col_expr[col] = "frame.time";
892 g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->col_buf[col],COL_MAX_LEN);
894 cinfo->col_data[col] = cinfo->col_buf[col];
898 set_time_seconds(const nstime_t *ts, gchar *buf)
900 switch (timestamp_get_precision()) {
901 case TS_PREC_FIXED_SEC:
902 case TS_PREC_AUTO_SEC:
903 display_signed_time(buf, COL_MAX_LEN,
904 (gint32) ts->secs, ts->nsecs / 1000000000, TO_STR_TIME_RES_T_SECS);
906 case TS_PREC_FIXED_DSEC:
907 case TS_PREC_AUTO_DSEC:
908 display_signed_time(buf, COL_MAX_LEN,
909 (gint32) ts->secs, ts->nsecs / 100000000, TO_STR_TIME_RES_T_DSECS);
911 case TS_PREC_FIXED_CSEC:
912 case TS_PREC_AUTO_CSEC:
913 display_signed_time(buf, COL_MAX_LEN,
914 (gint32) ts->secs, ts->nsecs / 10000000, TO_STR_TIME_RES_T_CSECS);
916 case TS_PREC_FIXED_MSEC:
917 case TS_PREC_AUTO_MSEC:
918 display_signed_time(buf, COL_MAX_LEN,
919 (gint32) ts->secs, ts->nsecs / 1000000, TO_STR_TIME_RES_T_MSECS);
921 case TS_PREC_FIXED_USEC:
922 case TS_PREC_AUTO_USEC:
923 display_signed_time(buf, COL_MAX_LEN,
924 (gint32) ts->secs, ts->nsecs / 1000, TO_STR_TIME_RES_T_USECS);
926 case TS_PREC_FIXED_NSEC:
927 case TS_PREC_AUTO_NSEC:
928 display_signed_time(buf, COL_MAX_LEN,
929 (gint32) ts->secs, ts->nsecs, TO_STR_TIME_RES_T_NSECS);
932 g_assert_not_reached();
937 set_time_hour_min_sec(const nstime_t *ts, gchar *buf)
939 time_t secs = ts->secs;
940 long nsecs = (long) ts->nsecs;
941 gboolean negative = FALSE;
952 switch (timestamp_get_precision()) {
953 case TS_PREC_FIXED_SEC:
954 case TS_PREC_AUTO_SEC:
955 if (secs >= (60*60)) {
956 g_snprintf(buf, COL_MAX_LEN, "%s%dh %2dm %2ds",
957 negative ? "- " : "",
958 (gint32) secs / (60 * 60),
959 (gint32) (secs / 60) % 60,
961 } else if (secs >= 60) {
962 g_snprintf(buf, COL_MAX_LEN, "%s%dm %2ds",
963 negative ? "- " : "",
967 g_snprintf(buf, COL_MAX_LEN, "%s%ds",
968 negative ? "- " : "",
972 case TS_PREC_FIXED_DSEC:
973 case TS_PREC_AUTO_DSEC:
974 if (secs >= (60*60)) {
975 g_snprintf(buf, COL_MAX_LEN, "%s%dh %2dm %2d.%01lds",
976 negative ? "- " : "",
977 (gint32) secs / (60 * 60),
978 (gint32) (secs / 60) % 60,
981 } else if (secs >= 60) {
982 g_snprintf(buf, COL_MAX_LEN, "%s%dm %2d.%01lds",
983 negative ? "- " : "",
988 g_snprintf(buf, COL_MAX_LEN, "%s%d.%01lds",
989 negative ? "- " : "",
994 case TS_PREC_FIXED_CSEC:
995 case TS_PREC_AUTO_CSEC:
996 if (secs >= (60*60)) {
997 g_snprintf(buf, COL_MAX_LEN, "%s%dh %2dm %2d.%02lds",
998 negative ? "- " : "",
999 (gint32) secs / (60 * 60),
1000 (gint32) (secs / 60) % 60,
1003 } else if (secs >= 60) {
1004 g_snprintf(buf, COL_MAX_LEN, "%s%dm %2d.%02lds",
1005 negative ? "- " : "",
1010 g_snprintf(buf, COL_MAX_LEN, "%s%d.%02lds",
1011 negative ? "- " : "",
1016 case TS_PREC_FIXED_MSEC:
1017 case TS_PREC_AUTO_MSEC:
1018 if (secs >= (60*60)) {
1019 g_snprintf(buf, COL_MAX_LEN, "%s%dh %2dm %2d.%03lds",
1020 negative ? "- " : "",
1021 (gint32) secs / (60 * 60),
1022 (gint32) (secs / 60) % 60,
1025 } else if (secs >= 60) {
1026 g_snprintf(buf, COL_MAX_LEN, "%s%dm %2d.%03lds",
1027 negative ? "- " : "",
1032 g_snprintf(buf, COL_MAX_LEN, "%s%d.%03lds",
1033 negative ? "- " : "",
1038 case TS_PREC_FIXED_USEC:
1039 case TS_PREC_AUTO_USEC:
1040 if (secs >= (60*60)) {
1041 g_snprintf(buf, COL_MAX_LEN, "%s%dh %2dm %2d.%06lds",
1042 negative ? "- " : "",
1043 (gint32) secs / (60 * 60),
1044 (gint32) (secs / 60) % 60,
1047 } else if (secs >= 60) {
1048 g_snprintf(buf, COL_MAX_LEN, "%s%dm %2d.%06lds",
1049 negative ? "- " : "",
1054 g_snprintf(buf, COL_MAX_LEN, "%s%d.%06lds",
1055 negative ? "- " : "",
1060 case TS_PREC_FIXED_NSEC:
1061 case TS_PREC_AUTO_NSEC:
1062 if (secs >= (60*60)) {
1063 g_snprintf(buf, COL_MAX_LEN, "%s%dh %2dm %2d.%09lds",
1064 negative ? "- " : "",
1065 (gint32) secs / (60 * 60),
1066 (gint32) (secs / 60) % 60,
1069 } else if (secs >= 60) {
1070 g_snprintf(buf, COL_MAX_LEN, "%s%dm %2d.%09lds",
1071 negative ? "- " : "",
1076 g_snprintf(buf, COL_MAX_LEN, "%s%d.%09lds",
1077 negative ? "- " : "",
1083 g_assert_not_reached();
1088 col_set_rel_time(const frame_data *fd, column_info *cinfo, const int col)
1090 nstime_t del_rel_ts;
1092 if (!fd->flags.has_ts) {
1093 cinfo->col_buf[col][0] = '\0';
1097 frame_delta_abs_time(cinfo->epan, fd, fd->frame_ref_num, &del_rel_ts);
1099 switch (timestamp_get_seconds_type()) {
1100 case TS_SECONDS_DEFAULT:
1101 set_time_seconds(&del_rel_ts, cinfo->col_buf[col]);
1102 cinfo->col_expr.col_expr[col] = "frame.time_relative";
1103 g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->col_buf[col],COL_MAX_LEN);
1105 case TS_SECONDS_HOUR_MIN_SEC:
1106 set_time_hour_min_sec(&del_rel_ts, cinfo->col_buf[col]);
1107 cinfo->col_expr.col_expr[col] = "frame.time_relative";
1108 set_time_seconds(&del_rel_ts, cinfo->col_expr.col_expr_val[col]);
1111 g_assert_not_reached();
1113 cinfo->col_data[col] = cinfo->col_buf[col];
1117 col_set_delta_time(const frame_data *fd, column_info *cinfo, const int col)
1119 nstime_t del_cap_ts;
1121 frame_delta_abs_time(cinfo->epan, fd, fd->num - 1, &del_cap_ts);
1123 switch (timestamp_get_seconds_type()) {
1124 case TS_SECONDS_DEFAULT:
1125 set_time_seconds(&del_cap_ts, cinfo->col_buf[col]);
1126 cinfo->col_expr.col_expr[col] = "frame.time_delta";
1127 g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->col_buf[col],COL_MAX_LEN);
1129 case TS_SECONDS_HOUR_MIN_SEC:
1130 set_time_hour_min_sec(&del_cap_ts, cinfo->col_buf[col]);
1131 cinfo->col_expr.col_expr[col] = "frame.time_delta";
1132 set_time_seconds(&del_cap_ts, cinfo->col_expr.col_expr_val[col]);
1135 g_assert_not_reached();
1138 cinfo->col_data[col] = cinfo->col_buf[col];
1142 col_set_delta_time_dis(const frame_data *fd, column_info *cinfo, const int col)
1144 nstime_t del_dis_ts;
1146 if (!fd->flags.has_ts) {
1147 cinfo->col_buf[col][0] = '\0';
1151 frame_delta_abs_time(cinfo->epan, fd, fd->prev_dis_num, &del_dis_ts);
1153 switch (timestamp_get_seconds_type()) {
1154 case TS_SECONDS_DEFAULT:
1155 set_time_seconds(&del_dis_ts, cinfo->col_buf[col]);
1156 cinfo->col_expr.col_expr[col] = "frame.time_delta_displayed";
1157 g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->col_buf[col],COL_MAX_LEN);
1159 case TS_SECONDS_HOUR_MIN_SEC:
1160 set_time_hour_min_sec(&del_dis_ts, cinfo->col_buf[col]);
1161 cinfo->col_expr.col_expr[col] = "frame.time_delta_displayed";
1162 set_time_seconds(&del_dis_ts, cinfo->col_expr.col_expr_val[col]);
1165 g_assert_not_reached();
1168 cinfo->col_data[col] = cinfo->col_buf[col];
1172 set_abs_time(const frame_data *fd, gchar *buf, gboolean local)
1177 if (fd->flags.has_ts) {
1178 then = fd->abs_ts.secs;
1180 tmp = localtime(&then);
1182 tmp = gmtime(&then);
1186 switch (timestamp_get_precision()) {
1187 case TS_PREC_FIXED_SEC:
1188 case TS_PREC_AUTO_SEC:
1189 g_snprintf(buf, COL_MAX_LEN,"%02d:%02d:%02d",
1194 case TS_PREC_FIXED_DSEC:
1195 case TS_PREC_AUTO_DSEC:
1196 g_snprintf(buf, COL_MAX_LEN,"%02d:%02d:%02d.%01d",
1200 fd->abs_ts.nsecs / 100000000);
1202 case TS_PREC_FIXED_CSEC:
1203 case TS_PREC_AUTO_CSEC:
1204 g_snprintf(buf, COL_MAX_LEN,"%02d:%02d:%02d.%02d",
1208 fd->abs_ts.nsecs / 10000000);
1210 case TS_PREC_FIXED_MSEC:
1211 case TS_PREC_AUTO_MSEC:
1212 g_snprintf(buf, COL_MAX_LEN,"%02d:%02d:%02d.%03d",
1216 fd->abs_ts.nsecs / 1000000);
1218 case TS_PREC_FIXED_USEC:
1219 case TS_PREC_AUTO_USEC:
1220 g_snprintf(buf, COL_MAX_LEN,"%02d:%02d:%02d.%06d",
1224 fd->abs_ts.nsecs / 1000);
1226 case TS_PREC_FIXED_NSEC:
1227 case TS_PREC_AUTO_NSEC:
1228 g_snprintf(buf, COL_MAX_LEN, "%02d:%02d:%02d.%09d",
1235 g_assert_not_reached();
1244 col_set_abs_time(const frame_data *fd, column_info *cinfo, const int col)
1246 set_abs_time(fd, cinfo->col_buf[col], TRUE);
1247 cinfo->col_expr.col_expr[col] = "frame.time";
1248 g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->col_buf[col],COL_MAX_LEN);
1250 cinfo->col_data[col] = cinfo->col_buf[col];
1254 col_set_utc_time(const frame_data *fd, column_info *cinfo, const int col)
1256 set_abs_time(fd, cinfo->col_buf[col], FALSE);
1257 cinfo->col_expr.col_expr[col] = "frame.time";
1258 g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->col_buf[col],COL_MAX_LEN);
1260 cinfo->col_data[col] = cinfo->col_buf[col];
1264 set_epoch_time(const frame_data *fd, gchar *buf)
1266 if (!fd->flags.has_ts) {
1270 switch (timestamp_get_precision()) {
1271 case TS_PREC_FIXED_SEC:
1272 case TS_PREC_AUTO_SEC:
1273 display_epoch_time(buf, COL_MAX_LEN,
1274 fd->abs_ts.secs, fd->abs_ts.nsecs / 1000000000, TO_STR_TIME_RES_T_SECS);
1276 case TS_PREC_FIXED_DSEC:
1277 case TS_PREC_AUTO_DSEC:
1278 display_epoch_time(buf, COL_MAX_LEN,
1279 fd->abs_ts.secs, fd->abs_ts.nsecs / 100000000, TO_STR_TIME_RES_T_DSECS);
1281 case TS_PREC_FIXED_CSEC:
1282 case TS_PREC_AUTO_CSEC:
1283 display_epoch_time(buf, COL_MAX_LEN,
1284 fd->abs_ts.secs, fd->abs_ts.nsecs / 10000000, TO_STR_TIME_RES_T_CSECS);
1286 case TS_PREC_FIXED_MSEC:
1287 case TS_PREC_AUTO_MSEC:
1288 display_epoch_time(buf, COL_MAX_LEN,
1289 fd->abs_ts.secs, fd->abs_ts.nsecs / 1000000, TO_STR_TIME_RES_T_MSECS);
1291 case TS_PREC_FIXED_USEC:
1292 case TS_PREC_AUTO_USEC:
1293 display_epoch_time(buf, COL_MAX_LEN,
1294 fd->abs_ts.secs, fd->abs_ts.nsecs / 1000, TO_STR_TIME_RES_T_USECS);
1296 case TS_PREC_FIXED_NSEC:
1297 case TS_PREC_AUTO_NSEC:
1298 display_epoch_time(buf, COL_MAX_LEN,
1299 fd->abs_ts.secs, fd->abs_ts.nsecs, TO_STR_TIME_RES_T_NSECS);
1302 g_assert_not_reached();
1308 col_set_epoch_time(const frame_data *fd, column_info *cinfo, const int col)
1310 if (set_epoch_time(fd, cinfo->col_buf[col])) {
1311 cinfo->col_expr.col_expr[col] = "frame.time_delta";
1312 g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->col_buf[col],COL_MAX_LEN);
1314 cinfo->col_data[col] = cinfo->col_buf[col];
1318 set_fd_time(const epan_t *epan, frame_data *fd, gchar *buf)
1321 switch (timestamp_get_type()) {
1323 set_abs_time(fd, buf, TRUE);
1326 case TS_ABSOLUTE_WITH_YMD:
1327 set_abs_ymd_time(fd, buf, TRUE);
1330 case TS_ABSOLUTE_WITH_YDOY:
1331 set_abs_ydoy_time(fd, buf, TRUE);
1335 if (fd->flags.has_ts) {
1336 nstime_t del_rel_ts;
1338 frame_delta_abs_time(epan, fd, fd->frame_ref_num, &del_rel_ts);
1340 switch (timestamp_get_seconds_type()) {
1341 case TS_SECONDS_DEFAULT:
1342 set_time_seconds(&del_rel_ts, buf);
1344 case TS_SECONDS_HOUR_MIN_SEC:
1345 set_time_seconds(&del_rel_ts, buf);
1348 g_assert_not_reached();
1356 if (fd->flags.has_ts) {
1357 nstime_t del_cap_ts;
1359 frame_delta_abs_time(epan, fd, fd->num - 1, &del_cap_ts);
1361 switch (timestamp_get_seconds_type()) {
1362 case TS_SECONDS_DEFAULT:
1363 set_time_seconds(&del_cap_ts, buf);
1365 case TS_SECONDS_HOUR_MIN_SEC:
1366 set_time_hour_min_sec(&del_cap_ts, buf);
1369 g_assert_not_reached();
1377 if (fd->flags.has_ts) {
1378 nstime_t del_dis_ts;
1380 frame_delta_abs_time(epan, fd, fd->prev_dis_num, &del_dis_ts);
1382 switch (timestamp_get_seconds_type()) {
1383 case TS_SECONDS_DEFAULT:
1384 set_time_seconds(&del_dis_ts, buf);
1386 case TS_SECONDS_HOUR_MIN_SEC:
1387 set_time_hour_min_sec(&del_dis_ts, buf);
1390 g_assert_not_reached();
1398 set_epoch_time(fd, buf);
1402 set_abs_time(fd, buf, FALSE);
1405 case TS_UTC_WITH_YMD:
1406 set_abs_ymd_time(fd, buf, FALSE);
1409 case TS_UTC_WITH_YDOY:
1410 set_abs_ydoy_time(fd, buf, FALSE);
1414 /* code is missing for this case, but I don't know which [jmayer20051219] */
1421 col_set_cls_time(const frame_data *fd, column_info *cinfo, const gint col)
1423 switch (timestamp_get_type()) {
1425 col_set_abs_time(fd, cinfo, col);
1428 case TS_ABSOLUTE_WITH_YMD:
1429 col_set_abs_ymd_time(fd, cinfo, col);
1432 case TS_ABSOLUTE_WITH_YDOY:
1433 col_set_abs_ydoy_time(fd, cinfo, col);
1437 col_set_rel_time(fd, cinfo, col);
1441 col_set_delta_time(fd, cinfo, col);
1445 col_set_delta_time_dis(fd, cinfo, col);
1449 col_set_epoch_time(fd, cinfo, col);
1453 col_set_utc_time(fd, cinfo, col);
1456 case TS_UTC_WITH_YMD:
1457 col_set_utc_ymd_time(fd, cinfo, col);
1460 case TS_UTC_WITH_YDOY:
1461 col_set_utc_ydoy_time(fd, cinfo, col);
1465 /* code is missing for this case, but I don't know which [jmayer20051219] */
1466 g_assert_not_reached();
1471 /* Set the format of the variable time format. */
1473 col_set_fmt_time(const frame_data *fd, column_info *cinfo, const gint fmt, const gint col)
1475 COL_CHECK_REF_TIME(fd, cinfo->col_buf[col]);
1479 col_set_cls_time(fd, cinfo, col);
1483 col_set_abs_time(fd, cinfo, col);
1486 case COL_ABS_YMD_TIME:
1487 col_set_abs_ymd_time(fd, cinfo, col);
1490 case COL_ABS_YDOY_TIME:
1491 col_set_abs_ydoy_time(fd, cinfo, col);
1495 col_set_rel_time(fd, cinfo, col);
1498 case COL_DELTA_TIME:
1499 col_set_delta_time(fd, cinfo, col);
1502 case COL_DELTA_TIME_DIS:
1503 col_set_delta_time_dis(fd, cinfo, col);
1507 col_set_utc_time(fd, cinfo, col);
1510 case COL_UTC_YMD_TIME:
1511 col_set_utc_ymd_time(fd, cinfo, col);
1514 case COL_UTC_YDOY_TIME:
1515 col_set_utc_ydoy_time(fd, cinfo, col);
1519 g_assert_not_reached();
1524 /* --------------------------- */
1525 /* Set the given (relative) time to a column element.
1527 * Used by multiple dissectors to set the time in the column
1528 * COL_DELTA_CONV_TIME
1530 * @param cinfo the current packet row
1531 * @param el the column to use, e.g. COL_INFO
1532 * @param ts the time to set in the column
1533 * @param fieldname the fieldname to use for creating a filter (when
1534 * applying/preparing/copying as filter)
1537 col_set_time(column_info *cinfo, const gint el, const nstime_t *ts, const char *fieldname)
1541 if (!CHECK_COL(cinfo, el))
1544 /** @todo TODO: We don't respect fd->flags.ref_time (no way to access 'fd')
1545 COL_CHECK_REF_TIME(fd, buf);
1548 for (col = cinfo->col_first[el]; col <= cinfo->col_last[el]; col++) {
1549 if (cinfo->fmt_matx[col][el]) {
1550 switch (timestamp_get_precision()) {
1551 case TS_PREC_FIXED_SEC:
1552 case TS_PREC_AUTO_SEC:
1553 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
1554 (gint32) ts->secs, ts->nsecs / 1000000000, TO_STR_TIME_RES_T_SECS);
1556 case TS_PREC_FIXED_DSEC:
1557 case TS_PREC_AUTO_DSEC:
1558 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
1559 (gint32) ts->secs, ts->nsecs / 100000000, TO_STR_TIME_RES_T_DSECS);
1561 case TS_PREC_FIXED_CSEC:
1562 case TS_PREC_AUTO_CSEC:
1563 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
1564 (gint32) ts->secs, ts->nsecs / 10000000, TO_STR_TIME_RES_T_CSECS);
1566 case TS_PREC_FIXED_MSEC:
1567 case TS_PREC_AUTO_MSEC:
1568 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
1569 (gint32) ts->secs, ts->nsecs / 1000000, TO_STR_TIME_RES_T_MSECS);
1571 case TS_PREC_FIXED_USEC:
1572 case TS_PREC_AUTO_USEC:
1573 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
1574 (gint32) ts->secs, ts->nsecs / 1000, TO_STR_TIME_RES_T_USECS);
1576 case TS_PREC_FIXED_NSEC:
1577 case TS_PREC_AUTO_NSEC:
1578 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
1579 (gint32) ts->secs, ts->nsecs, TO_STR_TIME_RES_T_NSECS);
1582 g_assert_not_reached();
1584 cinfo->col_data[col] = cinfo->col_buf[col];
1585 cinfo->col_expr.col_expr[col] = fieldname;
1586 g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->col_buf[col],COL_MAX_LEN);
1592 col_set_addr(packet_info *pinfo, const int col, const address *addr, const gboolean is_src,
1593 const gboolean fill_col_exprs, const gboolean res)
1595 if (addr->type == AT_NONE) {
1596 /* No address, nothing to do */
1601 pinfo->cinfo->col_data[col] = se_get_addr_name(addr);
1603 pinfo->cinfo->col_data[col] = se_address_to_str(addr);
1605 if (!fill_col_exprs)
1608 switch (addr->type) {
1611 pinfo->cinfo->col_expr.col_expr[col] = "ax25.src";
1613 pinfo->cinfo->col_expr.col_expr[col] = "ax25.dst";
1614 g_strlcpy(pinfo->cinfo->col_expr.col_expr_val[col], ax25_to_str((const guint8 *)addr->data), COL_MAX_LEN);
1619 pinfo->cinfo->col_expr.col_expr[col] = "eth.src";
1621 pinfo->cinfo->col_expr.col_expr[col] = "eth.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] = "ip.src";
1629 pinfo->cinfo->col_expr.col_expr[col] = "ip.dst";
1630 ip_to_str_buf((const guint8 *)addr->data, pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN);
1635 pinfo->cinfo->col_expr.col_expr[col] = "ipv6.src";
1637 pinfo->cinfo->col_expr.col_expr[col] = "ipv6.dst";
1638 address_to_str_buf(addr, pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN);
1643 pinfo->cinfo->col_expr.col_expr[col] = "ddp.src";
1645 pinfo->cinfo->col_expr.col_expr[col] = "ddp.dst";
1646 g_strlcpy(pinfo->cinfo->col_expr.col_expr_val[col], pinfo->cinfo->col_buf[col], COL_MAX_LEN);
1651 pinfo->cinfo->col_expr.col_expr[col] = "arcnet.src";
1653 pinfo->cinfo->col_expr.col_expr[col] = "arcnet.dst";
1654 g_strlcpy(pinfo->cinfo->col_expr.col_expr_val[col], pinfo->cinfo->col_buf[col], COL_MAX_LEN);
1659 pinfo->cinfo->col_expr.col_expr[col] = "uri.src";
1661 pinfo->cinfo->col_expr.col_expr[col] = "uri.dst";
1662 address_to_str_buf(addr, pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN);
1669 /* Some addresses (e.g. ieee80211) use a standard format like AT_ETHER but
1670 * don't use the same hf_ value (and thus don't use the same filter string).
1671 * Such address can use the SET_ADDRESS_HF macro to pass in the specific hf_
1672 * value they use. If they did so, we overwrite the default filter string
1673 * with their specific one here. See bug #7728 for further discussion.
1674 * https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=7728 */
1675 if (addr->hf != -1) {
1676 pinfo->cinfo->col_expr.col_expr[col] = proto_registrar_get_nth(addr->hf)->abbrev;
1681 /* ------------------------ */
1683 col_set_port(packet_info *pinfo, const int col, const gboolean is_res, const gboolean is_src, const gboolean fill_col_exprs _U_)
1688 port = pinfo->srcport;
1690 port = pinfo->destport;
1692 /* TODO: Use fill_col_exprs */
1694 switch (pinfo->ptype) {
1697 g_strlcpy(pinfo->cinfo->col_buf[col], get_sctp_port(port), COL_MAX_LEN);
1699 guint32_to_str_buf(port, pinfo->cinfo->col_buf[col], COL_MAX_LEN);
1703 guint32_to_str_buf(port, pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN);
1705 g_strlcpy(pinfo->cinfo->col_buf[col], get_tcp_port(port), COL_MAX_LEN);
1707 g_strlcpy(pinfo->cinfo->col_buf[col], pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN);
1709 pinfo->cinfo->col_expr.col_expr[col] = "tcp.srcport";
1711 pinfo->cinfo->col_expr.col_expr[col] = "tcp.dstport";
1715 guint32_to_str_buf(port, pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN);
1717 g_strlcpy(pinfo->cinfo->col_buf[col], get_udp_port(port), COL_MAX_LEN);
1719 g_strlcpy(pinfo->cinfo->col_buf[col], pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN);
1721 pinfo->cinfo->col_expr.col_expr[col] = "udp.srcport";
1723 pinfo->cinfo->col_expr.col_expr[col] = "udp.dstport";
1728 pinfo->cinfo->col_expr.col_expr[col] = "ddp.src_socket";
1730 pinfo->cinfo->col_expr.col_expr[col] = "ddp.dst_socket";
1731 guint32_to_str_buf(port, pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN);
1732 g_strlcpy(pinfo->cinfo->col_buf[col], pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN);
1736 /* XXX - resolve IPX socket numbers */
1737 g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "0x%04x", port);
1738 g_strlcpy(pinfo->cinfo->col_expr.col_expr_val[col], pinfo->cinfo->col_buf[col],COL_MAX_LEN);
1740 pinfo->cinfo->col_expr.col_expr[col] = "ipx.src.socket";
1742 pinfo->cinfo->col_expr.col_expr[col] = "ipx.dst.socket";
1746 /* XXX - resolve IDP socket numbers */
1747 g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "0x%04x", port);
1748 g_strlcpy(pinfo->cinfo->col_expr.col_expr_val[col], pinfo->cinfo->col_buf[col],COL_MAX_LEN);
1750 pinfo->cinfo->col_expr.col_expr[col] = "idp.src.socket";
1752 pinfo->cinfo->col_expr.col_expr[col] = "idp.dst.socket";
1756 /* XXX - resolve USB endpoint numbers */
1757 g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "0x%08x", port);
1758 g_strlcpy(pinfo->cinfo->col_expr.col_expr_val[col], pinfo->cinfo->col_buf[col],COL_MAX_LEN);
1760 pinfo->cinfo->col_expr.col_expr[col] = "usb.src.endpoint";
1762 pinfo->cinfo->col_expr.col_expr[col] = "usb.dst.endpoint";
1768 pinfo->cinfo->col_data[col] = pinfo->cinfo->col_buf[col];
1772 col_based_on_frame_data(column_info *cinfo, const gint col)
1775 g_assert(col < cinfo->num_cols);
1777 switch (cinfo->col_fmt[col]) {
1781 case COL_ABS_YMD_TIME:
1782 case COL_ABS_YDOY_TIME:
1784 case COL_UTC_YMD_TIME:
1785 case COL_UTC_YDOY_TIME:
1787 case COL_DELTA_TIME:
1788 case COL_DELTA_TIME_DIS:
1789 case COL_PACKET_LENGTH:
1790 case COL_CUMULATIVE_BYTES:
1799 col_fill_in_frame_data(const frame_data *fd, column_info *cinfo, const gint col, const gboolean fill_col_exprs)
1801 switch (cinfo->col_fmt[col]) {
1803 guint32_to_str_buf(fd->num, cinfo->col_buf[col], COL_MAX_LEN);
1804 cinfo->col_data[col] = cinfo->col_buf[col];
1809 case COL_ABS_YMD_TIME:
1810 case COL_ABS_YDOY_TIME:
1812 case COL_UTC_YMD_TIME:
1813 case COL_UTC_YDOY_TIME:
1815 case COL_DELTA_TIME:
1816 case COL_DELTA_TIME_DIS:
1817 /* TODO: Pass on fill_col_exprs */
1818 col_set_fmt_time(fd, cinfo, cinfo->col_fmt[col], col);
1821 case COL_PACKET_LENGTH:
1822 guint32_to_str_buf(fd->pkt_len, cinfo->col_buf[col], COL_MAX_LEN);
1823 cinfo->col_data[col] = cinfo->col_buf[col];
1826 case COL_CUMULATIVE_BYTES:
1827 guint32_to_str_buf(fd->cum_bytes, cinfo->col_buf[col], COL_MAX_LEN);
1828 cinfo->col_data[col] = cinfo->col_buf[col];
1835 if (!fill_col_exprs)
1838 switch (cinfo->col_fmt[col]) {
1840 cinfo->col_expr.col_expr[col] = "frame.number";
1841 g_strlcpy(cinfo->col_expr.col_expr_val[col], cinfo->col_buf[col], COL_MAX_LEN);
1846 case COL_ABS_YMD_TIME:
1847 case COL_ABS_YDOY_TIME:
1849 case COL_UTC_YMD_TIME:
1850 case COL_UTC_YDOY_TIME:
1852 case COL_DELTA_TIME:
1853 case COL_DELTA_TIME_DIS:
1854 /* Already handled above */
1857 case COL_PACKET_LENGTH:
1858 cinfo->col_expr.col_expr[col] = "frame.len";
1859 g_strlcpy(cinfo->col_expr.col_expr_val[col], cinfo->col_buf[col], COL_MAX_LEN);
1862 case COL_CUMULATIVE_BYTES:
1871 col_fill_in(packet_info *pinfo, const gboolean fill_col_exprs, const gboolean fill_fd_colums)
1878 for (i = 0; i < pinfo->cinfo->num_cols; i++) {
1879 if (col_based_on_frame_data(pinfo->cinfo, i)) {
1881 col_fill_in_frame_data(pinfo->fd, pinfo->cinfo, i, fill_col_exprs);
1883 switch (pinfo->cinfo->col_fmt[i]) {
1885 case COL_RES_SRC: /* COL_DEF_SRC is currently just like COL_RES_SRC */
1886 col_set_addr(pinfo, i, &pinfo->src, TRUE, fill_col_exprs, TRUE);
1890 col_set_addr(pinfo, i, &pinfo->src, TRUE, fill_col_exprs, FALSE);
1893 case COL_DEF_DL_SRC:
1894 case COL_RES_DL_SRC:
1895 col_set_addr(pinfo, i, &pinfo->dl_src, TRUE, fill_col_exprs, TRUE);
1898 case COL_UNRES_DL_SRC:
1899 col_set_addr(pinfo, i, &pinfo->dl_src, TRUE, fill_col_exprs, FALSE);
1902 case COL_DEF_NET_SRC:
1903 case COL_RES_NET_SRC:
1904 col_set_addr(pinfo, i, &pinfo->net_src, TRUE, fill_col_exprs, TRUE);
1907 case COL_UNRES_NET_SRC:
1908 col_set_addr(pinfo, i, &pinfo->net_src, TRUE, fill_col_exprs, FALSE);
1912 case COL_RES_DST: /* COL_DEF_DST is currently just like COL_RES_DST */
1913 col_set_addr(pinfo, i, &pinfo->dst, FALSE, fill_col_exprs, TRUE);
1917 col_set_addr(pinfo, i, &pinfo->dst, FALSE, fill_col_exprs, FALSE);
1920 case COL_DEF_DL_DST:
1921 case COL_RES_DL_DST:
1922 col_set_addr(pinfo, i, &pinfo->dl_dst, FALSE, fill_col_exprs, TRUE);
1925 case COL_UNRES_DL_DST:
1926 col_set_addr(pinfo, i, &pinfo->dl_dst, FALSE, fill_col_exprs, FALSE);
1929 case COL_DEF_NET_DST:
1930 case COL_RES_NET_DST:
1931 col_set_addr(pinfo, i, &pinfo->net_dst, FALSE, fill_col_exprs, TRUE);
1934 case COL_UNRES_NET_DST:
1935 col_set_addr(pinfo, i, &pinfo->net_dst, FALSE, fill_col_exprs, FALSE);
1938 case COL_DEF_SRC_PORT:
1939 case COL_RES_SRC_PORT: /* COL_DEF_SRC_PORT is currently just like COL_RES_SRC_PORT */
1940 col_set_port(pinfo, i, TRUE, TRUE, fill_col_exprs);
1943 case COL_UNRES_SRC_PORT:
1944 col_set_port(pinfo, i, FALSE, TRUE, fill_col_exprs);
1947 case COL_DEF_DST_PORT:
1948 case COL_RES_DST_PORT: /* COL_DEF_DST_PORT is currently just like COL_RES_DST_PORT */
1949 col_set_port(pinfo, i, TRUE, FALSE, fill_col_exprs);
1952 case COL_UNRES_DST_PORT:
1953 col_set_port(pinfo, i, FALSE, FALSE, fill_col_exprs);
1956 case NUM_COL_FMTS: /* keep compiler happy - shouldn't get here */
1957 g_assert_not_reached();
1960 if (pinfo->cinfo->col_fmt[i] >= NUM_COL_FMTS) {
1961 g_assert_not_reached();
1964 * Formatting handled by col_custom_set_edt() (COL_CUSTOM), expert.c
1965 * (COL_EXPERT), or individual dissectors.
1974 * Fill in columns if we got an error reading the packet.
1975 * We set most columns to "???", fill in columns that don't need data read
1976 * from the file, and set the Info column to an error message.
1979 col_fill_in_error(column_info *cinfo, frame_data *fdata, const gboolean fill_col_exprs, const gboolean fill_fd_colums)
1986 for (i = 0; i < cinfo->num_cols; i++) {
1987 if (col_based_on_frame_data(cinfo, i)) {
1989 col_fill_in_frame_data(fdata, cinfo, i, fill_col_exprs);
1990 } else if (cinfo->col_fmt[i] == COL_INFO) {
1991 /* XXX - say more than this */
1992 cinfo->col_data[i] = "Read error";
1994 if (cinfo->col_fmt[i] >= NUM_COL_FMTS) {
1995 g_assert_not_reached();
1998 * No dissection was done, and these columns are set as the
1999 * result of the dissection, so....
2001 cinfo->col_data[i] = "???";
2013 * indent-tabs-mode: nil
2016 * ex: set shiftwidth=2 tabstop=8 expandtab:
2017 * :indentSize=2:tabSize=8:noTabs=true: