2 * Routines for column utilities.
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * SPDX-License-Identifier: GPL-2.0-or-later
17 #include "column-utils.h"
18 #include "timestamp.h"
20 #include "packet_info.h"
21 #include "wsutil/pint.h"
22 #include "addr_resolv.h"
23 #include "address_types.h"
25 #include "osi-utils.h"
26 #include "value_string.h"
27 #include "column-info.h"
30 #include <epan/strutil.h>
31 #include <epan/epan.h>
32 #include <epan/dfilter/dfilter.h>
34 #include <wsutil/utf8_entities.h>
35 #include <wsutil/ws_printf.h>
38 #include <epan/wslua/wslua.h>
41 /* Used for locale decimal point */
42 static char *col_decimal_point;
44 /* Used to indicate updated column information, e.g. a new request/response. */
45 static gboolean col_data_changed_;
47 /* Allocate all the data structures for constructing column data, given
48 the number of columns. */
50 col_setup(column_info *cinfo, const gint num_cols)
54 col_decimal_point = localeconv()->decimal_point;
55 cinfo->num_cols = num_cols;
56 cinfo->columns = g_new(col_item_t, num_cols);
57 cinfo->col_first = g_new(int, NUM_COL_FMTS);
58 cinfo->col_last = g_new(int, NUM_COL_FMTS);
59 for (i = 0; i < num_cols; i++) {
60 cinfo->columns[i].col_custom_fields_ids = NULL;
62 cinfo->col_expr.col_expr = g_new(const gchar*, num_cols + 1);
63 cinfo->col_expr.col_expr_val = g_new(gchar*, num_cols + 1);
65 for (i = 0; i < NUM_COL_FMTS; i++) {
66 cinfo->col_first[i] = -1;
67 cinfo->col_last[i] = -1;
69 cinfo->prime_regex = g_regex_new(COL_CUSTOM_PRIME_REGEX,
70 G_REGEX_ANCHORED, G_REGEX_MATCH_ANCHORED, NULL);
74 col_custom_fields_ids_free(GSList** custom_fields_id)
76 if (*custom_fields_id != NULL) {
77 g_slist_free_full(*custom_fields_id, g_free);
79 *custom_fields_id = NULL;
82 /* Cleanup all the data structures for constructing column data; undoes
83 the allocations that col_setup() does. */
85 col_cleanup(column_info *cinfo)
93 for (i = 0; i < cinfo->num_cols; i++) {
94 col_item = &cinfo->columns[i];
95 g_free(col_item->fmt_matx);
96 g_free(col_item->col_title);
97 g_free(col_item->col_custom_fields);
98 dfilter_free(col_item->col_custom_dfilter);
99 /* col_item->col_data points to col_buf or static memory */
100 g_free(col_item->col_buf);
101 g_free(cinfo->col_expr.col_expr_val[i]);
102 col_custom_fields_ids_free(&col_item->col_custom_fields_ids);
105 g_free(cinfo->columns);
106 g_free(cinfo->col_first);
107 g_free(cinfo->col_last);
109 * XXX - MSVC doesn't correctly handle the "const" qualifier; it thinks
110 * "const XXX **" means "pointer to const pointer to XXX", i.e. that
111 * it's a pointer to something that's "const"ant, not "pointer to
112 * pointer to const XXX", i.e. that it's a pointer to a pointer to
113 * something that's "const"ant. Cast its bogus complaints away.
115 g_free((gchar **)cinfo->col_expr.col_expr);
116 g_free(cinfo->col_expr.col_expr_val);
117 if (cinfo->prime_regex)
118 g_regex_unref(cinfo->prime_regex);
121 /* Initialize the data structures for constructing column data. */
123 col_init(column_info *cinfo, const struct epan_session *epan)
126 col_item_t* col_item;
131 for (i = 0; i < cinfo->num_cols; i++) {
132 col_item = &cinfo->columns[i];
133 col_item->col_buf[0] = '\0';
134 col_item->col_data = col_item->col_buf;
135 col_item->col_fence = 0;
136 col_item->writable = TRUE;
137 cinfo->col_expr.col_expr[i] = "";
138 cinfo->col_expr.col_expr_val[i][0] = '\0';
140 cinfo->writable = TRUE;
145 col_get_writable(column_info *cinfo, const gint col)
148 col_item_t* col_item;
153 /* "global" (not) writeability will always override
154 an individual column */
155 if ((col == -1) || (cinfo->writable == FALSE))
156 return cinfo->writable;
158 if (cinfo->col_first[col] >= 0) {
159 for (i = cinfo->col_first[col]; i <= cinfo->col_last[col]; i++) {
160 col_item = &cinfo->columns[i];
161 if (col_item->fmt_matx[col]) {
162 return col_item->writable;
170 col_set_writable(column_info *cinfo, const gint col, const gboolean writable)
173 col_item_t* col_item;
177 cinfo->writable = writable;
178 } else if (cinfo->col_first[col] >= 0) {
179 for (i = cinfo->col_first[col]; i <= cinfo->col_last[col]; i++) {
180 col_item = &cinfo->columns[i];
181 if (col_item->fmt_matx[col]) {
182 col_item->writable = writable;
189 /* Checks to see if a particular packet information element is needed for the packet list */
190 #define CHECK_COL(cinfo, el) \
191 /* We are constructing columns, and they're writable */ \
192 (col_get_writable(cinfo, el) && \
193 /* There is at least one column in that format */ \
194 ((cinfo)->col_first[el] >= 0))
196 /* Sets the fence for a column to be at the end of the column. */
198 col_set_fence(column_info *cinfo, const gint el)
201 col_item_t* col_item;
203 if (!CHECK_COL(cinfo, el))
206 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
207 col_item = &cinfo->columns[i];
208 if (col_item->fmt_matx[el]) {
209 col_item->col_fence = (int)strlen(col_item->col_data);
214 /* Clear the fence for a column. */
216 col_clear_fence(column_info *cinfo, const gint el)
219 col_item_t* col_item;
221 if (!CHECK_COL(cinfo, el))
224 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
225 col_item = &cinfo->columns[i];
226 if (col_item->fmt_matx[el]) {
227 col_item->col_fence = 0;
232 /* Gets the text of a column */
234 col_get_text(column_info *cinfo, const gint el)
237 const gchar* text = NULL;
238 col_item_t* col_item;
240 if (!(cinfo && (cinfo)->col_first[el] >= 0)) {
244 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
245 col_item = &cinfo->columns[i];
246 if (col_item->fmt_matx[el]) {
247 text = (col_item->col_data);
254 /* Use this to clear out a column, especially if you're going to be
255 appending to it later; at least on some platforms, it's more
256 efficient than using "col_add_str()" with a null string, and
257 more efficient than "col_set_str()" with a null string if you
258 later append to it, as the later append will cause a string
261 col_clear(column_info *cinfo, const gint el)
264 col_item_t* col_item;
266 if (!CHECK_COL(cinfo, el))
269 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
270 col_item = &cinfo->columns[i];
271 if (col_item->fmt_matx[el]) {
273 * At this point, either
275 * 1) col_data[i] is equal to col_buf[i], in which case we
276 * don't have to worry about copying col_data[i] to
279 * 2) col_data[i] isn't equal to col_buf[i], in which case
280 * the only thing that's been done to the column is
281 * "col_set_str()" calls and possibly "col_set_fence()"
282 * calls, in which case the fence is either unset and
283 * at the beginning of the string or set and at the end
284 * of the string - if it's at the beginning, we're just
285 * going to clear the column, and if it's at the end,
286 * we don't do anything.
288 if (col_item->col_buf == col_item->col_data || col_item->col_fence == 0) {
290 * The fence isn't at the end of the column, or the column wasn't
291 * last set with "col_set_str()", so clear the column out.
293 col_item->col_buf[col_item->col_fence] = '\0';
294 col_item->col_data = col_item->col_buf;
296 cinfo->col_expr.col_expr[i] = "";
297 cinfo->col_expr.col_expr_val[i][0] = '\0';
302 #define COL_CHECK_APPEND(col_item, max_len) \
303 if (col_item->col_data != col_item->col_buf) { \
304 /* This was set with "col_set_str()"; copy the string they \
305 set it to into the buffer, so we can append to it. */ \
306 g_strlcpy(col_item->col_buf, col_item->col_data, max_len); \
307 col_item->col_data = col_item->col_buf; \
310 #define COL_CHECK_REF_TIME(fd, buf) \
311 if (fd->ref_time) { \
312 g_strlcpy(buf, "*REF*", COL_MAX_LEN ); \
316 /* The same as CHECK_COL(), but without the check to see if the column is writable. */
317 #define HAVE_CUSTOM_COLS(cinfo) ((cinfo) && (cinfo)->col_first[COL_CUSTOM] >= 0)
320 have_custom_cols(column_info *cinfo)
322 return HAVE_CUSTOM_COLS(cinfo);
326 have_field_extractors(void)
329 return wslua_has_field_extractors();
335 /* search in edt tree custom fields */
336 void col_custom_set_edt(epan_dissect_t *edt, column_info *cinfo)
339 col_item_t* col_item;
341 if (!HAVE_CUSTOM_COLS(cinfo))
344 for (i = cinfo->col_first[COL_CUSTOM];
345 i <= cinfo->col_last[COL_CUSTOM]; i++) {
346 col_item = &cinfo->columns[i];
347 if (col_item->fmt_matx[COL_CUSTOM] &&
348 col_item->col_custom_fields &&
349 col_item->col_custom_fields_ids) {
350 col_item->col_data = col_item->col_buf;
351 cinfo->col_expr.col_expr[i] = epan_custom_set(edt, col_item->col_custom_fields_ids,
352 col_item->col_custom_occurrence,
354 cinfo->col_expr.col_expr_val[i],
361 col_custom_prime_edt(epan_dissect_t *edt, column_info *cinfo)
364 col_item_t* col_item;
366 if (!HAVE_CUSTOM_COLS(cinfo))
369 for (i = cinfo->col_first[COL_CUSTOM];
370 i <= cinfo->col_last[COL_CUSTOM]; i++) {
371 col_item = &cinfo->columns[i];
373 if (col_item->fmt_matx[COL_CUSTOM] &&
374 col_item->col_custom_dfilter) {
375 epan_dissect_prime_with_dfilter(edt, col_item->col_custom_dfilter);
381 col_append_lstr(column_info *cinfo, const gint el, const gchar *str1, ...)
387 col_item_t* col_item;
389 if (!CHECK_COL(cinfo, el))
393 max_len = COL_MAX_INFO_LEN;
395 max_len = COL_MAX_LEN;
397 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
398 col_item = &cinfo->columns[i];
399 if (col_item->fmt_matx[el]) {
401 * First arrange that we can append, if necessary.
403 COL_CHECK_APPEND(col_item, max_len);
405 pos = strlen(col_item->col_buf);
412 if (G_UNLIKELY(str == NULL))
415 pos += g_strlcpy(&col_item->col_buf[pos], str, max_len - pos);
417 } while (pos < max_len && (str = va_arg(ap, const char *)) != COL_ADD_LSTR_TERMINATOR);
424 col_append_str_uint(column_info *cinfo, const gint col, const gchar *abbrev, guint32 val, const gchar *sep)
428 guint32_to_str_buf(val, buf, sizeof(buf));
429 col_append_lstr(cinfo, col, sep ? sep : "", abbrev, "=", buf, COL_ADD_LSTR_TERMINATOR);
433 col_snprint_port(gchar *buf, gulong buf_siz, port_type typ, guint16 val)
437 if (gbl_resolv_flags.transport_name &&
438 (str = try_serv_name_lookup(typ, val)) != NULL) {
439 ws_snprintf(buf, buf_siz, "%s(%"G_GUINT16_FORMAT")", str, val);
441 ws_snprintf(buf, buf_siz, "%"G_GUINT16_FORMAT, val);
446 col_append_ports(column_info *cinfo, const gint col, port_type typ, guint16 src, guint16 dst)
448 char buf_src[32], buf_dst[32];
450 col_snprint_port(buf_src, 32, typ, src);
451 col_snprint_port(buf_dst, 32, typ, dst);
452 col_append_lstr(cinfo, col, buf_src, " " UTF8_RIGHTWARDS_ARROW " ", buf_dst, COL_ADD_LSTR_TERMINATOR);
456 col_append_frame_number(packet_info *pinfo, const gint col, const gchar *fmt_str, guint frame_num)
458 col_append_fstr(pinfo->cinfo, col, fmt_str, frame_num);
459 if (!pinfo->fd->visited) {
460 col_data_changed_ = TRUE;
465 col_do_append_fstr(column_info *cinfo, const int el, const char *separator, const char *format, va_list ap)
467 size_t len, max_len, sep_len;
469 col_item_t* col_item;
471 sep_len = (separator) ? strlen(separator) : 0;
474 max_len = COL_MAX_INFO_LEN;
476 max_len = COL_MAX_LEN;
478 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
479 col_item = &cinfo->columns[i];
480 if (col_item->fmt_matx[el]) {
482 * First arrange that we can append, if necessary.
484 COL_CHECK_APPEND(col_item, max_len);
486 len = strlen(col_item->col_buf);
489 * If we have a separator, append it if the column isn't empty.
491 if (sep_len != 0 && len != 0) {
492 g_strlcat(col_item->col_buf, separator, max_len);
500 ws_vsnprintf(&col_item->col_buf[len], (guint32)(max_len - len), format, ap2);
507 /* Appends a vararg list to a packet info string. */
509 col_append_fstr(column_info *cinfo, const gint el, const gchar *format, ...)
513 if (!CHECK_COL(cinfo, el))
516 va_start(ap, format);
517 col_do_append_fstr(cinfo, el, NULL, format, ap);
521 /* Appends a vararg list to a packet info string.
522 * Prefixes it with the given separator if the column is not empty.
525 col_append_sep_fstr(column_info *cinfo, const gint el, const gchar *separator,
526 const gchar *format, ...)
530 if (!CHECK_COL(cinfo, el))
533 if (separator == NULL)
534 separator = ", "; /* default */
536 va_start(ap, format);
537 col_do_append_fstr(cinfo, el, separator, format, ap);
541 /* Prepends a vararg list to a packet info string. */
542 #define COL_BUF_MAX_LEN (((COL_MAX_INFO_LEN) > (COL_MAX_LEN)) ? \
543 (COL_MAX_INFO_LEN) : (COL_MAX_LEN))
545 col_prepend_fstr(column_info *cinfo, const gint el, const gchar *format, ...)
549 char orig_buf[COL_BUF_MAX_LEN];
552 col_item_t* col_item;
554 if (!CHECK_COL(cinfo, el))
558 max_len = COL_MAX_INFO_LEN;
560 max_len = COL_MAX_LEN;
562 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
563 col_item = &cinfo->columns[i];
564 if (col_item->fmt_matx[el]) {
565 if (col_item->col_data != col_item->col_buf) {
566 /* This was set with "col_set_str()"; which is effectively const */
567 orig = col_item->col_data;
569 g_strlcpy(orig_buf, col_item->col_buf, max_len);
572 va_start(ap, format);
573 ws_vsnprintf(col_item->col_buf, max_len, format, ap);
577 * Move the fence, unless it's at the beginning of the string.
579 if (col_item->col_fence > 0)
580 col_item->col_fence += (int) strlen(col_item->col_buf);
582 g_strlcat(col_item->col_buf, orig, max_len);
583 col_item->col_data = col_item->col_buf;
588 col_prepend_fence_fstr(column_info *cinfo, const gint el, const gchar *format, ...)
592 char orig_buf[COL_BUF_MAX_LEN];
595 col_item_t* col_item;
597 if (!CHECK_COL(cinfo, el))
601 max_len = COL_MAX_INFO_LEN;
603 max_len = COL_MAX_LEN;
605 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
606 col_item = &cinfo->columns[i];
607 if (col_item->fmt_matx[el]) {
608 if (col_item->col_data != col_item->col_buf) {
609 /* This was set with "col_set_str()"; which is effectively const */
610 orig = col_item->col_data;
612 g_strlcpy(orig_buf, col_item->col_buf, max_len);
615 va_start(ap, format);
616 ws_vsnprintf(col_item->col_buf, max_len, format, ap);
620 * Move the fence if it exists, else create a new fence at the
621 * end of the prepended data.
623 if (col_item->col_fence > 0) {
624 col_item->col_fence += (int) strlen(col_item->col_buf);
626 col_item->col_fence = (int) strlen(col_item->col_buf);
628 g_strlcat(col_item->col_buf, orig, max_len);
629 col_item->col_data = col_item->col_buf;
634 /* Use this if "str" points to something that won't stay around (and
635 must thus be copied). */
637 col_add_str(column_info *cinfo, const gint el, const gchar* str)
641 col_item_t* col_item;
643 if (!CHECK_COL(cinfo, el))
647 max_len = COL_MAX_INFO_LEN;
649 max_len = COL_MAX_LEN;
651 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
652 col_item = &cinfo->columns[i];
653 if (col_item->fmt_matx[el]) {
654 if (col_item->col_fence != 0) {
656 * We will append the string after the fence.
657 * First arrange that we can append, if necessary.
659 COL_CHECK_APPEND(col_item, max_len);
662 * There's no fence, so we can just write to the string.
664 col_item->col_data = col_item->col_buf;
666 g_strlcpy(&col_item->col_buf[col_item->col_fence], str, max_len - col_item->col_fence);
671 /* Use this if "str" points to something that will stay around (and thus
672 needn't be copied). */
674 col_set_str(column_info *cinfo, const gint el, const gchar* str)
678 col_item_t* col_item;
680 DISSECTOR_ASSERT(str);
682 if (!CHECK_COL(cinfo, el))
686 max_len = COL_MAX_INFO_LEN;
688 max_len = COL_MAX_LEN;
690 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
691 col_item = &cinfo->columns[i];
692 if (col_item->fmt_matx[el]) {
693 if (col_item->col_fence != 0) {
695 * We will append the string after the fence.
696 * First arrange that we can append, if necessary.
698 COL_CHECK_APPEND(col_item, max_len);
700 g_strlcpy(&col_item->col_buf[col_item->col_fence], str, max_len - col_item->col_fence);
703 * There's no fence, so we can just set the column to point
706 col_item->col_data = str;
713 col_add_lstr(column_info *cinfo, const gint el, const gchar *str1, ...)
720 col_item_t* col_item;
722 if (!CHECK_COL(cinfo, el))
726 max_len = COL_MAX_INFO_LEN;
728 max_len = COL_MAX_LEN;
730 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
731 col_item = &cinfo->columns[i];
732 if (col_item->fmt_matx[el]) {
733 pos = col_item->col_fence;
736 * We will append the string after the fence.
737 * First arrange that we can append, if necessary.
739 COL_CHECK_APPEND(col_item, max_len);
742 * There's no fence, so we can just write to the string.
744 col_item->col_data = col_item->col_buf;
750 if (G_UNLIKELY(str == NULL))
753 pos += g_strlcpy(&col_item->col_buf[pos], str, max_len - pos);
755 } while (pos < max_len && (str = va_arg(ap, const char *)) != COL_ADD_LSTR_TERMINATOR);
761 /* Adds a vararg list to a packet info string. */
763 col_add_fstr(column_info *cinfo, const gint el, const gchar *format, ...)
768 col_item_t* col_item;
770 if (!CHECK_COL(cinfo, el))
774 max_len = COL_MAX_INFO_LEN;
776 max_len = COL_MAX_LEN;
778 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
779 col_item = &cinfo->columns[i];
780 if (col_item->fmt_matx[el]) {
781 if (col_item->col_fence != 0) {
783 * We will append the string after the fence.
784 * First arrange that we can append, if necessary.
786 COL_CHECK_APPEND(col_item, max_len);
789 * There's no fence, so we can just write to the string.
791 col_item->col_data = col_item->col_buf;
793 va_start(ap, format);
794 ws_vsnprintf(&col_item->col_buf[col_item->col_fence], max_len - col_item->col_fence, format, ap);
801 col_do_append_str(column_info *cinfo, const gint el, const gchar* separator,
806 col_item_t* col_item;
809 max_len = COL_MAX_INFO_LEN;
811 max_len = COL_MAX_LEN;
813 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
814 col_item = &cinfo->columns[i];
815 if (col_item->fmt_matx[el]) {
817 * First arrange that we can append, if necessary.
819 COL_CHECK_APPEND(col_item, max_len);
821 len = col_item->col_buf[0];
824 * If we have a separator, append it if the column isn't empty.
826 if (separator != NULL) {
828 g_strlcat(col_item->col_buf, separator, max_len);
831 g_strlcat(col_item->col_buf, str, max_len);
837 col_append_str(column_info *cinfo, const gint el, const gchar* str)
839 if (!CHECK_COL(cinfo, el))
842 col_do_append_str(cinfo, el, NULL, str);
846 col_append_sep_str(column_info *cinfo, const gint el, const gchar* separator,
849 if (!CHECK_COL(cinfo, el))
852 if (separator == NULL)
853 separator = ", "; /* default */
855 col_do_append_str(cinfo, el, separator, str);
858 /* --------------------------------- */
860 col_has_time_fmt(column_info *cinfo, const gint col)
862 col_item_t* col_item = &cinfo->columns[col];
863 return ((col_item->fmt_matx[COL_CLS_TIME]) ||
864 (col_item->fmt_matx[COL_ABS_TIME]) ||
865 (col_item->fmt_matx[COL_ABS_YMD_TIME]) ||
866 (col_item->fmt_matx[COL_ABS_YDOY_TIME]) ||
867 (col_item->fmt_matx[COL_UTC_TIME]) ||
868 (col_item->fmt_matx[COL_UTC_YMD_TIME]) ||
869 (col_item->fmt_matx[COL_UTC_YDOY_TIME]) ||
870 (col_item->fmt_matx[COL_REL_TIME]) ||
871 (col_item->fmt_matx[COL_DELTA_TIME]) ||
872 (col_item->fmt_matx[COL_DELTA_TIME_DIS]));
876 set_abs_ymd_time(const frame_data *fd, gchar *buf, char *decimal_point, gboolean local)
883 then = fd->abs_ts.secs;
885 tmp = localtime(&then);
891 switch (timestamp_get_precision()) {
892 case TS_PREC_FIXED_SEC:
893 tsprecision = WTAP_TSPREC_SEC;
895 case TS_PREC_FIXED_DSEC:
896 tsprecision = WTAP_TSPREC_DSEC;
898 case TS_PREC_FIXED_CSEC:
899 tsprecision = WTAP_TSPREC_CSEC;
901 case TS_PREC_FIXED_MSEC:
902 tsprecision = WTAP_TSPREC_MSEC;
904 case TS_PREC_FIXED_USEC:
905 tsprecision = WTAP_TSPREC_USEC;
907 case TS_PREC_FIXED_NSEC:
908 tsprecision = WTAP_TSPREC_NSEC;
911 tsprecision = fd->tsprec;
914 g_assert_not_reached();
916 switch (tsprecision) {
917 case WTAP_TSPREC_SEC:
918 ws_snprintf(buf, COL_MAX_LEN,"%04d-%02d-%02d %02d:%02d:%02d",
926 case WTAP_TSPREC_DSEC:
927 ws_snprintf(buf, COL_MAX_LEN,"%04d-%02d-%02d %02d:%02d:%02d%s%01d",
935 fd->abs_ts.nsecs / 100000000);
937 case WTAP_TSPREC_CSEC:
938 ws_snprintf(buf, COL_MAX_LEN,"%04d-%02d-%02d %02d:%02d:%02d%s%02d",
946 fd->abs_ts.nsecs / 10000000);
948 case WTAP_TSPREC_MSEC:
949 ws_snprintf(buf, COL_MAX_LEN, "%04d-%02d-%02d %02d:%02d:%02d%s%03d",
957 fd->abs_ts.nsecs / 1000000);
959 case WTAP_TSPREC_USEC:
960 ws_snprintf(buf, COL_MAX_LEN, "%04d-%02d-%02d %02d:%02d:%02d%s%06d",
968 fd->abs_ts.nsecs / 1000);
970 case WTAP_TSPREC_NSEC:
971 ws_snprintf(buf, COL_MAX_LEN, "%04d-%02d-%02d %02d:%02d:%02d%s%09d",
982 g_assert_not_reached();
990 col_set_abs_ymd_time(const frame_data *fd, column_info *cinfo, const int col)
992 set_abs_ymd_time(fd, cinfo->columns[col].col_buf, col_decimal_point, TRUE);
993 cinfo->col_expr.col_expr[col] = "frame.time";
994 g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->columns[col].col_buf,COL_MAX_LEN);
996 cinfo->columns[col].col_data = cinfo->columns[col].col_buf;
1000 col_set_utc_ymd_time(const frame_data *fd, column_info *cinfo, const int col)
1002 set_abs_ymd_time(fd, cinfo->columns[col].col_buf, col_decimal_point, FALSE);
1003 cinfo->col_expr.col_expr[col] = "frame.time";
1004 g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->columns[col].col_buf,COL_MAX_LEN);
1006 cinfo->columns[col].col_data = cinfo->columns[col].col_buf;
1010 set_abs_ydoy_time(const frame_data *fd, gchar *buf, char *decimal_point, gboolean local)
1017 then = fd->abs_ts.secs;
1019 tmp = localtime(&then);
1021 tmp = gmtime(&then);
1025 switch (timestamp_get_precision()) {
1026 case TS_PREC_FIXED_SEC:
1027 tsprecision = WTAP_TSPREC_SEC;
1029 case TS_PREC_FIXED_DSEC:
1030 tsprecision = WTAP_TSPREC_DSEC;
1032 case TS_PREC_FIXED_CSEC:
1033 tsprecision = WTAP_TSPREC_CSEC;
1035 case TS_PREC_FIXED_MSEC:
1036 tsprecision = WTAP_TSPREC_MSEC;
1038 case TS_PREC_FIXED_USEC:
1039 tsprecision = WTAP_TSPREC_USEC;
1041 case TS_PREC_FIXED_NSEC:
1042 tsprecision = WTAP_TSPREC_NSEC;
1045 tsprecision = fd->tsprec;
1048 g_assert_not_reached();
1050 switch (tsprecision) {
1051 case WTAP_TSPREC_SEC:
1052 ws_snprintf(buf, COL_MAX_LEN,"%04d/%03d %02d:%02d:%02d",
1053 tmp->tm_year + 1900,
1059 case WTAP_TSPREC_DSEC:
1060 ws_snprintf(buf, COL_MAX_LEN,"%04d/%03d %02d:%02d:%02d%s%01d",
1061 tmp->tm_year + 1900,
1067 fd->abs_ts.nsecs / 100000000);
1069 case WTAP_TSPREC_CSEC:
1070 ws_snprintf(buf, COL_MAX_LEN,"%04d/%03d %02d:%02d:%02d%s%02d",
1071 tmp->tm_year + 1900,
1077 fd->abs_ts.nsecs / 10000000);
1079 case WTAP_TSPREC_MSEC:
1080 ws_snprintf(buf, COL_MAX_LEN, "%04d/%03d %02d:%02d:%02d%s%03d",
1081 tmp->tm_year + 1900,
1087 fd->abs_ts.nsecs / 1000000);
1089 case WTAP_TSPREC_USEC:
1090 ws_snprintf(buf, COL_MAX_LEN, "%04d/%03d %02d:%02d:%02d%s%06d",
1091 tmp->tm_year + 1900,
1097 fd->abs_ts.nsecs / 1000);
1099 case WTAP_TSPREC_NSEC:
1100 ws_snprintf(buf, COL_MAX_LEN, "%04d/%03d %02d:%02d:%02d%s%09d",
1101 tmp->tm_year + 1900,
1110 g_assert_not_reached();
1118 col_set_abs_ydoy_time(const frame_data *fd, column_info *cinfo, const int col)
1120 set_abs_ydoy_time(fd, cinfo->columns[col].col_buf, col_decimal_point, TRUE);
1121 cinfo->col_expr.col_expr[col] = "frame.time";
1122 g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->columns[col].col_buf,COL_MAX_LEN);
1124 cinfo->columns[col].col_data = cinfo->columns[col].col_buf;
1128 col_set_utc_ydoy_time(const frame_data *fd, column_info *cinfo, const int col)
1130 set_abs_ydoy_time(fd, cinfo->columns[col].col_buf, col_decimal_point, FALSE);
1131 cinfo->col_expr.col_expr[col] = "frame.time";
1132 g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->columns[col].col_buf,COL_MAX_LEN);
1134 cinfo->columns[col].col_data = cinfo->columns[col].col_buf;
1138 set_time_seconds(const frame_data *fd, const nstime_t *ts, gchar *buf)
1142 switch (timestamp_get_precision()) {
1143 case TS_PREC_FIXED_SEC:
1144 tsprecision = WTAP_TSPREC_SEC;
1146 case TS_PREC_FIXED_DSEC:
1147 tsprecision = WTAP_TSPREC_DSEC;
1149 case TS_PREC_FIXED_CSEC:
1150 tsprecision = WTAP_TSPREC_CSEC;
1152 case TS_PREC_FIXED_MSEC:
1153 tsprecision = WTAP_TSPREC_MSEC;
1155 case TS_PREC_FIXED_USEC:
1156 tsprecision = WTAP_TSPREC_USEC;
1158 case TS_PREC_FIXED_NSEC:
1159 tsprecision = WTAP_TSPREC_NSEC;
1162 tsprecision = fd->tsprec;
1165 g_assert_not_reached();
1167 switch (tsprecision) {
1168 case WTAP_TSPREC_SEC:
1169 display_signed_time(buf, COL_MAX_LEN,
1170 (gint32) ts->secs, ts->nsecs / 1000000000, TO_STR_TIME_RES_T_SECS);
1172 case WTAP_TSPREC_DSEC:
1173 display_signed_time(buf, COL_MAX_LEN,
1174 (gint32) ts->secs, ts->nsecs / 100000000, TO_STR_TIME_RES_T_DSECS);
1176 case WTAP_TSPREC_CSEC:
1177 display_signed_time(buf, COL_MAX_LEN,
1178 (gint32) ts->secs, ts->nsecs / 10000000, TO_STR_TIME_RES_T_CSECS);
1180 case WTAP_TSPREC_MSEC:
1181 display_signed_time(buf, COL_MAX_LEN,
1182 (gint32) ts->secs, ts->nsecs / 1000000, TO_STR_TIME_RES_T_MSECS);
1184 case WTAP_TSPREC_USEC:
1185 display_signed_time(buf, COL_MAX_LEN,
1186 (gint32) ts->secs, ts->nsecs / 1000, TO_STR_TIME_RES_T_USECS);
1188 case WTAP_TSPREC_NSEC:
1189 display_signed_time(buf, COL_MAX_LEN,
1190 (gint32) ts->secs, ts->nsecs, TO_STR_TIME_RES_T_NSECS);
1193 g_assert_not_reached();
1198 set_time_hour_min_sec(const frame_data *fd, const nstime_t *ts, gchar *buf, char *decimal_point)
1200 time_t secs = ts->secs;
1201 long nsecs = (long) ts->nsecs;
1202 gboolean negative = FALSE;
1214 switch (timestamp_get_precision()) {
1215 case TS_PREC_FIXED_SEC:
1216 tsprecision = WTAP_TSPREC_SEC;
1218 case TS_PREC_FIXED_DSEC:
1219 tsprecision = WTAP_TSPREC_DSEC;
1221 case TS_PREC_FIXED_CSEC:
1222 tsprecision = WTAP_TSPREC_CSEC;
1224 case TS_PREC_FIXED_MSEC:
1225 tsprecision = WTAP_TSPREC_MSEC;
1227 case TS_PREC_FIXED_USEC:
1228 tsprecision = WTAP_TSPREC_USEC;
1230 case TS_PREC_FIXED_NSEC:
1231 tsprecision = WTAP_TSPREC_NSEC;
1234 tsprecision = fd->tsprec;
1237 g_assert_not_reached();
1239 switch (tsprecision) {
1240 case WTAP_TSPREC_SEC:
1241 if (secs >= (60*60)) {
1242 ws_snprintf(buf, COL_MAX_LEN, "%s%dh %2dm %2ds",
1243 negative ? "- " : "",
1244 (gint32) secs / (60 * 60),
1245 (gint32) (secs / 60) % 60,
1246 (gint32) secs % 60);
1247 } else if (secs >= 60) {
1248 ws_snprintf(buf, COL_MAX_LEN, "%s%dm %2ds",
1249 negative ? "- " : "",
1251 (gint32) secs % 60);
1253 ws_snprintf(buf, COL_MAX_LEN, "%s%ds",
1254 negative ? "- " : "",
1258 case WTAP_TSPREC_DSEC:
1259 if (secs >= (60*60)) {
1260 ws_snprintf(buf, COL_MAX_LEN, "%s%dh %2dm %2d%s%01lds",
1261 negative ? "- " : "",
1262 (gint32) secs / (60 * 60),
1263 (gint32) (secs / 60) % 60,
1267 } else if (secs >= 60) {
1268 ws_snprintf(buf, COL_MAX_LEN, "%s%dm %2d%s%01lds",
1269 negative ? "- " : "",
1275 ws_snprintf(buf, COL_MAX_LEN, "%s%d%s%01lds",
1276 negative ? "- " : "",
1282 case WTAP_TSPREC_CSEC:
1283 if (secs >= (60*60)) {
1284 ws_snprintf(buf, COL_MAX_LEN, "%s%dh %2dm %2d%s%02lds",
1285 negative ? "- " : "",
1286 (gint32) secs / (60 * 60),
1287 (gint32) (secs / 60) % 60,
1291 } else if (secs >= 60) {
1292 ws_snprintf(buf, COL_MAX_LEN, "%s%dm %2d%s%02lds",
1293 negative ? "- " : "",
1299 ws_snprintf(buf, COL_MAX_LEN, "%s%d%s%02lds",
1300 negative ? "- " : "",
1306 case WTAP_TSPREC_MSEC:
1307 if (secs >= (60*60)) {
1308 ws_snprintf(buf, COL_MAX_LEN, "%s%dh %2dm %2d%s%03lds",
1309 negative ? "- " : "",
1310 (gint32) secs / (60 * 60),
1311 (gint32) (secs / 60) % 60,
1315 } else if (secs >= 60) {
1316 ws_snprintf(buf, COL_MAX_LEN, "%s%dm %2d%s%03lds",
1317 negative ? "- " : "",
1323 ws_snprintf(buf, COL_MAX_LEN, "%s%d%s%03lds",
1324 negative ? "- " : "",
1330 case WTAP_TSPREC_USEC:
1331 if (secs >= (60*60)) {
1332 ws_snprintf(buf, COL_MAX_LEN, "%s%dh %2dm %2d%s%06lds",
1333 negative ? "- " : "",
1334 (gint32) secs / (60 * 60),
1335 (gint32) (secs / 60) % 60,
1339 } else if (secs >= 60) {
1340 ws_snprintf(buf, COL_MAX_LEN, "%s%dm %2d%s%06lds",
1341 negative ? "- " : "",
1347 ws_snprintf(buf, COL_MAX_LEN, "%s%d%s%06lds",
1348 negative ? "- " : "",
1354 case WTAP_TSPREC_NSEC:
1355 if (secs >= (60*60)) {
1356 ws_snprintf(buf, COL_MAX_LEN, "%s%dh %2dm %2d%s%09lds",
1357 negative ? "- " : "",
1358 (gint32) secs / (60 * 60),
1359 (gint32) (secs / 60) % 60,
1363 } else if (secs >= 60) {
1364 ws_snprintf(buf, COL_MAX_LEN, "%s%dm %2d%s%09lds",
1365 negative ? "- " : "",
1371 ws_snprintf(buf, COL_MAX_LEN, "%s%d%s%09lds",
1372 negative ? "- " : "",
1379 g_assert_not_reached();
1384 col_set_rel_time(const frame_data *fd, column_info *cinfo, const int col)
1386 nstime_t del_rel_ts;
1389 cinfo->columns[col].col_buf[0] = '\0';
1393 frame_delta_abs_time(cinfo->epan, fd, fd->frame_ref_num, &del_rel_ts);
1395 switch (timestamp_get_seconds_type()) {
1396 case TS_SECONDS_DEFAULT:
1397 set_time_seconds(fd, &del_rel_ts, cinfo->columns[col].col_buf);
1398 cinfo->col_expr.col_expr[col] = "frame.time_relative";
1399 g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->columns[col].col_buf,COL_MAX_LEN);
1401 case TS_SECONDS_HOUR_MIN_SEC:
1402 set_time_hour_min_sec(fd, &del_rel_ts, cinfo->columns[col].col_buf, col_decimal_point);
1403 cinfo->col_expr.col_expr[col] = "frame.time_relative";
1404 set_time_seconds(fd, &del_rel_ts, cinfo->col_expr.col_expr_val[col]);
1407 g_assert_not_reached();
1409 cinfo->columns[col].col_data = cinfo->columns[col].col_buf;
1413 col_set_delta_time(const frame_data *fd, column_info *cinfo, const int col)
1415 nstime_t del_cap_ts;
1417 frame_delta_abs_time(cinfo->epan, fd, fd->num - 1, &del_cap_ts);
1419 switch (timestamp_get_seconds_type()) {
1420 case TS_SECONDS_DEFAULT:
1421 set_time_seconds(fd, &del_cap_ts, cinfo->columns[col].col_buf);
1422 cinfo->col_expr.col_expr[col] = "frame.time_delta";
1423 g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->columns[col].col_buf,COL_MAX_LEN);
1425 case TS_SECONDS_HOUR_MIN_SEC:
1426 set_time_hour_min_sec(fd, &del_cap_ts, cinfo->columns[col].col_buf, col_decimal_point);
1427 cinfo->col_expr.col_expr[col] = "frame.time_delta";
1428 set_time_seconds(fd, &del_cap_ts, cinfo->col_expr.col_expr_val[col]);
1431 g_assert_not_reached();
1434 cinfo->columns[col].col_data = cinfo->columns[col].col_buf;
1438 col_set_delta_time_dis(const frame_data *fd, column_info *cinfo, const int col)
1440 nstime_t del_dis_ts;
1443 cinfo->columns[col].col_buf[0] = '\0';
1447 frame_delta_abs_time(cinfo->epan, fd, fd->prev_dis_num, &del_dis_ts);
1449 switch (timestamp_get_seconds_type()) {
1450 case TS_SECONDS_DEFAULT:
1451 set_time_seconds(fd, &del_dis_ts, cinfo->columns[col].col_buf);
1452 cinfo->col_expr.col_expr[col] = "frame.time_delta_displayed";
1453 g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->columns[col].col_buf,COL_MAX_LEN);
1455 case TS_SECONDS_HOUR_MIN_SEC:
1456 set_time_hour_min_sec(fd, &del_dis_ts, cinfo->columns[col].col_buf, col_decimal_point);
1457 cinfo->col_expr.col_expr[col] = "frame.time_delta_displayed";
1458 set_time_seconds(fd, &del_dis_ts, cinfo->col_expr.col_expr_val[col]);
1461 g_assert_not_reached();
1464 cinfo->columns[col].col_data = cinfo->columns[col].col_buf;
1468 set_abs_time(const frame_data *fd, gchar *buf, char *decimal_point, gboolean local)
1475 then = fd->abs_ts.secs;
1477 tmp = localtime(&then);
1479 tmp = gmtime(&then);
1483 switch (timestamp_get_precision()) {
1484 case TS_PREC_FIXED_SEC:
1485 tsprecision = WTAP_TSPREC_SEC;
1487 case TS_PREC_FIXED_DSEC:
1488 tsprecision = WTAP_TSPREC_DSEC;
1490 case TS_PREC_FIXED_CSEC:
1491 tsprecision = WTAP_TSPREC_CSEC;
1493 case TS_PREC_FIXED_MSEC:
1494 tsprecision = WTAP_TSPREC_MSEC;
1496 case TS_PREC_FIXED_USEC:
1497 tsprecision = WTAP_TSPREC_USEC;
1499 case TS_PREC_FIXED_NSEC:
1500 tsprecision = WTAP_TSPREC_NSEC;
1503 tsprecision = fd->tsprec;
1506 g_assert_not_reached();
1508 switch (tsprecision) {
1509 case WTAP_TSPREC_SEC:
1510 ws_snprintf(buf, COL_MAX_LEN,"%02d:%02d:%02d",
1515 case WTAP_TSPREC_DSEC:
1516 ws_snprintf(buf, COL_MAX_LEN,"%02d:%02d:%02d%s%01d",
1521 fd->abs_ts.nsecs / 100000000);
1523 case WTAP_TSPREC_CSEC:
1524 ws_snprintf(buf, COL_MAX_LEN,"%02d:%02d:%02d%s%02d",
1529 fd->abs_ts.nsecs / 10000000);
1531 case WTAP_TSPREC_MSEC:
1532 ws_snprintf(buf, COL_MAX_LEN,"%02d:%02d:%02d%s%03d",
1537 fd->abs_ts.nsecs / 1000000);
1539 case WTAP_TSPREC_USEC:
1540 ws_snprintf(buf, COL_MAX_LEN,"%02d:%02d:%02d%s%06d",
1545 fd->abs_ts.nsecs / 1000);
1547 case WTAP_TSPREC_NSEC:
1548 ws_snprintf(buf, COL_MAX_LEN, "%02d:%02d:%02d%s%09d",
1556 g_assert_not_reached();
1565 col_set_abs_time(const frame_data *fd, column_info *cinfo, const int col)
1567 set_abs_time(fd, cinfo->columns[col].col_buf, col_decimal_point, TRUE);
1568 cinfo->col_expr.col_expr[col] = "frame.time";
1569 g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->columns[col].col_buf,COL_MAX_LEN);
1571 cinfo->columns[col].col_data = cinfo->columns[col].col_buf;
1575 col_set_utc_time(const frame_data *fd, column_info *cinfo, const int col)
1577 set_abs_time(fd, cinfo->columns[col].col_buf, col_decimal_point, FALSE);
1578 cinfo->col_expr.col_expr[col] = "frame.time";
1579 g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->columns[col].col_buf,COL_MAX_LEN);
1581 cinfo->columns[col].col_data = cinfo->columns[col].col_buf;
1585 set_epoch_time(const frame_data *fd, gchar *buf)
1593 switch (timestamp_get_precision()) {
1594 case TS_PREC_FIXED_SEC:
1595 tsprecision = WTAP_TSPREC_SEC;
1597 case TS_PREC_FIXED_DSEC:
1598 tsprecision = WTAP_TSPREC_DSEC;
1600 case TS_PREC_FIXED_CSEC:
1601 tsprecision = WTAP_TSPREC_CSEC;
1603 case TS_PREC_FIXED_MSEC:
1604 tsprecision = WTAP_TSPREC_MSEC;
1606 case TS_PREC_FIXED_USEC:
1607 tsprecision = WTAP_TSPREC_USEC;
1609 case TS_PREC_FIXED_NSEC:
1610 tsprecision = WTAP_TSPREC_NSEC;
1613 tsprecision = fd->tsprec;
1616 g_assert_not_reached();
1618 switch (tsprecision) {
1619 case WTAP_TSPREC_SEC:
1620 display_epoch_time(buf, COL_MAX_LEN,
1621 fd->abs_ts.secs, fd->abs_ts.nsecs / 1000000000, TO_STR_TIME_RES_T_SECS);
1623 case WTAP_TSPREC_DSEC:
1624 display_epoch_time(buf, COL_MAX_LEN,
1625 fd->abs_ts.secs, fd->abs_ts.nsecs / 100000000, TO_STR_TIME_RES_T_DSECS);
1627 case WTAP_TSPREC_CSEC:
1628 display_epoch_time(buf, COL_MAX_LEN,
1629 fd->abs_ts.secs, fd->abs_ts.nsecs / 10000000, TO_STR_TIME_RES_T_CSECS);
1631 case WTAP_TSPREC_MSEC:
1632 display_epoch_time(buf, COL_MAX_LEN,
1633 fd->abs_ts.secs, fd->abs_ts.nsecs / 1000000, TO_STR_TIME_RES_T_MSECS);
1635 case WTAP_TSPREC_USEC:
1636 display_epoch_time(buf, COL_MAX_LEN,
1637 fd->abs_ts.secs, fd->abs_ts.nsecs / 1000, TO_STR_TIME_RES_T_USECS);
1639 case WTAP_TSPREC_NSEC:
1640 display_epoch_time(buf, COL_MAX_LEN,
1641 fd->abs_ts.secs, fd->abs_ts.nsecs, TO_STR_TIME_RES_T_NSECS);
1644 g_assert_not_reached();
1650 col_set_epoch_time(const frame_data *fd, column_info *cinfo, const int col)
1652 if (set_epoch_time(fd, cinfo->columns[col].col_buf)) {
1653 cinfo->col_expr.col_expr[col] = "frame.time_delta";
1654 g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->columns[col].col_buf,COL_MAX_LEN);
1656 cinfo->columns[col].col_data = cinfo->columns[col].col_buf;
1660 set_fd_time(const epan_t *epan, frame_data *fd, gchar *buf)
1663 switch (timestamp_get_type()) {
1665 set_abs_time(fd, buf, col_decimal_point, TRUE);
1668 case TS_ABSOLUTE_WITH_YMD:
1669 set_abs_ymd_time(fd, buf, col_decimal_point, TRUE);
1672 case TS_ABSOLUTE_WITH_YDOY:
1673 set_abs_ydoy_time(fd, buf, col_decimal_point, TRUE);
1678 nstime_t del_rel_ts;
1680 frame_delta_abs_time(epan, fd, fd->frame_ref_num, &del_rel_ts);
1682 switch (timestamp_get_seconds_type()) {
1683 case TS_SECONDS_DEFAULT:
1684 set_time_seconds(fd, &del_rel_ts, buf);
1686 case TS_SECONDS_HOUR_MIN_SEC:
1687 set_time_seconds(fd, &del_rel_ts, buf);
1690 g_assert_not_reached();
1699 nstime_t del_cap_ts;
1701 frame_delta_abs_time(epan, fd, fd->num - 1, &del_cap_ts);
1703 switch (timestamp_get_seconds_type()) {
1704 case TS_SECONDS_DEFAULT:
1705 set_time_seconds(fd, &del_cap_ts, buf);
1707 case TS_SECONDS_HOUR_MIN_SEC:
1708 set_time_hour_min_sec(fd, &del_cap_ts, buf, col_decimal_point);
1711 g_assert_not_reached();
1720 nstime_t del_dis_ts;
1722 frame_delta_abs_time(epan, fd, fd->prev_dis_num, &del_dis_ts);
1724 switch (timestamp_get_seconds_type()) {
1725 case TS_SECONDS_DEFAULT:
1726 set_time_seconds(fd, &del_dis_ts, buf);
1728 case TS_SECONDS_HOUR_MIN_SEC:
1729 set_time_hour_min_sec(fd, &del_dis_ts, buf, col_decimal_point);
1732 g_assert_not_reached();
1740 set_epoch_time(fd, buf);
1744 set_abs_time(fd, buf, col_decimal_point, FALSE);
1747 case TS_UTC_WITH_YMD:
1748 set_abs_ymd_time(fd, buf, col_decimal_point, FALSE);
1751 case TS_UTC_WITH_YDOY:
1752 set_abs_ydoy_time(fd, buf, col_decimal_point, FALSE);
1756 /* code is missing for this case, but I don't know which [jmayer20051219] */
1763 col_set_cls_time(const frame_data *fd, column_info *cinfo, const gint col)
1765 switch (timestamp_get_type()) {
1767 col_set_abs_time(fd, cinfo, col);
1770 case TS_ABSOLUTE_WITH_YMD:
1771 col_set_abs_ymd_time(fd, cinfo, col);
1774 case TS_ABSOLUTE_WITH_YDOY:
1775 col_set_abs_ydoy_time(fd, cinfo, col);
1779 col_set_rel_time(fd, cinfo, col);
1783 col_set_delta_time(fd, cinfo, col);
1787 col_set_delta_time_dis(fd, cinfo, col);
1791 col_set_epoch_time(fd, cinfo, col);
1795 col_set_utc_time(fd, cinfo, col);
1798 case TS_UTC_WITH_YMD:
1799 col_set_utc_ymd_time(fd, cinfo, col);
1802 case TS_UTC_WITH_YDOY:
1803 col_set_utc_ydoy_time(fd, cinfo, col);
1807 /* code is missing for this case, but I don't know which [jmayer20051219] */
1808 g_assert_not_reached();
1813 /* Set the format of the variable time format. */
1815 col_set_fmt_time(const frame_data *fd, column_info *cinfo, const gint fmt, const gint col)
1817 COL_CHECK_REF_TIME(fd, cinfo->columns[col].col_buf);
1821 col_set_cls_time(fd, cinfo, col);
1825 col_set_abs_time(fd, cinfo, col);
1828 case COL_ABS_YMD_TIME:
1829 col_set_abs_ymd_time(fd, cinfo, col);
1832 case COL_ABS_YDOY_TIME:
1833 col_set_abs_ydoy_time(fd, cinfo, col);
1837 col_set_rel_time(fd, cinfo, col);
1840 case COL_DELTA_TIME:
1841 col_set_delta_time(fd, cinfo, col);
1844 case COL_DELTA_TIME_DIS:
1845 col_set_delta_time_dis(fd, cinfo, col);
1849 col_set_utc_time(fd, cinfo, col);
1852 case COL_UTC_YMD_TIME:
1853 col_set_utc_ymd_time(fd, cinfo, col);
1856 case COL_UTC_YDOY_TIME:
1857 col_set_utc_ydoy_time(fd, cinfo, col);
1861 g_assert_not_reached();
1866 /* --------------------------- */
1867 /* Set the given (relative) time to a column element.
1869 * Used by dissectors to set the time in a column
1871 * @param cinfo the current packet row
1872 * @param el the column to use, e.g. COL_INFO
1873 * @param ts the time to set in the column
1874 * @param fieldname the fieldname to use for creating a filter (when
1875 * applying/preparing/copying as filter)
1878 col_set_time(column_info *cinfo, const gint el, const nstime_t *ts, const char *fieldname)
1881 col_item_t* col_item;
1883 if (!CHECK_COL(cinfo, el))
1886 /** @todo TODO: We don't respect fd->ref_time (no way to access 'fd')
1887 COL_CHECK_REF_TIME(fd, buf);
1890 for (col = cinfo->col_first[el]; col <= cinfo->col_last[el]; col++) {
1891 col_item = &cinfo->columns[col];
1892 if (col_item->fmt_matx[el]) {
1893 switch (timestamp_get_precision()) {
1894 case TS_PREC_FIXED_SEC:
1895 display_signed_time(col_item->col_buf, COL_MAX_LEN,
1896 (gint32) ts->secs, ts->nsecs / 1000000000, TO_STR_TIME_RES_T_SECS);
1898 case TS_PREC_FIXED_DSEC:
1899 display_signed_time(col_item->col_buf, COL_MAX_LEN,
1900 (gint32) ts->secs, ts->nsecs / 100000000, TO_STR_TIME_RES_T_DSECS);
1902 case TS_PREC_FIXED_CSEC:
1903 display_signed_time(col_item->col_buf, COL_MAX_LEN,
1904 (gint32) ts->secs, ts->nsecs / 10000000, TO_STR_TIME_RES_T_CSECS);
1906 case TS_PREC_FIXED_MSEC:
1907 display_signed_time(col_item->col_buf, COL_MAX_LEN,
1908 (gint32) ts->secs, ts->nsecs / 1000000, TO_STR_TIME_RES_T_MSECS);
1910 case TS_PREC_FIXED_USEC:
1911 display_signed_time(col_item->col_buf, COL_MAX_LEN,
1912 (gint32) ts->secs, ts->nsecs / 1000, TO_STR_TIME_RES_T_USECS);
1914 case TS_PREC_FIXED_NSEC:
1915 case TS_PREC_AUTO: /* default to maximum */
1916 display_signed_time(col_item->col_buf, COL_MAX_LEN,
1917 (gint32) ts->secs, ts->nsecs, TO_STR_TIME_RES_T_NSECS);
1920 g_assert_not_reached();
1922 col_item->col_data = col_item->col_buf;
1923 cinfo->col_expr.col_expr[col] = fieldname;
1924 g_strlcpy(cinfo->col_expr.col_expr_val[col],col_item->col_buf,COL_MAX_LEN);
1930 col_set_addr(packet_info *pinfo, const int col, const address *addr, const gboolean is_src,
1931 const gboolean fill_col_exprs, const gboolean res)
1934 col_item_t* col_item = &pinfo->cinfo->columns[col];
1936 if (addr->type == AT_NONE) {
1937 /* No address, nothing to do */
1941 if (res && (name = address_to_name(addr)) != NULL)
1942 col_item->col_data = name;
1944 col_item->col_data = col_item->col_buf;
1945 address_to_str_buf(addr, col_item->col_buf, COL_MAX_LEN);
1948 if (!fill_col_exprs)
1951 pinfo->cinfo->col_expr.col_expr[col] = address_type_column_filter_string(addr, is_src);
1952 /* For address types that have a filter, create a string */
1953 if (strlen(pinfo->cinfo->col_expr.col_expr[col]) > 0)
1954 address_to_str_buf(addr, pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN);
1957 /* ------------------------ */
1959 col_set_port(packet_info *pinfo, const int col, const gboolean is_res, const gboolean is_src, const gboolean fill_col_exprs _U_)
1962 col_item_t* col_item = &pinfo->cinfo->columns[col];
1965 port = pinfo->srcport;
1967 port = pinfo->destport;
1969 /* TODO: Use fill_col_exprs */
1971 switch (pinfo->ptype) {
1974 g_strlcpy(col_item->col_buf, sctp_port_to_display(pinfo->pool, port), COL_MAX_LEN);
1976 guint32_to_str_buf(port, col_item->col_buf, COL_MAX_LEN);
1980 guint32_to_str_buf(port, pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN);
1982 g_strlcpy(col_item->col_buf, tcp_port_to_display(pinfo->pool, port), COL_MAX_LEN);
1984 g_strlcpy(col_item->col_buf, pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN);
1986 pinfo->cinfo->col_expr.col_expr[col] = "tcp.srcport";
1988 pinfo->cinfo->col_expr.col_expr[col] = "tcp.dstport";
1992 guint32_to_str_buf(port, pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN);
1994 g_strlcpy(col_item->col_buf, udp_port_to_display(pinfo->pool, port), COL_MAX_LEN);
1996 g_strlcpy(col_item->col_buf, pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN);
1998 pinfo->cinfo->col_expr.col_expr[col] = "udp.srcport";
2000 pinfo->cinfo->col_expr.col_expr[col] = "udp.dstport";
2005 pinfo->cinfo->col_expr.col_expr[col] = "ddp.src_socket";
2007 pinfo->cinfo->col_expr.col_expr[col] = "ddp.dst_socket";
2008 guint32_to_str_buf(port, pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN);
2009 g_strlcpy(col_item->col_buf, pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN);
2013 /* XXX - resolve IPX socket numbers */
2014 ws_snprintf(col_item->col_buf, COL_MAX_LEN, "0x%04x", port);
2015 g_strlcpy(pinfo->cinfo->col_expr.col_expr_val[col], col_item->col_buf,COL_MAX_LEN);
2017 pinfo->cinfo->col_expr.col_expr[col] = "ipx.src.socket";
2019 pinfo->cinfo->col_expr.col_expr[col] = "ipx.dst.socket";
2023 /* XXX - resolve IDP socket numbers */
2024 ws_snprintf(col_item->col_buf, COL_MAX_LEN, "0x%04x", port);
2025 g_strlcpy(pinfo->cinfo->col_expr.col_expr_val[col], col_item->col_buf,COL_MAX_LEN);
2027 pinfo->cinfo->col_expr.col_expr[col] = "idp.src.socket";
2029 pinfo->cinfo->col_expr.col_expr[col] = "idp.dst.socket";
2033 /* XXX - resolve USB endpoint numbers */
2034 ws_snprintf(col_item->col_buf, COL_MAX_LEN, "0x%08x", port);
2035 g_strlcpy(pinfo->cinfo->col_expr.col_expr_val[col], col_item->col_buf,COL_MAX_LEN);
2037 pinfo->cinfo->col_expr.col_expr[col] = "usb.src.endpoint";
2039 pinfo->cinfo->col_expr.col_expr[col] = "usb.dst.endpoint";
2045 col_item->col_data = col_item->col_buf;
2049 col_based_on_frame_data(column_info *cinfo, const gint col)
2052 g_assert(col < cinfo->num_cols);
2054 switch (cinfo->columns[col].col_fmt) {
2058 case COL_ABS_YMD_TIME:
2059 case COL_ABS_YDOY_TIME:
2061 case COL_UTC_YMD_TIME:
2062 case COL_UTC_YDOY_TIME:
2064 case COL_DELTA_TIME:
2065 case COL_DELTA_TIME_DIS:
2066 case COL_PACKET_LENGTH:
2067 case COL_CUMULATIVE_BYTES:
2076 col_fill_in_frame_data(const frame_data *fd, column_info *cinfo, const gint col, const gboolean fill_col_exprs)
2078 col_item_t* col_item = &cinfo->columns[col];
2080 switch (col_item->col_fmt) {
2082 guint32_to_str_buf(fd->num, col_item->col_buf, COL_MAX_LEN);
2083 col_item->col_data = col_item->col_buf;
2088 case COL_ABS_YMD_TIME:
2089 case COL_ABS_YDOY_TIME:
2091 case COL_UTC_YMD_TIME:
2092 case COL_UTC_YDOY_TIME:
2094 case COL_DELTA_TIME:
2095 case COL_DELTA_TIME_DIS:
2096 /* TODO: Pass on fill_col_exprs */
2097 col_set_fmt_time(fd, cinfo, col_item->col_fmt, col);
2100 case COL_PACKET_LENGTH:
2101 guint32_to_str_buf(fd->pkt_len, col_item->col_buf, COL_MAX_LEN);
2102 col_item->col_data = col_item->col_buf;
2105 case COL_CUMULATIVE_BYTES:
2106 guint32_to_str_buf(fd->cum_bytes, col_item->col_buf, COL_MAX_LEN);
2107 col_item->col_data = col_item->col_buf;
2114 if (!fill_col_exprs)
2117 switch (col_item->col_fmt) {
2119 cinfo->col_expr.col_expr[col] = "frame.number";
2120 g_strlcpy(cinfo->col_expr.col_expr_val[col], col_item->col_buf, COL_MAX_LEN);
2125 case COL_ABS_YMD_TIME:
2126 case COL_ABS_YDOY_TIME:
2128 case COL_UTC_YMD_TIME:
2129 case COL_UTC_YDOY_TIME:
2131 case COL_DELTA_TIME:
2132 case COL_DELTA_TIME_DIS:
2133 /* Already handled above */
2136 case COL_PACKET_LENGTH:
2137 cinfo->col_expr.col_expr[col] = "frame.len";
2138 g_strlcpy(cinfo->col_expr.col_expr_val[col], col_item->col_buf, COL_MAX_LEN);
2141 case COL_CUMULATIVE_BYTES:
2150 col_fill_in(packet_info *pinfo, const gboolean fill_col_exprs, const gboolean fill_fd_colums)
2153 col_item_t* col_item;
2158 for (i = 0; i < pinfo->cinfo->num_cols; i++) {
2159 col_item = &pinfo->cinfo->columns[i];
2160 if (col_based_on_frame_data(pinfo->cinfo, i)) {
2162 col_fill_in_frame_data(pinfo->fd, pinfo->cinfo, i, fill_col_exprs);
2164 switch (col_item->col_fmt) {
2166 case COL_RES_SRC: /* COL_DEF_SRC is currently just like COL_RES_SRC */
2167 col_set_addr(pinfo, i, &pinfo->src, TRUE, fill_col_exprs, TRUE);
2171 col_set_addr(pinfo, i, &pinfo->src, TRUE, fill_col_exprs, FALSE);
2174 case COL_DEF_DL_SRC:
2175 case COL_RES_DL_SRC:
2176 col_set_addr(pinfo, i, &pinfo->dl_src, TRUE, fill_col_exprs, TRUE);
2179 case COL_UNRES_DL_SRC:
2180 col_set_addr(pinfo, i, &pinfo->dl_src, TRUE, fill_col_exprs, FALSE);
2183 case COL_DEF_NET_SRC:
2184 case COL_RES_NET_SRC:
2185 col_set_addr(pinfo, i, &pinfo->net_src, TRUE, fill_col_exprs, TRUE);
2188 case COL_UNRES_NET_SRC:
2189 col_set_addr(pinfo, i, &pinfo->net_src, TRUE, fill_col_exprs, FALSE);
2193 case COL_RES_DST: /* COL_DEF_DST is currently just like COL_RES_DST */
2194 col_set_addr(pinfo, i, &pinfo->dst, FALSE, fill_col_exprs, TRUE);
2198 col_set_addr(pinfo, i, &pinfo->dst, FALSE, fill_col_exprs, FALSE);
2201 case COL_DEF_DL_DST:
2202 case COL_RES_DL_DST:
2203 col_set_addr(pinfo, i, &pinfo->dl_dst, FALSE, fill_col_exprs, TRUE);
2206 case COL_UNRES_DL_DST:
2207 col_set_addr(pinfo, i, &pinfo->dl_dst, FALSE, fill_col_exprs, FALSE);
2210 case COL_DEF_NET_DST:
2211 case COL_RES_NET_DST:
2212 col_set_addr(pinfo, i, &pinfo->net_dst, FALSE, fill_col_exprs, TRUE);
2215 case COL_UNRES_NET_DST:
2216 col_set_addr(pinfo, i, &pinfo->net_dst, FALSE, fill_col_exprs, FALSE);
2219 case COL_DEF_SRC_PORT:
2220 case COL_RES_SRC_PORT: /* COL_DEF_SRC_PORT is currently just like COL_RES_SRC_PORT */
2221 col_set_port(pinfo, i, TRUE, TRUE, fill_col_exprs);
2224 case COL_UNRES_SRC_PORT:
2225 col_set_port(pinfo, i, FALSE, TRUE, fill_col_exprs);
2228 case COL_DEF_DST_PORT:
2229 case COL_RES_DST_PORT: /* COL_DEF_DST_PORT is currently just like COL_RES_DST_PORT */
2230 col_set_port(pinfo, i, TRUE, FALSE, fill_col_exprs);
2233 case COL_UNRES_DST_PORT:
2234 col_set_port(pinfo, i, FALSE, FALSE, fill_col_exprs);
2237 case NUM_COL_FMTS: /* keep compiler happy - shouldn't get here */
2238 g_assert_not_reached();
2241 if (col_item->col_fmt >= NUM_COL_FMTS) {
2242 g_assert_not_reached();
2245 * Formatting handled by col_custom_set_edt() (COL_CUSTOM), expert.c
2246 * (COL_EXPERT), or individual dissectors.
2255 * Fill in columns if we got an error reading the packet.
2256 * We set most columns to "???", fill in columns that don't need data read
2257 * from the file, and set the Info column to an error message.
2260 col_fill_in_error(column_info *cinfo, frame_data *fdata, const gboolean fill_col_exprs, const gboolean fill_fd_colums)
2263 col_item_t* col_item;
2268 for (i = 0; i < cinfo->num_cols; i++) {
2269 col_item = &cinfo->columns[i];
2270 if (col_based_on_frame_data(cinfo, i)) {
2272 col_fill_in_frame_data(fdata, cinfo, i, fill_col_exprs);
2273 } else if (col_item->col_fmt == COL_INFO) {
2274 /* XXX - say more than this */
2275 col_item->col_data = "Read error";
2277 if (col_item->col_fmt >= NUM_COL_FMTS) {
2278 g_assert_not_reached();
2281 * No dissection was done, and these columns are set as the
2282 * result of the dissection, so....
2284 col_item->col_data = "???";
2290 gboolean col_data_changed(void) {
2291 gboolean cur_cdc = col_data_changed_;
2292 col_data_changed_ = FALSE;
2301 * indent-tabs-mode: nil
2304 * ex: set shiftwidth=2 tabstop=8 expandtab:
2305 * :indentSize=2:tabSize=8:noTabs=true: