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_DATE_TIME]) ||
660 (cinfo->fmt_matx[col][COL_UTC_TIME]) ||
661 (cinfo->fmt_matx[col][COL_UTC_DATE_TIME]) ||
662 (cinfo->fmt_matx[col][COL_REL_TIME]) ||
663 (cinfo->fmt_matx[col][COL_DELTA_TIME]) ||
664 (cinfo->fmt_matx[col][COL_DELTA_TIME_DIS]));
668 set_abs_date_time(const frame_data *fd, gchar *buf, gboolean local)
673 if (fd->flags.has_ts) {
674 then = fd->abs_ts.secs;
676 tmp = localtime(&then);
682 switch (timestamp_get_precision()) {
683 case TS_PREC_FIXED_SEC:
684 case TS_PREC_AUTO_SEC:
685 g_snprintf(buf, COL_MAX_LEN,"%04d-%02d-%02d %02d:%02d:%02d",
693 case TS_PREC_FIXED_DSEC:
694 case TS_PREC_AUTO_DSEC:
695 g_snprintf(buf, COL_MAX_LEN,"%04d-%02d-%02d %02d:%02d:%02d.%01d",
702 fd->abs_ts.nsecs / 100000000);
704 case TS_PREC_FIXED_CSEC:
705 case TS_PREC_AUTO_CSEC:
706 g_snprintf(buf, COL_MAX_LEN,"%04d-%02d-%02d %02d:%02d:%02d.%02d",
713 fd->abs_ts.nsecs / 10000000);
715 case TS_PREC_FIXED_MSEC:
716 case TS_PREC_AUTO_MSEC:
717 g_snprintf(buf, COL_MAX_LEN, "%04d-%02d-%02d %02d:%02d:%02d.%03d",
724 fd->abs_ts.nsecs / 1000000);
726 case TS_PREC_FIXED_USEC:
727 case TS_PREC_AUTO_USEC:
728 g_snprintf(buf, COL_MAX_LEN, "%04d-%02d-%02d %02d:%02d:%02d.%06d",
735 fd->abs_ts.nsecs / 1000);
737 case TS_PREC_FIXED_NSEC:
738 case TS_PREC_AUTO_NSEC:
739 g_snprintf(buf, COL_MAX_LEN, "%04d-%02d-%02d %02d:%02d:%02d.%09d",
749 g_assert_not_reached();
757 col_set_abs_date_time(const frame_data *fd, column_info *cinfo, const int col)
759 set_abs_date_time(fd, cinfo->col_buf[col], TRUE);
760 cinfo->col_expr.col_expr[col] = "frame.time";
761 g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->col_buf[col],COL_MAX_LEN);
763 cinfo->col_data[col] = cinfo->col_buf[col];
767 col_set_utc_date_time(const frame_data *fd, column_info *cinfo, const int col)
769 set_abs_date_time(fd, cinfo->col_buf[col], FALSE);
770 cinfo->col_expr.col_expr[col] = "frame.time";
771 g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->col_buf[col],COL_MAX_LEN);
773 cinfo->col_data[col] = cinfo->col_buf[col];
777 set_time_seconds(const nstime_t *ts, gchar *buf)
779 switch (timestamp_get_precision()) {
780 case TS_PREC_FIXED_SEC:
781 case TS_PREC_AUTO_SEC:
782 display_signed_time(buf, COL_MAX_LEN,
783 (gint32) ts->secs, ts->nsecs / 1000000000, TO_STR_TIME_RES_T_SECS);
785 case TS_PREC_FIXED_DSEC:
786 case TS_PREC_AUTO_DSEC:
787 display_signed_time(buf, COL_MAX_LEN,
788 (gint32) ts->secs, ts->nsecs / 100000000, TO_STR_TIME_RES_T_DSECS);
790 case TS_PREC_FIXED_CSEC:
791 case TS_PREC_AUTO_CSEC:
792 display_signed_time(buf, COL_MAX_LEN,
793 (gint32) ts->secs, ts->nsecs / 10000000, TO_STR_TIME_RES_T_CSECS);
795 case TS_PREC_FIXED_MSEC:
796 case TS_PREC_AUTO_MSEC:
797 display_signed_time(buf, COL_MAX_LEN,
798 (gint32) ts->secs, ts->nsecs / 1000000, TO_STR_TIME_RES_T_MSECS);
800 case TS_PREC_FIXED_USEC:
801 case TS_PREC_AUTO_USEC:
802 display_signed_time(buf, COL_MAX_LEN,
803 (gint32) ts->secs, ts->nsecs / 1000, TO_STR_TIME_RES_T_USECS);
805 case TS_PREC_FIXED_NSEC:
806 case TS_PREC_AUTO_NSEC:
807 display_signed_time(buf, COL_MAX_LEN,
808 (gint32) ts->secs, ts->nsecs, TO_STR_TIME_RES_T_NSECS);
811 g_assert_not_reached();
816 set_time_hour_min_sec(const nstime_t *ts, gchar *buf)
818 time_t secs = ts->secs;
819 long nsecs = (long) ts->nsecs;
820 gboolean negative = FALSE;
831 switch (timestamp_get_precision()) {
832 case TS_PREC_FIXED_SEC:
833 case TS_PREC_AUTO_SEC:
834 if (secs >= (60*60)) {
835 g_snprintf(buf, COL_MAX_LEN, "%s%dh %2dm %2ds",
836 negative ? "- " : "",
837 (gint32) secs / (60 * 60),
838 (gint32) (secs / 60) % 60,
840 } else if (secs >= 60) {
841 g_snprintf(buf, COL_MAX_LEN, "%s%dm %2ds",
842 negative ? "- " : "",
846 g_snprintf(buf, COL_MAX_LEN, "%s%ds",
847 negative ? "- " : "",
851 case TS_PREC_FIXED_DSEC:
852 case TS_PREC_AUTO_DSEC:
853 if (secs >= (60*60)) {
854 g_snprintf(buf, COL_MAX_LEN, "%s%dh %2dm %2d.%01lds",
855 negative ? "- " : "",
856 (gint32) secs / (60 * 60),
857 (gint32) (secs / 60) % 60,
860 } else if (secs >= 60) {
861 g_snprintf(buf, COL_MAX_LEN, "%s%dm %2d.%01lds",
862 negative ? "- " : "",
867 g_snprintf(buf, COL_MAX_LEN, "%s%d.%01lds",
868 negative ? "- " : "",
873 case TS_PREC_FIXED_CSEC:
874 case TS_PREC_AUTO_CSEC:
875 if (secs >= (60*60)) {
876 g_snprintf(buf, COL_MAX_LEN, "%s%dh %2dm %2d.%02lds",
877 negative ? "- " : "",
878 (gint32) secs / (60 * 60),
879 (gint32) (secs / 60) % 60,
882 } else if (secs >= 60) {
883 g_snprintf(buf, COL_MAX_LEN, "%s%dm %2d.%02lds",
884 negative ? "- " : "",
889 g_snprintf(buf, COL_MAX_LEN, "%s%d.%02lds",
890 negative ? "- " : "",
895 case TS_PREC_FIXED_MSEC:
896 case TS_PREC_AUTO_MSEC:
897 if (secs >= (60*60)) {
898 g_snprintf(buf, COL_MAX_LEN, "%s%dh %2dm %2d.%03lds",
899 negative ? "- " : "",
900 (gint32) secs / (60 * 60),
901 (gint32) (secs / 60) % 60,
904 } else if (secs >= 60) {
905 g_snprintf(buf, COL_MAX_LEN, "%s%dm %2d.%03lds",
906 negative ? "- " : "",
911 g_snprintf(buf, COL_MAX_LEN, "%s%d.%03lds",
912 negative ? "- " : "",
917 case TS_PREC_FIXED_USEC:
918 case TS_PREC_AUTO_USEC:
919 if (secs >= (60*60)) {
920 g_snprintf(buf, COL_MAX_LEN, "%s%dh %2dm %2d.%06lds",
921 negative ? "- " : "",
922 (gint32) secs / (60 * 60),
923 (gint32) (secs / 60) % 60,
926 } else if (secs >= 60) {
927 g_snprintf(buf, COL_MAX_LEN, "%s%dm %2d.%06lds",
928 negative ? "- " : "",
933 g_snprintf(buf, COL_MAX_LEN, "%s%d.%06lds",
934 negative ? "- " : "",
939 case TS_PREC_FIXED_NSEC:
940 case TS_PREC_AUTO_NSEC:
941 if (secs >= (60*60)) {
942 g_snprintf(buf, COL_MAX_LEN, "%s%dh %2dm %2d.%09lds",
943 negative ? "- " : "",
944 (gint32) secs / (60 * 60),
945 (gint32) (secs / 60) % 60,
948 } else if (secs >= 60) {
949 g_snprintf(buf, COL_MAX_LEN, "%s%dm %2d.%09lds",
950 negative ? "- " : "",
955 g_snprintf(buf, COL_MAX_LEN, "%s%d.%09lds",
956 negative ? "- " : "",
962 g_assert_not_reached();
967 col_set_rel_time(const frame_data *fd, column_info *cinfo, const int col)
971 if (!fd->flags.has_ts) {
972 cinfo->col_buf[col][0] = '\0';
976 frame_delta_abs_time(cinfo->epan, fd, fd->frame_ref_num, &del_rel_ts);
978 switch (timestamp_get_seconds_type()) {
979 case TS_SECONDS_DEFAULT:
980 set_time_seconds(&del_rel_ts, cinfo->col_buf[col]);
981 cinfo->col_expr.col_expr[col] = "frame.time_relative";
982 g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->col_buf[col],COL_MAX_LEN);
984 case TS_SECONDS_HOUR_MIN_SEC:
985 set_time_hour_min_sec(&del_rel_ts, cinfo->col_buf[col]);
986 cinfo->col_expr.col_expr[col] = "frame.time_relative";
987 set_time_seconds(&del_rel_ts, cinfo->col_expr.col_expr_val[col]);
990 g_assert_not_reached();
992 cinfo->col_data[col] = cinfo->col_buf[col];
996 col_set_delta_time(const frame_data *fd, column_info *cinfo, const int col)
1000 frame_delta_abs_time(cinfo->epan, fd, fd->num - 1, &del_cap_ts);
1002 switch (timestamp_get_seconds_type()) {
1003 case TS_SECONDS_DEFAULT:
1004 set_time_seconds(&del_cap_ts, cinfo->col_buf[col]);
1005 cinfo->col_expr.col_expr[col] = "frame.time_delta";
1006 g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->col_buf[col],COL_MAX_LEN);
1008 case TS_SECONDS_HOUR_MIN_SEC:
1009 set_time_hour_min_sec(&del_cap_ts, cinfo->col_buf[col]);
1010 cinfo->col_expr.col_expr[col] = "frame.time_delta";
1011 set_time_seconds(&del_cap_ts, cinfo->col_expr.col_expr_val[col]);
1014 g_assert_not_reached();
1017 cinfo->col_data[col] = cinfo->col_buf[col];
1021 col_set_delta_time_dis(const frame_data *fd, column_info *cinfo, const int col)
1023 nstime_t del_dis_ts;
1025 if (!fd->flags.has_ts) {
1026 cinfo->col_buf[col][0] = '\0';
1030 frame_delta_abs_time(cinfo->epan, fd, fd->prev_dis_num, &del_dis_ts);
1032 switch (timestamp_get_seconds_type()) {
1033 case TS_SECONDS_DEFAULT:
1034 set_time_seconds(&del_dis_ts, cinfo->col_buf[col]);
1035 cinfo->col_expr.col_expr[col] = "frame.time_delta_displayed";
1036 g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->col_buf[col],COL_MAX_LEN);
1038 case TS_SECONDS_HOUR_MIN_SEC:
1039 set_time_hour_min_sec(&del_dis_ts, cinfo->col_buf[col]);
1040 cinfo->col_expr.col_expr[col] = "frame.time_delta_displayed";
1041 set_time_seconds(&del_dis_ts, cinfo->col_expr.col_expr_val[col]);
1044 g_assert_not_reached();
1047 cinfo->col_data[col] = cinfo->col_buf[col];
1051 set_abs_time(const frame_data *fd, gchar *buf, gboolean local)
1056 if (fd->flags.has_ts) {
1057 then = fd->abs_ts.secs;
1059 tmp = localtime(&then);
1061 tmp = gmtime(&then);
1065 switch (timestamp_get_precision()) {
1066 case TS_PREC_FIXED_SEC:
1067 case TS_PREC_AUTO_SEC:
1068 g_snprintf(buf, COL_MAX_LEN,"%02d:%02d:%02d",
1073 case TS_PREC_FIXED_DSEC:
1074 case TS_PREC_AUTO_DSEC:
1075 g_snprintf(buf, COL_MAX_LEN,"%02d:%02d:%02d.%01d",
1079 fd->abs_ts.nsecs / 100000000);
1081 case TS_PREC_FIXED_CSEC:
1082 case TS_PREC_AUTO_CSEC:
1083 g_snprintf(buf, COL_MAX_LEN,"%02d:%02d:%02d.%02d",
1087 fd->abs_ts.nsecs / 10000000);
1089 case TS_PREC_FIXED_MSEC:
1090 case TS_PREC_AUTO_MSEC:
1091 g_snprintf(buf, COL_MAX_LEN,"%02d:%02d:%02d.%03d",
1095 fd->abs_ts.nsecs / 1000000);
1097 case TS_PREC_FIXED_USEC:
1098 case TS_PREC_AUTO_USEC:
1099 g_snprintf(buf, COL_MAX_LEN,"%02d:%02d:%02d.%06d",
1103 fd->abs_ts.nsecs / 1000);
1105 case TS_PREC_FIXED_NSEC:
1106 case TS_PREC_AUTO_NSEC:
1107 g_snprintf(buf, COL_MAX_LEN, "%02d:%02d:%02d.%09d",
1114 g_assert_not_reached();
1123 col_set_abs_time(const frame_data *fd, column_info *cinfo, const int col)
1125 set_abs_time(fd, cinfo->col_buf[col], TRUE);
1126 cinfo->col_expr.col_expr[col] = "frame.time";
1127 g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->col_buf[col],COL_MAX_LEN);
1129 cinfo->col_data[col] = cinfo->col_buf[col];
1133 col_set_utc_time(const frame_data *fd, column_info *cinfo, const int col)
1135 set_abs_time(fd, cinfo->col_buf[col], FALSE);
1136 cinfo->col_expr.col_expr[col] = "frame.time";
1137 g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->col_buf[col],COL_MAX_LEN);
1139 cinfo->col_data[col] = cinfo->col_buf[col];
1143 set_epoch_time(const frame_data *fd, gchar *buf)
1145 if (!fd->flags.has_ts) {
1149 switch (timestamp_get_precision()) {
1150 case TS_PREC_FIXED_SEC:
1151 case TS_PREC_AUTO_SEC:
1152 display_epoch_time(buf, COL_MAX_LEN,
1153 fd->abs_ts.secs, fd->abs_ts.nsecs / 1000000000, TO_STR_TIME_RES_T_SECS);
1155 case TS_PREC_FIXED_DSEC:
1156 case TS_PREC_AUTO_DSEC:
1157 display_epoch_time(buf, COL_MAX_LEN,
1158 fd->abs_ts.secs, fd->abs_ts.nsecs / 100000000, TO_STR_TIME_RES_T_DSECS);
1160 case TS_PREC_FIXED_CSEC:
1161 case TS_PREC_AUTO_CSEC:
1162 display_epoch_time(buf, COL_MAX_LEN,
1163 fd->abs_ts.secs, fd->abs_ts.nsecs / 10000000, TO_STR_TIME_RES_T_CSECS);
1165 case TS_PREC_FIXED_MSEC:
1166 case TS_PREC_AUTO_MSEC:
1167 display_epoch_time(buf, COL_MAX_LEN,
1168 fd->abs_ts.secs, fd->abs_ts.nsecs / 1000000, TO_STR_TIME_RES_T_MSECS);
1170 case TS_PREC_FIXED_USEC:
1171 case TS_PREC_AUTO_USEC:
1172 display_epoch_time(buf, COL_MAX_LEN,
1173 fd->abs_ts.secs, fd->abs_ts.nsecs / 1000, TO_STR_TIME_RES_T_USECS);
1175 case TS_PREC_FIXED_NSEC:
1176 case TS_PREC_AUTO_NSEC:
1177 display_epoch_time(buf, COL_MAX_LEN,
1178 fd->abs_ts.secs, fd->abs_ts.nsecs, TO_STR_TIME_RES_T_NSECS);
1181 g_assert_not_reached();
1187 col_set_epoch_time(const frame_data *fd, column_info *cinfo, const int col)
1189 if (set_epoch_time(fd, cinfo->col_buf[col])) {
1190 cinfo->col_expr.col_expr[col] = "frame.time_delta";
1191 g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->col_buf[col],COL_MAX_LEN);
1193 cinfo->col_data[col] = cinfo->col_buf[col];
1197 set_fd_time(const epan_t *epan, frame_data *fd, gchar *buf)
1200 switch (timestamp_get_type()) {
1202 set_abs_time(fd, buf, TRUE);
1205 case TS_ABSOLUTE_WITH_DATE:
1206 set_abs_date_time(fd, buf, TRUE);
1210 if (fd->flags.has_ts) {
1211 nstime_t del_rel_ts;
1213 frame_delta_abs_time(epan, fd, fd->frame_ref_num, &del_rel_ts);
1215 switch (timestamp_get_seconds_type()) {
1216 case TS_SECONDS_DEFAULT:
1217 set_time_seconds(&del_rel_ts, buf);
1219 case TS_SECONDS_HOUR_MIN_SEC:
1220 set_time_seconds(&del_rel_ts, buf);
1223 g_assert_not_reached();
1231 if (fd->flags.has_ts) {
1232 nstime_t del_cap_ts;
1234 frame_delta_abs_time(epan, fd, fd->num - 1, &del_cap_ts);
1236 switch (timestamp_get_seconds_type()) {
1237 case TS_SECONDS_DEFAULT:
1238 set_time_seconds(&del_cap_ts, buf);
1240 case TS_SECONDS_HOUR_MIN_SEC:
1241 set_time_hour_min_sec(&del_cap_ts, buf);
1244 g_assert_not_reached();
1252 if (fd->flags.has_ts) {
1253 nstime_t del_dis_ts;
1255 frame_delta_abs_time(epan, fd, fd->prev_dis_num, &del_dis_ts);
1257 switch (timestamp_get_seconds_type()) {
1258 case TS_SECONDS_DEFAULT:
1259 set_time_seconds(&del_dis_ts, buf);
1261 case TS_SECONDS_HOUR_MIN_SEC:
1262 set_time_hour_min_sec(&del_dis_ts, buf);
1265 g_assert_not_reached();
1273 set_epoch_time(fd, buf);
1277 set_abs_time(fd, buf, FALSE);
1280 case TS_UTC_WITH_DATE:
1281 set_abs_date_time(fd, buf, FALSE);
1285 /* code is missing for this case, but I don't know which [jmayer20051219] */
1292 col_set_cls_time(const frame_data *fd, column_info *cinfo, const gint col)
1294 switch (timestamp_get_type()) {
1296 col_set_abs_time(fd, cinfo, col);
1299 case TS_ABSOLUTE_WITH_DATE:
1300 col_set_abs_date_time(fd, cinfo, col);
1304 col_set_rel_time(fd, cinfo, col);
1308 col_set_delta_time(fd, cinfo, col);
1312 col_set_delta_time_dis(fd, cinfo, col);
1316 col_set_epoch_time(fd, cinfo, col);
1320 col_set_utc_time(fd, cinfo, col);
1323 case TS_UTC_WITH_DATE:
1324 col_set_utc_date_time(fd, cinfo, col);
1328 /* code is missing for this case, but I don't know which [jmayer20051219] */
1329 g_assert_not_reached();
1334 /* Set the format of the variable time format. */
1336 col_set_fmt_time(const frame_data *fd, column_info *cinfo, const gint fmt, const gint col)
1338 COL_CHECK_REF_TIME(fd, cinfo->col_buf[col]);
1342 col_set_cls_time(fd, cinfo, col);
1346 col_set_abs_time(fd, cinfo, col);
1349 case COL_ABS_DATE_TIME:
1350 col_set_abs_date_time(fd, cinfo, col);
1354 col_set_rel_time(fd, cinfo, col);
1357 case COL_DELTA_TIME:
1358 col_set_delta_time(fd, cinfo, col);
1361 case COL_DELTA_TIME_DIS:
1362 col_set_delta_time_dis(fd, cinfo, col);
1366 col_set_utc_time(fd, cinfo, col);
1369 case COL_UTC_DATE_TIME:
1370 col_set_utc_date_time(fd, cinfo, col);
1374 g_assert_not_reached();
1379 /* --------------------------- */
1380 /* Set the given (relative) time to a column element.
1382 * Used by multiple dissectors to set the time in the column
1383 * COL_DELTA_CONV_TIME
1385 * @param cinfo the current packet row
1386 * @param el the column to use, e.g. COL_INFO
1387 * @param ts the time to set in the column
1388 * @param fieldname the fieldname to use for creating a filter (when
1389 * applying/preparing/copying as filter)
1392 col_set_time(column_info *cinfo, const gint el, const nstime_t *ts, const char *fieldname)
1396 if (!CHECK_COL(cinfo, el))
1399 /** @todo TODO: We don't respect fd->flags.ref_time (no way to access 'fd')
1400 COL_CHECK_REF_TIME(fd, buf);
1403 for (col = cinfo->col_first[el]; col <= cinfo->col_last[el]; col++) {
1404 if (cinfo->fmt_matx[col][el]) {
1405 switch (timestamp_get_precision()) {
1406 case TS_PREC_FIXED_SEC:
1407 case TS_PREC_AUTO_SEC:
1408 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
1409 (gint32) ts->secs, ts->nsecs / 1000000000, TO_STR_TIME_RES_T_SECS);
1411 case TS_PREC_FIXED_DSEC:
1412 case TS_PREC_AUTO_DSEC:
1413 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
1414 (gint32) ts->secs, ts->nsecs / 100000000, TO_STR_TIME_RES_T_DSECS);
1416 case TS_PREC_FIXED_CSEC:
1417 case TS_PREC_AUTO_CSEC:
1418 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
1419 (gint32) ts->secs, ts->nsecs / 10000000, TO_STR_TIME_RES_T_CSECS);
1421 case TS_PREC_FIXED_MSEC:
1422 case TS_PREC_AUTO_MSEC:
1423 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
1424 (gint32) ts->secs, ts->nsecs / 1000000, TO_STR_TIME_RES_T_MSECS);
1426 case TS_PREC_FIXED_USEC:
1427 case TS_PREC_AUTO_USEC:
1428 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
1429 (gint32) ts->secs, ts->nsecs / 1000, TO_STR_TIME_RES_T_USECS);
1431 case TS_PREC_FIXED_NSEC:
1432 case TS_PREC_AUTO_NSEC:
1433 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
1434 (gint32) ts->secs, ts->nsecs, TO_STR_TIME_RES_T_NSECS);
1437 g_assert_not_reached();
1439 cinfo->col_data[col] = cinfo->col_buf[col];
1440 cinfo->col_expr.col_expr[col] = fieldname;
1441 g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->col_buf[col],COL_MAX_LEN);
1447 col_set_addr(packet_info *pinfo, const int col, const address *addr, const gboolean is_src,
1448 const gboolean fill_col_exprs, const gboolean res)
1450 if (addr->type == AT_NONE) {
1451 /* No address, nothing to do */
1456 pinfo->cinfo->col_data[col] = se_get_addr_name(addr);
1458 pinfo->cinfo->col_data[col] = se_address_to_str(addr);
1460 if (!fill_col_exprs)
1463 switch (addr->type) {
1466 pinfo->cinfo->col_expr.col_expr[col] = "ax25.src";
1468 pinfo->cinfo->col_expr.col_expr[col] = "ax25.dst";
1469 g_strlcpy(pinfo->cinfo->col_expr.col_expr_val[col], ax25_to_str((guint8 *)addr->data), COL_MAX_LEN);
1474 pinfo->cinfo->col_expr.col_expr[col] = "eth.src";
1476 pinfo->cinfo->col_expr.col_expr[col] = "eth.dst";
1477 address_to_str_buf(addr, pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN);
1482 pinfo->cinfo->col_expr.col_expr[col] = "ip.src";
1484 pinfo->cinfo->col_expr.col_expr[col] = "ip.dst";
1485 ip_to_str_buf((guint8 *)addr->data, pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN);
1490 pinfo->cinfo->col_expr.col_expr[col] = "ipv6.src";
1492 pinfo->cinfo->col_expr.col_expr[col] = "ipv6.dst";
1493 address_to_str_buf(addr, pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN);
1498 pinfo->cinfo->col_expr.col_expr[col] = "ddp.src";
1500 pinfo->cinfo->col_expr.col_expr[col] = "ddp.dst";
1501 g_strlcpy(pinfo->cinfo->col_expr.col_expr_val[col], pinfo->cinfo->col_buf[col], COL_MAX_LEN);
1506 pinfo->cinfo->col_expr.col_expr[col] = "arcnet.src";
1508 pinfo->cinfo->col_expr.col_expr[col] = "arcnet.dst";
1509 g_strlcpy(pinfo->cinfo->col_expr.col_expr_val[col], pinfo->cinfo->col_buf[col], COL_MAX_LEN);
1514 pinfo->cinfo->col_expr.col_expr[col] = "uri.src";
1516 pinfo->cinfo->col_expr.col_expr[col] = "uri.dst";
1517 address_to_str_buf(addr, pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN);
1524 /* Some addresses (e.g. ieee80211) use a standard format like AT_ETHER but
1525 * don't use the same hf_ value (and thus don't use the same filter string).
1526 * Such address can use the SET_ADDRESS_HF macro to pass in the specific hf_
1527 * value they use. If they did so, we overwrite the default filter string
1528 * with their specific one here. See bug #7728 for further discussion.
1529 * https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=7728 */
1530 if (addr->hf != -1) {
1531 pinfo->cinfo->col_expr.col_expr[col] = proto_registrar_get_nth(addr->hf)->abbrev;
1536 /* ------------------------ */
1538 col_set_port(packet_info *pinfo, const int col, const gboolean is_res, const gboolean is_src, const gboolean fill_col_exprs _U_)
1543 port = pinfo->srcport;
1545 port = pinfo->destport;
1547 /* TODO: Use fill_col_exprs */
1549 switch (pinfo->ptype) {
1552 g_strlcpy(pinfo->cinfo->col_buf[col], get_sctp_port(port), COL_MAX_LEN);
1554 guint32_to_str_buf(port, pinfo->cinfo->col_buf[col], COL_MAX_LEN);
1558 guint32_to_str_buf(port, pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN);
1560 g_strlcpy(pinfo->cinfo->col_buf[col], get_tcp_port(port), COL_MAX_LEN);
1562 g_strlcpy(pinfo->cinfo->col_buf[col], pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN);
1564 pinfo->cinfo->col_expr.col_expr[col] = "tcp.srcport";
1566 pinfo->cinfo->col_expr.col_expr[col] = "tcp.dstport";
1570 guint32_to_str_buf(port, pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN);
1572 g_strlcpy(pinfo->cinfo->col_buf[col], get_udp_port(port), COL_MAX_LEN);
1574 g_strlcpy(pinfo->cinfo->col_buf[col], pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN);
1576 pinfo->cinfo->col_expr.col_expr[col] = "udp.srcport";
1578 pinfo->cinfo->col_expr.col_expr[col] = "udp.dstport";
1583 pinfo->cinfo->col_expr.col_expr[col] = "ddp.src_socket";
1585 pinfo->cinfo->col_expr.col_expr[col] = "ddp.dst_socket";
1586 guint32_to_str_buf(port, pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN);
1587 g_strlcpy(pinfo->cinfo->col_buf[col], pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN);
1591 /* XXX - resolve IPX socket numbers */
1592 g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "0x%04x", port);
1593 g_strlcpy(pinfo->cinfo->col_expr.col_expr_val[col], pinfo->cinfo->col_buf[col],COL_MAX_LEN);
1595 pinfo->cinfo->col_expr.col_expr[col] = "ipx.src.socket";
1597 pinfo->cinfo->col_expr.col_expr[col] = "ipx.dst.socket";
1601 /* XXX - resolve IDP socket numbers */
1602 g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "0x%04x", port);
1603 g_strlcpy(pinfo->cinfo->col_expr.col_expr_val[col], pinfo->cinfo->col_buf[col],COL_MAX_LEN);
1605 pinfo->cinfo->col_expr.col_expr[col] = "idp.src.socket";
1607 pinfo->cinfo->col_expr.col_expr[col] = "idp.dst.socket";
1611 /* XXX - resolve USB endpoint numbers */
1612 g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "0x%08x", port);
1613 g_strlcpy(pinfo->cinfo->col_expr.col_expr_val[col], pinfo->cinfo->col_buf[col],COL_MAX_LEN);
1615 pinfo->cinfo->col_expr.col_expr[col] = "usb.src.endpoint";
1617 pinfo->cinfo->col_expr.col_expr[col] = "usb.dst.endpoint";
1623 pinfo->cinfo->col_data[col] = pinfo->cinfo->col_buf[col];
1627 col_based_on_frame_data(column_info *cinfo, const gint col)
1630 g_assert(col < cinfo->num_cols);
1632 switch (cinfo->col_fmt[col]) {
1636 case COL_ABS_DATE_TIME:
1638 case COL_UTC_DATE_TIME:
1640 case COL_DELTA_TIME:
1641 case COL_DELTA_TIME_DIS:
1642 case COL_PACKET_LENGTH:
1643 case COL_CUMULATIVE_BYTES:
1652 col_fill_in_frame_data(const frame_data *fd, column_info *cinfo, const gint col, const gboolean fill_col_exprs)
1654 switch (cinfo->col_fmt[col]) {
1656 guint32_to_str_buf(fd->num, cinfo->col_buf[col], COL_MAX_LEN);
1657 cinfo->col_data[col] = cinfo->col_buf[col];
1662 case COL_ABS_DATE_TIME:
1664 case COL_UTC_DATE_TIME:
1666 case COL_DELTA_TIME:
1667 case COL_DELTA_TIME_DIS:
1668 /* TODO: Pass on fill_col_exprs */
1669 col_set_fmt_time(fd, cinfo, cinfo->col_fmt[col], col);
1672 case COL_PACKET_LENGTH:
1673 guint32_to_str_buf(fd->pkt_len, cinfo->col_buf[col], COL_MAX_LEN);
1674 cinfo->col_data[col] = cinfo->col_buf[col];
1677 case COL_CUMULATIVE_BYTES:
1678 guint32_to_str_buf(fd->cum_bytes, cinfo->col_buf[col], COL_MAX_LEN);
1679 cinfo->col_data[col] = cinfo->col_buf[col];
1686 if (!fill_col_exprs)
1689 switch (cinfo->col_fmt[col]) {
1691 cinfo->col_expr.col_expr[col] = "frame.number";
1692 g_strlcpy(cinfo->col_expr.col_expr_val[col], cinfo->col_buf[col], COL_MAX_LEN);
1697 case COL_ABS_DATE_TIME:
1699 case COL_UTC_DATE_TIME:
1701 case COL_DELTA_TIME:
1702 case COL_DELTA_TIME_DIS:
1703 /* Already handled above */
1706 case COL_PACKET_LENGTH:
1707 cinfo->col_expr.col_expr[col] = "frame.len";
1708 g_strlcpy(cinfo->col_expr.col_expr_val[col], cinfo->col_buf[col], COL_MAX_LEN);
1711 case COL_CUMULATIVE_BYTES:
1720 col_fill_in(packet_info *pinfo, const gboolean fill_col_exprs, const gboolean fill_fd_colums)
1727 for (i = 0; i < pinfo->cinfo->num_cols; i++) {
1728 switch (pinfo->cinfo->col_fmt[i]) {
1732 case COL_ABS_DATE_TIME:
1734 case COL_UTC_DATE_TIME:
1736 case COL_DELTA_TIME:
1737 case COL_DELTA_TIME_DIS:
1738 case COL_PACKET_LENGTH:
1739 case COL_CUMULATIVE_BYTES:
1741 col_fill_in_frame_data(pinfo->fd, pinfo->cinfo, i, fill_col_exprs);
1745 case COL_RES_SRC: /* COL_DEF_SRC is currently just like COL_RES_SRC */
1746 col_set_addr(pinfo, i, &pinfo->src, TRUE, fill_col_exprs, TRUE);
1750 col_set_addr(pinfo, i, &pinfo->src, TRUE, fill_col_exprs, FALSE);
1753 case COL_DEF_DL_SRC:
1754 case COL_RES_DL_SRC:
1755 col_set_addr(pinfo, i, &pinfo->dl_src, TRUE, fill_col_exprs, TRUE);
1758 case COL_UNRES_DL_SRC:
1759 col_set_addr(pinfo, i, &pinfo->dl_src, TRUE, fill_col_exprs, FALSE);
1762 case COL_DEF_NET_SRC:
1763 case COL_RES_NET_SRC:
1764 col_set_addr(pinfo, i, &pinfo->net_src, TRUE, fill_col_exprs, TRUE);
1767 case COL_UNRES_NET_SRC:
1768 col_set_addr(pinfo, i, &pinfo->net_src, TRUE, fill_col_exprs, FALSE);
1772 case COL_RES_DST: /* COL_DEF_DST is currently just like COL_RES_DST */
1773 col_set_addr(pinfo, i, &pinfo->dst, FALSE, fill_col_exprs, TRUE);
1777 col_set_addr(pinfo, i, &pinfo->dst, FALSE, fill_col_exprs, FALSE);
1780 case COL_DEF_DL_DST:
1781 case COL_RES_DL_DST:
1782 col_set_addr(pinfo, i, &pinfo->dl_dst, FALSE, fill_col_exprs, TRUE);
1785 case COL_UNRES_DL_DST:
1786 col_set_addr(pinfo, i, &pinfo->dl_dst, FALSE, fill_col_exprs, FALSE);
1789 case COL_DEF_NET_DST:
1790 case COL_RES_NET_DST:
1791 col_set_addr(pinfo, i, &pinfo->net_dst, FALSE, fill_col_exprs, TRUE);
1794 case COL_UNRES_NET_DST:
1795 col_set_addr(pinfo, i, &pinfo->net_dst, FALSE, fill_col_exprs, FALSE);
1798 case COL_DEF_SRC_PORT:
1799 case COL_RES_SRC_PORT: /* COL_DEF_SRC_PORT is currently just like COL_RES_SRC_PORT */
1800 col_set_port(pinfo, i, TRUE, TRUE, fill_col_exprs);
1803 case COL_UNRES_SRC_PORT:
1804 col_set_port(pinfo, i, FALSE, TRUE, fill_col_exprs);
1807 case COL_DEF_DST_PORT:
1808 case COL_RES_DST_PORT: /* COL_DEF_DST_PORT is currently just like COL_RES_DST_PORT */
1809 col_set_port(pinfo, i, TRUE, FALSE, fill_col_exprs);
1812 case COL_UNRES_DST_PORT:
1813 col_set_port(pinfo, i, FALSE, FALSE, fill_col_exprs);
1816 case NUM_COL_FMTS: /* keep compiler happy - shouldn't get here */
1817 g_assert_not_reached();
1820 if (pinfo->cinfo->col_fmt[i] >= NUM_COL_FMTS) {
1821 g_assert_not_reached();
1824 * Formatting handled by col_custom_set_edt() (COL_CUSTOM), expert.c
1825 * (COL_EXPERT), or individual dissectors.
1833 * Fill in columns if we got an error reading the packet.
1834 * We set most columns to "???", and set the Info column to an error
1838 col_fill_in_error(column_info *cinfo, frame_data *fdata, const gboolean fill_col_exprs, const gboolean fill_fd_colums)
1845 for (i = 0; i < cinfo->num_cols; i++) {
1846 switch (cinfo->col_fmt[i]) {
1850 case COL_ABS_DATE_TIME:
1852 case COL_UTC_DATE_TIME:
1854 case COL_DELTA_TIME:
1855 case COL_DELTA_TIME_DIS:
1856 case COL_PACKET_LENGTH:
1857 case COL_CUMULATIVE_BYTES:
1859 col_fill_in_frame_data(fdata, cinfo, i, fill_col_exprs);
1863 /* XXX - say more than this */
1864 cinfo->col_data[i] = "Read error";
1867 case NUM_COL_FMTS: /* keep compiler happy - shouldn't get here */
1868 g_assert_not_reached();
1871 if (cinfo->col_fmt[i] >= NUM_COL_FMTS) {
1872 g_assert_not_reached();
1875 * No dissection was done, and these columns are set as the
1876 * result of the dissection, so....
1878 cinfo->col_data[i] = "???";
1885 XXX this needs more rework?
1886 /* --------------------------- */
1889 set_addr(address *addr, gboolean is_res)
1891 if (addr->type == AT_NONE)
1892 return ""; /* no address, nothing to do */
1895 return se_get_addr_name(addr /*, COL_MAX_LEN*/);
1897 return se_address_to_str(addr);
1900 /* Fills col_text in the frame data structure */
1902 col_fill_fdata(packet_info *pinfo)
1915 for (i = 0; i < pinfo->cinfo->num_cols; i++) {
1917 switch (pinfo->cinfo->col_fmt[i]) {
1918 case COL_NUMBER: /* frame number */
1919 case COL_PACKET_LENGTH: /* fd->pkt_len */
1920 case COL_CUMULATIVE_BYTES: /* fd->cum_bytes */
1923 case COL_ABS_DATE_TIME:
1925 case COL_UTC_DATE_TIME: /* from fd structures */
1927 case COL_DELTA_TIME:
1928 case COL_DELTA_TIME_DIS:
1932 case COL_RES_SRC: /* COL_DEF_SRC is currently just like COL_RES_SRC */
1935 fdata->col_text[i] = set_addr(&pinfo->src, res);
1938 case COL_DEF_DL_SRC:
1939 case COL_RES_DL_SRC:
1941 case COL_UNRES_DL_SRC:
1942 fdata->col_text[i] = set_addr (&pinfo->dl_src, res);
1945 case COL_DEF_NET_SRC:
1946 case COL_RES_NET_SRC:
1948 case COL_UNRES_NET_SRC:
1949 fdata->col_text[i] = set_addr (&pinfo->net_src, res);
1953 case COL_RES_DST: /* COL_DEF_DST is currently just like COL_RES_DST */
1956 fdata->col_text[i] = set_addr (&pinfo->dst, res);
1959 case COL_DEF_DL_DST:
1960 case COL_RES_DL_DST:
1962 case COL_UNRES_DL_DST:
1963 fdata->col_text[i] = set_addr (&pinfo->dl_dst, res);
1966 case COL_DEF_NET_DST:
1967 case COL_RES_NET_DST:
1969 case COL_UNRES_NET_DST:
1970 fdata->col_text[i] = set_addr (&pinfo->net_dst, res);
1973 case COL_DEF_SRC_PORT:
1974 case COL_RES_SRC_PORT: /* COL_DEF_SRC_PORT is currently just like COL_RES_SRC_PORT */
1975 fdata->col_text[i] = set_port(pinfo, TRUE, pinfo->srcport);
1977 case COL_UNRES_SRC_PORT:
1978 fdata->col_text[i] = set_port(pinfo, FALSE, pinfo->srcport);
1981 case COL_DEF_DST_PORT:
1982 case COL_RES_DST_PORT: /* COL_DEF_DST_PORT is currently just like COL_RES_DST_PORT */
1983 fdata->col_text[i] = set_port(pinfo, TRUE, pinfo->destport);
1986 case COL_UNRES_DST_PORT:
1987 fdata->col_text[i] = set_port(pinfo, FALSE, pinfo->destport);
1990 case COL_IF_DIR: /* currently done by dissectors */
1993 case COL_HPUX_SUBSYS:
1994 case COL_HPUX_DEVID:
1996 case COL_8021Q_VLAN_ID:
1997 case COL_DSCP_VALUE:
2000 case COL_BSSGP_TLLI:
2004 if (pinfo->cinfo->col_data[i] != pinfo->cinfo->col_buf[i]) {
2005 /* XXX assume it's a constant */
2006 fdata->col_text[i] = (gchar *)pinfo->cinfo->col_data[i];
2010 fdata->col_text[i] = se_strdup(pinfo->cinfo->col_data[i]);
2014 fdata->col_text[i] = (gchar *)(GUINT_TO_POINTER((guint)pinfo->oxid));
2017 fdata->col_text[i] = (gchar *)(GUINT_TO_POINTER((guint)pinfo->rxid));
2019 case COL_CIRCUIT_ID:
2020 set_circuit_id(pinfo);
2023 fdata->col_text[i] = (gchar *)-1; /* !! DEPRECATED !!*/
2026 fdata->col_text[i] = (gchar *)-1; /* !! DEPRECATED !!*/
2029 fdata->col_text[i] = (gchar *)-1; /* !! DEPRECATED !!*/
2032 case NUM_COL_FMTS: /* keep compiler happy - shouldn't get here */
2033 g_assert_not_reached();
2039 /* XXX Gets/creates the text from col_text in frame data */
2040 /* --------------------- */
2042 col_get_text(frame_data *fd, column_info *cinfo, gint col)
2044 static gchar fmtbuf[3][COL_MAX_LEN];
2049 idx = (idx + 1) % 3;
2054 switch (cinfo->col_fmt[col]) {
2055 case COL_NUMBER: /* frame number */
2056 guint32_to_str_buf(fd->num, buf, COL_MAX_LEN);
2060 set_cls_time(fd, buf);
2063 set_abs_time(fd, buf, TRUE);
2066 set_abs_time(fd, buf, FALSE);
2068 case COL_ABS_DATE_TIME:
2069 set_abs_date_time(fd, buf, TRUE);
2071 case COL_UTC_DATE_TIME:
2072 set_abs_date_time(fd, buf, FALSE);
2075 set_rel_time(fd, buf);
2077 case COL_DELTA_TIME:
2078 set_delta_time(fd, buf);
2080 case COL_DELTA_TIME_DIS:
2081 set_delta_time_dis(fd, buf);
2084 case COL_PACKET_LENGTH: /* fd->pkt_len */
2085 guint32_to_str_buf(fd->pkt_len, buf, COL_MAX_LEN);
2088 case COL_CUMULATIVE_BYTES: /* fd->cum_bytes */
2089 guint32_to_str_buf(fd->cum_bytes, buf, COL_MAX_LEN);
2093 case COL_RES_SRC: /* network address */
2095 case COL_DEF_DL_SRC:
2096 case COL_RES_DL_SRC:
2097 case COL_UNRES_DL_SRC:
2098 case COL_DEF_NET_SRC:
2099 case COL_RES_NET_SRC:
2100 case COL_UNRES_NET_SRC:
2104 case COL_DEF_DL_DST:
2105 case COL_RES_DL_DST:
2106 case COL_UNRES_DL_DST:
2107 case COL_DEF_NET_DST:
2108 case COL_RES_NET_DST:
2109 case COL_UNRES_NET_DST:
2112 case COL_CIRCUIT_ID:
2115 case COL_HPUX_SUBSYS:
2116 case COL_HPUX_DEVID:
2118 case COL_8021Q_VLAN_ID:
2119 case COL_DSCP_VALUE:
2122 case COL_BSSGP_TLLI:
2126 ptr = fd->col_text[col];
2129 case COL_DEF_SRC_PORT:
2130 case COL_RES_SRC_PORT:
2131 case COL_UNRES_SRC_PORT:
2132 case COL_DEF_DST_PORT:
2133 case COL_RES_DST_PORT:
2134 case COL_UNRES_DST_PORT:
2136 if (GPOINTER_TO_UINT(fd->col_text[col]) <= 65536)
2137 guint32_to_str_buf(GPOINTER_TO_UINT(fd->col_text[col], buf, COL_MAX_LEN));
2139 ptr = fd->col_text[col];
2146 g_snprintf(buf, COL_MAX_LEN, "0x%x", GPOINTER_TO_UINT(fd->col_text[col]));
2150 guint32_to_str_buf(GPOINTER_TO_UINT(fd->col_text[col]), buf, COL_MAX_LEN);
2153 case NUM_COL_FMTS: /* keep compiler happy - shouldn't get here */
2154 g_assert_not_reached();
2167 * indent-tabs-mode: nil
2170 * ex: set shiftwidth=2 tabstop=8 expandtab:
2171 * :indentSize=2:tabSize=8:noTabs=true: