2 * Routines for column utilities.
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 #include "column-utils.h"
29 #include "timestamp.h"
31 #include "packet_info.h"
32 #include "wsutil/pint.h"
33 #include "addr_resolv.h"
34 #include "address_types.h"
36 #include "osi-utils.h"
37 #include "value_string.h"
38 #include "column-info.h"
41 #include <epan/strutil.h>
42 #include <epan/epan.h>
43 #include <epan/dfilter/dfilter.h>
44 #include <wsutil/utf8_entities.h>
47 #include <epan/wslua/wslua.h>
50 /* Allocate all the data structures for constructing column data, given
51 the number of columns. */
53 col_setup(column_info *cinfo, const gint num_cols)
57 cinfo->num_cols = num_cols;
58 cinfo->columns = g_new(col_item_t, num_cols);
59 cinfo->col_first = g_new(int, NUM_COL_FMTS);
60 cinfo->col_last = g_new(int, NUM_COL_FMTS);
61 for (i = 0; i < num_cols; i++) {
62 cinfo->columns[i].col_custom_fields_ids = NULL;
64 cinfo->col_expr.col_expr = g_new(const gchar*, num_cols + 1);
65 cinfo->col_expr.col_expr_val = g_new(gchar*, num_cols + 1);
67 for (i = 0; i < NUM_COL_FMTS; i++) {
68 cinfo->col_first[i] = -1;
69 cinfo->col_last[i] = -1;
71 cinfo->prime_regex = g_regex_new(COL_CUSTOM_PRIME_REGEX,
72 G_REGEX_ANCHORED, G_REGEX_MATCH_ANCHORED, NULL);
76 col_custom_ids_free_wrapper(gpointer data, gpointer user_data _U_)
82 col_custom_fields_ids_free(GSList** custom_fields_id)
84 if (*custom_fields_id != NULL) {
85 g_slist_foreach(*custom_fields_id, col_custom_ids_free_wrapper, NULL);
86 g_slist_free(*custom_fields_id);
88 *custom_fields_id = NULL;
91 /* Cleanup all the data structures for constructing column data; undoes
92 the allocations that col_setup() does. */
94 col_cleanup(column_info *cinfo)
99 for (i = 0; i < cinfo->num_cols; i++) {
100 col_item = &cinfo->columns[i];
101 g_free(col_item->fmt_matx);
102 g_free(col_item->col_title);
103 g_free(col_item->col_custom_fields);
104 dfilter_free(col_item->col_custom_dfilter);
105 /* col_item->col_data points to col_buf or static memory */
106 g_free(col_item->col_buf);
107 g_free(cinfo->col_expr.col_expr_val[i]);
108 col_custom_fields_ids_free(&col_item->col_custom_fields_ids);
111 g_free(cinfo->columns);
112 g_free(cinfo->col_first);
113 g_free(cinfo->col_last);
115 * XXX - MSVC doesn't correctly handle the "const" qualifier; it thinks
116 * "const XXX **" means "pointer to const pointer to XXX", i.e. that
117 * it's a pointer to something that's "const"ant, not "pointer to
118 * pointer to const XXX", i.e. that it's a pointer to a pointer to
119 * something that's "const"ant. Cast its bogus complaints away.
121 g_free((gchar **)cinfo->col_expr.col_expr);
122 g_free(cinfo->col_expr.col_expr_val);
123 g_regex_unref(cinfo->prime_regex);
126 /* Initialize the data structures for constructing column data. */
128 col_init(column_info *cinfo, const struct epan_session *epan)
131 col_item_t* col_item;
136 for (i = 0; i < cinfo->num_cols; i++) {
137 col_item = &cinfo->columns[i];
138 col_item->col_buf[0] = '\0';
139 col_item->col_data = col_item->col_buf;
140 col_item->col_fence = 0;
141 cinfo->col_expr.col_expr[i] = "";
142 cinfo->col_expr.col_expr_val[i][0] = '\0';
144 cinfo->writable = TRUE;
148 #define COL_GET_WRITABLE(cinfo) (cinfo ? cinfo->writable : FALSE)
151 col_get_writable(column_info *cinfo)
153 return COL_GET_WRITABLE(cinfo);
157 col_set_writable(column_info *cinfo, const gboolean writable)
160 cinfo->writable = writable;
163 /* Checks to see if a particular packet information element is needed for the packet list */
164 #define CHECK_COL(cinfo, el) \
165 /* We are constructing columns, and they're writable */ \
166 (COL_GET_WRITABLE(cinfo) && \
167 /* There is at least one column in that format */ \
168 ((cinfo)->col_first[el] >= 0))
170 /* Sets the fence for a column to be at the end of the column. */
172 col_set_fence(column_info *cinfo, const gint el)
175 col_item_t* col_item;
177 if (!CHECK_COL(cinfo, el))
180 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
181 col_item = &cinfo->columns[i];
182 if (col_item->fmt_matx[el]) {
183 col_item->col_fence = (int)strlen(col_item->col_data);
188 /* Clear the fence for a column. */
190 col_clear_fence(column_info *cinfo, const gint el)
193 col_item_t* col_item;
195 if (!CHECK_COL(cinfo, el))
198 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
199 col_item = &cinfo->columns[i];
200 if (col_item->fmt_matx[el]) {
201 col_item->col_fence = 0;
206 /* Gets the text of a column */
208 col_get_text(column_info *cinfo, const gint el)
211 const gchar* text = NULL;
212 col_item_t* col_item;
214 if (!(cinfo && (cinfo)->col_first[el] >= 0)) {
218 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
219 col_item = &cinfo->columns[i];
220 if (col_item->fmt_matx[el]) {
221 text = (col_item->col_data);
228 /* Use this to clear out a column, especially if you're going to be
229 appending to it later; at least on some platforms, it's more
230 efficient than using "col_add_str()" with a null string, and
231 more efficient than "col_set_str()" with a null string if you
232 later append to it, as the later append will cause a string
235 col_clear(column_info *cinfo, const gint el)
238 col_item_t* col_item;
240 if (!CHECK_COL(cinfo, el))
243 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
244 col_item = &cinfo->columns[i];
245 if (col_item->fmt_matx[el]) {
247 * At this point, either
249 * 1) col_data[i] is equal to col_buf[i], in which case we
250 * don't have to worry about copying col_data[i] to
253 * 2) col_data[i] isn't equal to col_buf[i], in which case
254 * the only thing that's been done to the column is
255 * "col_set_str()" calls and possibly "col_set_fence()"
256 * calls, in which case the fence is either unset and
257 * at the beginning of the string or set and at the end
258 * of the string - if it's at the beginning, we're just
259 * going to clear the column, and if it's at the end,
260 * we don't do anything.
262 if (col_item->col_buf == col_item->col_data || col_item->col_fence == 0) {
264 * The fence isn't at the end of the column, or the column wasn't
265 * last set with "col_set_str()", so clear the column out.
267 col_item->col_buf[col_item->col_fence] = '\0';
268 col_item->col_data = col_item->col_buf;
270 cinfo->col_expr.col_expr[i] = "";
271 cinfo->col_expr.col_expr_val[i][0] = '\0';
276 #define COL_CHECK_APPEND(col_item, max_len) \
277 if (col_item->col_data != col_item->col_buf) { \
278 /* This was set with "col_set_str()"; copy the string they \
279 set it to into the buffer, so we can append to it. */ \
280 g_strlcpy(col_item->col_buf, col_item->col_data, max_len); \
281 col_item->col_data = col_item->col_buf; \
284 #define COL_CHECK_REF_TIME(fd, buf) \
285 if (fd->flags.ref_time) { \
286 g_strlcpy(buf, "*REF*", COL_MAX_LEN ); \
290 /* The same as CHECK_COL(), but without the check to see if the column is writable. */
291 #define HAVE_CUSTOM_COLS(cinfo) ((cinfo) && (cinfo)->col_first[COL_CUSTOM] >= 0)
294 have_custom_cols(column_info *cinfo)
296 return HAVE_CUSTOM_COLS(cinfo);
300 have_field_extractors(void)
303 return wslua_has_field_extractors();
309 /* search in edt tree custom fields */
310 void col_custom_set_edt(epan_dissect_t *edt, column_info *cinfo)
313 col_item_t* col_item;
315 if (!HAVE_CUSTOM_COLS(cinfo))
318 for (i = cinfo->col_first[COL_CUSTOM];
319 i <= cinfo->col_last[COL_CUSTOM]; i++) {
320 col_item = &cinfo->columns[i];
321 if (col_item->fmt_matx[COL_CUSTOM] &&
322 col_item->col_custom_fields &&
323 col_item->col_custom_fields_ids) {
324 col_item->col_data = col_item->col_buf;
325 cinfo->col_expr.col_expr[i] = epan_custom_set(edt, col_item->col_custom_fields_ids,
326 col_item->col_custom_occurrence,
328 cinfo->col_expr.col_expr_val[i],
335 col_custom_prime_edt(epan_dissect_t *edt, column_info *cinfo)
338 col_item_t* col_item;
340 if (!HAVE_CUSTOM_COLS(cinfo))
343 for (i = cinfo->col_first[COL_CUSTOM];
344 i <= cinfo->col_last[COL_CUSTOM]; i++) {
345 col_item = &cinfo->columns[i];
347 if (col_item->fmt_matx[COL_CUSTOM] &&
348 col_item->col_custom_dfilter) {
349 epan_dissect_prime_dfilter(edt, col_item->col_custom_dfilter);
355 col_append_lstr(column_info *cinfo, const gint el, const gchar *str1, ...)
361 col_item_t* col_item;
363 if (!CHECK_COL(cinfo, el))
367 max_len = COL_MAX_INFO_LEN;
369 max_len = COL_MAX_LEN;
371 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
372 col_item = &cinfo->columns[i];
373 if (col_item->fmt_matx[el]) {
375 * First arrange that we can append, if necessary.
377 COL_CHECK_APPEND(col_item, max_len);
379 pos = strlen(col_item->col_buf);
386 if G_UNLIKELY(str == NULL)
389 pos += g_strlcpy(&col_item->col_buf[pos], str, max_len - pos);
391 } while (pos < max_len && (str = va_arg(ap, const char *)) != COL_ADD_LSTR_TERMINATOR);
398 col_append_str_uint(column_info *cinfo, const gint col, const gchar *abbrev, guint32 val, const gchar *sep)
402 guint32_to_str_buf(val, buf, sizeof(buf));
403 col_append_lstr(cinfo, col, sep ? sep : "", abbrev, "=", buf, COL_ADD_LSTR_TERMINATOR);
407 col_snprint_port(gchar *buf, gulong buf_siz, port_type typ, guint16 val)
412 if (gbl_resolv_flags.transport_name &&
413 (str = try_serv_name_lookup(typ, val)) != NULL) {
414 n = g_snprintf(buf, buf_siz, "%s(%"G_GUINT16_FORMAT")", str, val);
416 n = g_snprintf(buf, buf_siz, "%"G_GUINT16_FORMAT, val);
422 col_append_ports(column_info *cinfo, const gint col, port_type typ, guint16 src, guint16 dst)
424 char buf_src[32], buf_dst[32];
426 col_snprint_port(buf_src, 32, typ, src);
427 col_snprint_port(buf_dst, 32, typ, dst);
428 col_append_lstr(cinfo, col, buf_src, UTF8_RIGHTWARDS_ARROW, buf_dst, COL_ADD_LSTR_TERMINATOR);
432 col_do_append_fstr(column_info *cinfo, const int el, const char *separator, const char *format, va_list ap)
434 size_t len, max_len, sep_len;
436 col_item_t* col_item;
438 sep_len = (separator) ? strlen(separator) : 0;
441 max_len = COL_MAX_INFO_LEN;
443 max_len = COL_MAX_LEN;
445 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
446 col_item = &cinfo->columns[i];
447 if (col_item->fmt_matx[el]) {
449 * First arrange that we can append, if necessary.
451 COL_CHECK_APPEND(col_item, max_len);
453 len = strlen(col_item->col_buf);
456 * If we have a separator, append it if the column isn't empty.
458 if (sep_len != 0 && len != 0) {
459 g_strlcat(col_item->col_buf, separator, max_len);
467 g_vsnprintf(&col_item->col_buf[len], (guint32)(max_len - len), format, ap2);
474 /* Appends a vararg list to a packet info string. */
476 col_append_fstr(column_info *cinfo, const gint el, const gchar *format, ...)
480 if (!CHECK_COL(cinfo, el))
483 va_start(ap, format);
484 col_do_append_fstr(cinfo, el, NULL, format, ap);
488 /* Appends a vararg list to a packet info string.
489 * Prefixes it with the given separator if the column is not empty.
492 col_append_sep_fstr(column_info *cinfo, const gint el, const gchar *separator,
493 const gchar *format, ...)
497 if (!CHECK_COL(cinfo, el))
500 if (separator == NULL)
501 separator = ", "; /* default */
503 va_start(ap, format);
504 col_do_append_fstr(cinfo, el, separator, format, ap);
508 /* Prepends a vararg list to a packet info string. */
509 #define COL_BUF_MAX_LEN (((COL_MAX_INFO_LEN) > (COL_MAX_LEN)) ? \
510 (COL_MAX_INFO_LEN) : (COL_MAX_LEN))
512 col_prepend_fstr(column_info *cinfo, const gint el, const gchar *format, ...)
516 char orig_buf[COL_BUF_MAX_LEN];
519 col_item_t* col_item;
521 if (!CHECK_COL(cinfo, el))
525 max_len = COL_MAX_INFO_LEN;
527 max_len = COL_MAX_LEN;
529 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
530 col_item = &cinfo->columns[i];
531 if (col_item->fmt_matx[el]) {
532 if (col_item->col_data != col_item->col_buf) {
533 /* This was set with "col_set_str()"; which is effectively const */
534 orig = col_item->col_data;
536 g_strlcpy(orig_buf, col_item->col_buf, max_len);
539 va_start(ap, format);
540 g_vsnprintf(col_item->col_buf, max_len, format, ap);
544 * Move the fence, unless it's at the beginning of the string.
546 if (col_item->col_fence > 0)
547 col_item->col_fence += (int) strlen(col_item->col_buf);
549 g_strlcat(col_item->col_buf, orig, max_len);
550 col_item->col_data = col_item->col_buf;
555 col_prepend_fence_fstr(column_info *cinfo, const gint el, const gchar *format, ...)
559 char orig_buf[COL_BUF_MAX_LEN];
562 col_item_t* col_item;
564 if (!CHECK_COL(cinfo, el))
568 max_len = COL_MAX_INFO_LEN;
570 max_len = COL_MAX_LEN;
572 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
573 col_item = &cinfo->columns[i];
574 if (col_item->fmt_matx[el]) {
575 if (col_item->col_data != col_item->col_buf) {
576 /* This was set with "col_set_str()"; which is effectively const */
577 orig = col_item->col_data;
579 g_strlcpy(orig_buf, col_item->col_buf, max_len);
582 va_start(ap, format);
583 g_vsnprintf(col_item->col_buf, max_len, format, ap);
587 * Move the fence if it exists, else create a new fence at the
588 * end of the prepended data.
590 if (col_item->col_fence > 0) {
591 col_item->col_fence += (int) strlen(col_item->col_buf);
593 col_item->col_fence = (int) strlen(col_item->col_buf);
595 g_strlcat(col_item->col_buf, orig, max_len);
596 col_item->col_data = col_item->col_buf;
601 /* Use this if "str" points to something that won't stay around (and
602 must thus be copied). */
604 col_add_str(column_info *cinfo, const gint el, const gchar* str)
608 col_item_t* col_item;
610 if (!CHECK_COL(cinfo, el))
614 max_len = COL_MAX_INFO_LEN;
616 max_len = COL_MAX_LEN;
618 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
619 col_item = &cinfo->columns[i];
620 if (col_item->fmt_matx[el]) {
621 if (col_item->col_fence != 0) {
623 * We will append the string after the fence.
624 * First arrange that we can append, if necessary.
626 COL_CHECK_APPEND(col_item, max_len);
629 * There's no fence, so we can just write to the string.
631 col_item->col_data = col_item->col_buf;
633 g_strlcpy(&col_item->col_buf[col_item->col_fence], str, max_len - col_item->col_fence);
638 /* Use this if "str" points to something that will stay around (and thus
639 needn't be copied). */
641 col_set_str(column_info *cinfo, const gint el, const gchar* str)
645 col_item_t* col_item;
647 DISSECTOR_ASSERT(str);
649 if (!CHECK_COL(cinfo, el))
653 max_len = COL_MAX_INFO_LEN;
655 max_len = COL_MAX_LEN;
657 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
658 col_item = &cinfo->columns[i];
659 if (col_item->fmt_matx[el]) {
660 if (col_item->col_fence != 0) {
662 * We will append the string after the fence.
663 * First arrange that we can append, if necessary.
665 COL_CHECK_APPEND(col_item, max_len);
667 g_strlcpy(&col_item->col_buf[col_item->col_fence], str, max_len - col_item->col_fence);
670 * There's no fence, so we can just set the column to point
673 col_item->col_data = str;
680 col_add_lstr(column_info *cinfo, const gint el, const gchar *str1, ...)
687 col_item_t* col_item;
689 if (!CHECK_COL(cinfo, el))
693 max_len = COL_MAX_INFO_LEN;
695 max_len = COL_MAX_LEN;
697 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
698 col_item = &cinfo->columns[i];
699 if (col_item->fmt_matx[el]) {
700 pos = col_item->col_fence;
703 * We will append the string after the fence.
704 * First arrange that we can append, if necessary.
706 COL_CHECK_APPEND(col_item, max_len);
709 * There's no fence, so we can just write to the string.
711 col_item->col_data = col_item->col_buf;
717 if G_UNLIKELY(str == NULL)
720 pos += g_strlcpy(&col_item->col_buf[pos], str, max_len - pos);
722 } while (pos < max_len && (str = va_arg(ap, const char *)) != COL_ADD_LSTR_TERMINATOR);
728 /* Adds a vararg list to a packet info string. */
730 col_add_fstr(column_info *cinfo, const gint el, const gchar *format, ...)
735 col_item_t* col_item;
737 if (!CHECK_COL(cinfo, el))
741 max_len = COL_MAX_INFO_LEN;
743 max_len = COL_MAX_LEN;
745 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
746 col_item = &cinfo->columns[i];
747 if (col_item->fmt_matx[el]) {
748 if (col_item->col_fence != 0) {
750 * We will append the string after the fence.
751 * First arrange that we can append, if necessary.
753 COL_CHECK_APPEND(col_item, max_len);
756 * There's no fence, so we can just write to the string.
758 col_item->col_data = col_item->col_buf;
760 va_start(ap, format);
761 g_vsnprintf(&col_item->col_buf[col_item->col_fence], max_len - col_item->col_fence, format, ap);
768 col_do_append_str(column_info *cinfo, const gint el, const gchar* separator,
773 col_item_t* col_item;
776 max_len = COL_MAX_INFO_LEN;
778 max_len = COL_MAX_LEN;
780 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
781 col_item = &cinfo->columns[i];
782 if (col_item->fmt_matx[el]) {
784 * First arrange that we can append, if necessary.
786 COL_CHECK_APPEND(col_item, max_len);
788 len = col_item->col_buf[0];
791 * If we have a separator, append it if the column isn't empty.
793 if (separator != NULL) {
795 g_strlcat(col_item->col_buf, separator, max_len);
798 g_strlcat(col_item->col_buf, str, max_len);
804 col_append_str(column_info *cinfo, const gint el, const gchar* str)
806 if (!CHECK_COL(cinfo, el))
809 col_do_append_str(cinfo, el, NULL, str);
813 col_append_sep_str(column_info *cinfo, const gint el, const gchar* separator,
816 if (!CHECK_COL(cinfo, el))
819 if (separator == NULL)
820 separator = ", "; /* default */
822 col_do_append_str(cinfo, el, separator, str);
825 /* --------------------------------- */
827 col_has_time_fmt(column_info *cinfo, const gint col)
829 col_item_t* col_item = &cinfo->columns[col];
830 return ((col_item->fmt_matx[COL_CLS_TIME]) ||
831 (col_item->fmt_matx[COL_ABS_TIME]) ||
832 (col_item->fmt_matx[COL_ABS_YMD_TIME]) ||
833 (col_item->fmt_matx[COL_ABS_YDOY_TIME]) ||
834 (col_item->fmt_matx[COL_UTC_TIME]) ||
835 (col_item->fmt_matx[COL_UTC_YMD_TIME]) ||
836 (col_item->fmt_matx[COL_UTC_YDOY_TIME]) ||
837 (col_item->fmt_matx[COL_REL_TIME]) ||
838 (col_item->fmt_matx[COL_DELTA_TIME]) ||
839 (col_item->fmt_matx[COL_DELTA_TIME_DIS]));
843 set_abs_ymd_time(const frame_data *fd, gchar *buf, gboolean local)
849 if (fd->flags.has_ts) {
850 then = fd->abs_ts.secs;
852 tmp = localtime(&then);
858 switch (timestamp_get_precision()) {
859 case TS_PREC_FIXED_SEC:
860 tsprecision = WTAP_TSPREC_SEC;
862 case TS_PREC_FIXED_DSEC:
863 tsprecision = WTAP_TSPREC_DSEC;
865 case TS_PREC_FIXED_CSEC:
866 tsprecision = WTAP_TSPREC_CSEC;
868 case TS_PREC_FIXED_MSEC:
869 tsprecision = WTAP_TSPREC_MSEC;
871 case TS_PREC_FIXED_USEC:
872 tsprecision = WTAP_TSPREC_USEC;
874 case TS_PREC_FIXED_NSEC:
875 tsprecision = WTAP_TSPREC_NSEC;
878 tsprecision = fd->tsprec;
881 g_assert_not_reached();
883 switch (tsprecision) {
884 case WTAP_TSPREC_SEC:
885 g_snprintf(buf, COL_MAX_LEN,"%04d-%02d-%02d %02d:%02d:%02d",
893 case WTAP_TSPREC_DSEC:
894 g_snprintf(buf, COL_MAX_LEN,"%04d-%02d-%02d %02d:%02d:%02d.%01d",
901 fd->abs_ts.nsecs / 100000000);
903 case WTAP_TSPREC_CSEC:
904 g_snprintf(buf, COL_MAX_LEN,"%04d-%02d-%02d %02d:%02d:%02d.%02d",
911 fd->abs_ts.nsecs / 10000000);
913 case WTAP_TSPREC_MSEC:
914 g_snprintf(buf, COL_MAX_LEN, "%04d-%02d-%02d %02d:%02d:%02d.%03d",
921 fd->abs_ts.nsecs / 1000000);
923 case WTAP_TSPREC_USEC:
924 g_snprintf(buf, COL_MAX_LEN, "%04d-%02d-%02d %02d:%02d:%02d.%06d",
931 fd->abs_ts.nsecs / 1000);
933 case WTAP_TSPREC_NSEC:
934 g_snprintf(buf, COL_MAX_LEN, "%04d-%02d-%02d %02d:%02d:%02d.%09d",
944 g_assert_not_reached();
952 col_set_abs_ymd_time(const frame_data *fd, column_info *cinfo, const int col)
954 set_abs_ymd_time(fd, cinfo->columns[col].col_buf, TRUE);
955 cinfo->col_expr.col_expr[col] = "frame.time";
956 g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->columns[col].col_buf,COL_MAX_LEN);
958 cinfo->columns[col].col_data = cinfo->columns[col].col_buf;
962 col_set_utc_ymd_time(const frame_data *fd, column_info *cinfo, const int col)
964 set_abs_ymd_time(fd, cinfo->columns[col].col_buf, FALSE);
965 cinfo->col_expr.col_expr[col] = "frame.time";
966 g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->columns[col].col_buf,COL_MAX_LEN);
968 cinfo->columns[col].col_data = cinfo->columns[col].col_buf;
972 set_abs_ydoy_time(const frame_data *fd, gchar *buf, gboolean local)
978 if (fd->flags.has_ts) {
979 then = fd->abs_ts.secs;
981 tmp = localtime(&then);
987 switch (timestamp_get_precision()) {
988 case TS_PREC_FIXED_SEC:
989 tsprecision = WTAP_TSPREC_SEC;
991 case TS_PREC_FIXED_DSEC:
992 tsprecision = WTAP_TSPREC_DSEC;
994 case TS_PREC_FIXED_CSEC:
995 tsprecision = WTAP_TSPREC_CSEC;
997 case TS_PREC_FIXED_MSEC:
998 tsprecision = WTAP_TSPREC_MSEC;
1000 case TS_PREC_FIXED_USEC:
1001 tsprecision = WTAP_TSPREC_USEC;
1003 case TS_PREC_FIXED_NSEC:
1004 tsprecision = WTAP_TSPREC_NSEC;
1007 tsprecision = fd->tsprec;
1010 g_assert_not_reached();
1012 switch (tsprecision) {
1013 case WTAP_TSPREC_SEC:
1014 g_snprintf(buf, COL_MAX_LEN,"%04d/%03d %02d:%02d:%02d",
1015 tmp->tm_year + 1900,
1021 case WTAP_TSPREC_DSEC:
1022 g_snprintf(buf, COL_MAX_LEN,"%04d/%03d %02d:%02d:%02d.%01d",
1023 tmp->tm_year + 1900,
1028 fd->abs_ts.nsecs / 100000000);
1030 case WTAP_TSPREC_CSEC:
1031 g_snprintf(buf, COL_MAX_LEN,"%04d/%03d %02d:%02d:%02d.%02d",
1032 tmp->tm_year + 1900,
1037 fd->abs_ts.nsecs / 10000000);
1039 case WTAP_TSPREC_MSEC:
1040 g_snprintf(buf, COL_MAX_LEN, "%04d/%03d %02d:%02d:%02d.%03d",
1041 tmp->tm_year + 1900,
1046 fd->abs_ts.nsecs / 1000000);
1048 case WTAP_TSPREC_USEC:
1049 g_snprintf(buf, COL_MAX_LEN, "%04d/%03d %02d:%02d:%02d.%06d",
1050 tmp->tm_year + 1900,
1055 fd->abs_ts.nsecs / 1000);
1057 case WTAP_TSPREC_NSEC:
1058 g_snprintf(buf, COL_MAX_LEN, "%04d/%03d %02d:%02d:%02d.%09d",
1059 tmp->tm_year + 1900,
1067 g_assert_not_reached();
1075 col_set_abs_ydoy_time(const frame_data *fd, column_info *cinfo, const int col)
1077 set_abs_ydoy_time(fd, cinfo->columns[col].col_buf, TRUE);
1078 cinfo->col_expr.col_expr[col] = "frame.time";
1079 g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->columns[col].col_buf,COL_MAX_LEN);
1081 cinfo->columns[col].col_data = cinfo->columns[col].col_buf;
1085 col_set_utc_ydoy_time(const frame_data *fd, column_info *cinfo, const int col)
1087 set_abs_ydoy_time(fd, cinfo->columns[col].col_buf, FALSE);
1088 cinfo->col_expr.col_expr[col] = "frame.time";
1089 g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->columns[col].col_buf,COL_MAX_LEN);
1091 cinfo->columns[col].col_data = cinfo->columns[col].col_buf;
1095 set_time_seconds(const frame_data *fd, const nstime_t *ts, gchar *buf)
1099 switch (timestamp_get_precision()) {
1100 case TS_PREC_FIXED_SEC:
1101 tsprecision = WTAP_TSPREC_SEC;
1103 case TS_PREC_FIXED_DSEC:
1104 tsprecision = WTAP_TSPREC_DSEC;
1106 case TS_PREC_FIXED_CSEC:
1107 tsprecision = WTAP_TSPREC_CSEC;
1109 case TS_PREC_FIXED_MSEC:
1110 tsprecision = WTAP_TSPREC_MSEC;
1112 case TS_PREC_FIXED_USEC:
1113 tsprecision = WTAP_TSPREC_USEC;
1115 case TS_PREC_FIXED_NSEC:
1116 tsprecision = WTAP_TSPREC_NSEC;
1119 tsprecision = fd->tsprec;
1122 g_assert_not_reached();
1124 switch (tsprecision) {
1125 case WTAP_TSPREC_SEC:
1126 display_signed_time(buf, COL_MAX_LEN,
1127 (gint32) ts->secs, ts->nsecs / 1000000000, TO_STR_TIME_RES_T_SECS);
1129 case WTAP_TSPREC_DSEC:
1130 display_signed_time(buf, COL_MAX_LEN,
1131 (gint32) ts->secs, ts->nsecs / 100000000, TO_STR_TIME_RES_T_DSECS);
1133 case WTAP_TSPREC_CSEC:
1134 display_signed_time(buf, COL_MAX_LEN,
1135 (gint32) ts->secs, ts->nsecs / 10000000, TO_STR_TIME_RES_T_CSECS);
1137 case WTAP_TSPREC_MSEC:
1138 display_signed_time(buf, COL_MAX_LEN,
1139 (gint32) ts->secs, ts->nsecs / 1000000, TO_STR_TIME_RES_T_MSECS);
1141 case WTAP_TSPREC_USEC:
1142 display_signed_time(buf, COL_MAX_LEN,
1143 (gint32) ts->secs, ts->nsecs / 1000, TO_STR_TIME_RES_T_USECS);
1145 case WTAP_TSPREC_NSEC:
1146 display_signed_time(buf, COL_MAX_LEN,
1147 (gint32) ts->secs, ts->nsecs, TO_STR_TIME_RES_T_NSECS);
1150 g_assert_not_reached();
1155 set_time_hour_min_sec(const frame_data *fd, const nstime_t *ts, gchar *buf)
1157 time_t secs = ts->secs;
1158 long nsecs = (long) ts->nsecs;
1159 gboolean negative = FALSE;
1171 switch (timestamp_get_precision()) {
1172 case TS_PREC_FIXED_SEC:
1173 tsprecision = WTAP_TSPREC_SEC;
1175 case TS_PREC_FIXED_DSEC:
1176 tsprecision = WTAP_TSPREC_DSEC;
1178 case TS_PREC_FIXED_CSEC:
1179 tsprecision = WTAP_TSPREC_CSEC;
1181 case TS_PREC_FIXED_MSEC:
1182 tsprecision = WTAP_TSPREC_MSEC;
1184 case TS_PREC_FIXED_USEC:
1185 tsprecision = WTAP_TSPREC_USEC;
1187 case TS_PREC_FIXED_NSEC:
1188 tsprecision = WTAP_TSPREC_NSEC;
1191 tsprecision = fd->tsprec;
1194 g_assert_not_reached();
1196 switch (tsprecision) {
1197 case WTAP_TSPREC_SEC:
1198 if (secs >= (60*60)) {
1199 g_snprintf(buf, COL_MAX_LEN, "%s%dh %2dm %2ds",
1200 negative ? "- " : "",
1201 (gint32) secs / (60 * 60),
1202 (gint32) (secs / 60) % 60,
1203 (gint32) secs % 60);
1204 } else if (secs >= 60) {
1205 g_snprintf(buf, COL_MAX_LEN, "%s%dm %2ds",
1206 negative ? "- " : "",
1208 (gint32) secs % 60);
1210 g_snprintf(buf, COL_MAX_LEN, "%s%ds",
1211 negative ? "- " : "",
1215 case WTAP_TSPREC_DSEC:
1216 if (secs >= (60*60)) {
1217 g_snprintf(buf, COL_MAX_LEN, "%s%dh %2dm %2d.%01lds",
1218 negative ? "- " : "",
1219 (gint32) secs / (60 * 60),
1220 (gint32) (secs / 60) % 60,
1223 } else if (secs >= 60) {
1224 g_snprintf(buf, COL_MAX_LEN, "%s%dm %2d.%01lds",
1225 negative ? "- " : "",
1230 g_snprintf(buf, COL_MAX_LEN, "%s%d.%01lds",
1231 negative ? "- " : "",
1236 case WTAP_TSPREC_CSEC:
1237 if (secs >= (60*60)) {
1238 g_snprintf(buf, COL_MAX_LEN, "%s%dh %2dm %2d.%02lds",
1239 negative ? "- " : "",
1240 (gint32) secs / (60 * 60),
1241 (gint32) (secs / 60) % 60,
1244 } else if (secs >= 60) {
1245 g_snprintf(buf, COL_MAX_LEN, "%s%dm %2d.%02lds",
1246 negative ? "- " : "",
1251 g_snprintf(buf, COL_MAX_LEN, "%s%d.%02lds",
1252 negative ? "- " : "",
1257 case WTAP_TSPREC_MSEC:
1258 if (secs >= (60*60)) {
1259 g_snprintf(buf, COL_MAX_LEN, "%s%dh %2dm %2d.%03lds",
1260 negative ? "- " : "",
1261 (gint32) secs / (60 * 60),
1262 (gint32) (secs / 60) % 60,
1265 } else if (secs >= 60) {
1266 g_snprintf(buf, COL_MAX_LEN, "%s%dm %2d.%03lds",
1267 negative ? "- " : "",
1272 g_snprintf(buf, COL_MAX_LEN, "%s%d.%03lds",
1273 negative ? "- " : "",
1278 case WTAP_TSPREC_USEC:
1279 if (secs >= (60*60)) {
1280 g_snprintf(buf, COL_MAX_LEN, "%s%dh %2dm %2d.%06lds",
1281 negative ? "- " : "",
1282 (gint32) secs / (60 * 60),
1283 (gint32) (secs / 60) % 60,
1286 } else if (secs >= 60) {
1287 g_snprintf(buf, COL_MAX_LEN, "%s%dm %2d.%06lds",
1288 negative ? "- " : "",
1293 g_snprintf(buf, COL_MAX_LEN, "%s%d.%06lds",
1294 negative ? "- " : "",
1299 case WTAP_TSPREC_NSEC:
1300 if (secs >= (60*60)) {
1301 g_snprintf(buf, COL_MAX_LEN, "%s%dh %2dm %2d.%09lds",
1302 negative ? "- " : "",
1303 (gint32) secs / (60 * 60),
1304 (gint32) (secs / 60) % 60,
1307 } else if (secs >= 60) {
1308 g_snprintf(buf, COL_MAX_LEN, "%s%dm %2d.%09lds",
1309 negative ? "- " : "",
1314 g_snprintf(buf, COL_MAX_LEN, "%s%d.%09lds",
1315 negative ? "- " : "",
1321 g_assert_not_reached();
1326 col_set_rel_time(const frame_data *fd, column_info *cinfo, const int col)
1328 nstime_t del_rel_ts;
1330 if (!fd->flags.has_ts) {
1331 cinfo->columns[col].col_buf[0] = '\0';
1335 frame_delta_abs_time(cinfo->epan, fd, fd->frame_ref_num, &del_rel_ts);
1337 switch (timestamp_get_seconds_type()) {
1338 case TS_SECONDS_DEFAULT:
1339 set_time_seconds(fd, &del_rel_ts, cinfo->columns[col].col_buf);
1340 cinfo->col_expr.col_expr[col] = "frame.time_relative";
1341 g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->columns[col].col_buf,COL_MAX_LEN);
1343 case TS_SECONDS_HOUR_MIN_SEC:
1344 set_time_hour_min_sec(fd, &del_rel_ts, cinfo->columns[col].col_buf);
1345 cinfo->col_expr.col_expr[col] = "frame.time_relative";
1346 set_time_seconds(fd, &del_rel_ts, cinfo->col_expr.col_expr_val[col]);
1349 g_assert_not_reached();
1351 cinfo->columns[col].col_data = cinfo->columns[col].col_buf;
1355 col_set_delta_time(const frame_data *fd, column_info *cinfo, const int col)
1357 nstime_t del_cap_ts;
1359 frame_delta_abs_time(cinfo->epan, fd, fd->num - 1, &del_cap_ts);
1361 switch (timestamp_get_seconds_type()) {
1362 case TS_SECONDS_DEFAULT:
1363 set_time_seconds(fd, &del_cap_ts, cinfo->columns[col].col_buf);
1364 cinfo->col_expr.col_expr[col] = "frame.time_delta";
1365 g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->columns[col].col_buf,COL_MAX_LEN);
1367 case TS_SECONDS_HOUR_MIN_SEC:
1368 set_time_hour_min_sec(fd, &del_cap_ts, cinfo->columns[col].col_buf);
1369 cinfo->col_expr.col_expr[col] = "frame.time_delta";
1370 set_time_seconds(fd, &del_cap_ts, cinfo->col_expr.col_expr_val[col]);
1373 g_assert_not_reached();
1376 cinfo->columns[col].col_data = cinfo->columns[col].col_buf;
1380 col_set_delta_time_dis(const frame_data *fd, column_info *cinfo, const int col)
1382 nstime_t del_dis_ts;
1384 if (!fd->flags.has_ts) {
1385 cinfo->columns[col].col_buf[0] = '\0';
1389 frame_delta_abs_time(cinfo->epan, fd, fd->prev_dis_num, &del_dis_ts);
1391 switch (timestamp_get_seconds_type()) {
1392 case TS_SECONDS_DEFAULT:
1393 set_time_seconds(fd, &del_dis_ts, cinfo->columns[col].col_buf);
1394 cinfo->col_expr.col_expr[col] = "frame.time_delta_displayed";
1395 g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->columns[col].col_buf,COL_MAX_LEN);
1397 case TS_SECONDS_HOUR_MIN_SEC:
1398 set_time_hour_min_sec(fd, &del_dis_ts, cinfo->columns[col].col_buf);
1399 cinfo->col_expr.col_expr[col] = "frame.time_delta_displayed";
1400 set_time_seconds(fd, &del_dis_ts, cinfo->col_expr.col_expr_val[col]);
1403 g_assert_not_reached();
1406 cinfo->columns[col].col_data = cinfo->columns[col].col_buf;
1410 set_abs_time(const frame_data *fd, gchar *buf, gboolean local)
1416 if (fd->flags.has_ts) {
1417 then = fd->abs_ts.secs;
1419 tmp = localtime(&then);
1421 tmp = gmtime(&then);
1425 switch (timestamp_get_precision()) {
1426 case TS_PREC_FIXED_SEC:
1427 tsprecision = WTAP_TSPREC_SEC;
1429 case TS_PREC_FIXED_DSEC:
1430 tsprecision = WTAP_TSPREC_DSEC;
1432 case TS_PREC_FIXED_CSEC:
1433 tsprecision = WTAP_TSPREC_CSEC;
1435 case TS_PREC_FIXED_MSEC:
1436 tsprecision = WTAP_TSPREC_MSEC;
1438 case TS_PREC_FIXED_USEC:
1439 tsprecision = WTAP_TSPREC_USEC;
1441 case TS_PREC_FIXED_NSEC:
1442 tsprecision = WTAP_TSPREC_NSEC;
1445 tsprecision = fd->tsprec;
1448 g_assert_not_reached();
1450 switch (tsprecision) {
1451 case WTAP_TSPREC_SEC:
1452 g_snprintf(buf, COL_MAX_LEN,"%02d:%02d:%02d",
1457 case WTAP_TSPREC_DSEC:
1458 g_snprintf(buf, COL_MAX_LEN,"%02d:%02d:%02d.%01d",
1462 fd->abs_ts.nsecs / 100000000);
1464 case WTAP_TSPREC_CSEC:
1465 g_snprintf(buf, COL_MAX_LEN,"%02d:%02d:%02d.%02d",
1469 fd->abs_ts.nsecs / 10000000);
1471 case WTAP_TSPREC_MSEC:
1472 g_snprintf(buf, COL_MAX_LEN,"%02d:%02d:%02d.%03d",
1476 fd->abs_ts.nsecs / 1000000);
1478 case WTAP_TSPREC_USEC:
1479 g_snprintf(buf, COL_MAX_LEN,"%02d:%02d:%02d.%06d",
1483 fd->abs_ts.nsecs / 1000);
1485 case WTAP_TSPREC_NSEC:
1486 g_snprintf(buf, COL_MAX_LEN, "%02d:%02d:%02d.%09d",
1493 g_assert_not_reached();
1502 col_set_abs_time(const frame_data *fd, column_info *cinfo, const int col)
1504 set_abs_time(fd, cinfo->columns[col].col_buf, TRUE);
1505 cinfo->col_expr.col_expr[col] = "frame.time";
1506 g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->columns[col].col_buf,COL_MAX_LEN);
1508 cinfo->columns[col].col_data = cinfo->columns[col].col_buf;
1512 col_set_utc_time(const frame_data *fd, column_info *cinfo, const int col)
1514 set_abs_time(fd, cinfo->columns[col].col_buf, FALSE);
1515 cinfo->col_expr.col_expr[col] = "frame.time";
1516 g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->columns[col].col_buf,COL_MAX_LEN);
1518 cinfo->columns[col].col_data = cinfo->columns[col].col_buf;
1522 set_epoch_time(const frame_data *fd, gchar *buf)
1526 if (!fd->flags.has_ts) {
1530 switch (timestamp_get_precision()) {
1531 case TS_PREC_FIXED_SEC:
1532 tsprecision = WTAP_TSPREC_SEC;
1534 case TS_PREC_FIXED_DSEC:
1535 tsprecision = WTAP_TSPREC_DSEC;
1537 case TS_PREC_FIXED_CSEC:
1538 tsprecision = WTAP_TSPREC_CSEC;
1540 case TS_PREC_FIXED_MSEC:
1541 tsprecision = WTAP_TSPREC_MSEC;
1543 case TS_PREC_FIXED_USEC:
1544 tsprecision = WTAP_TSPREC_USEC;
1546 case TS_PREC_FIXED_NSEC:
1547 tsprecision = WTAP_TSPREC_NSEC;
1550 tsprecision = fd->tsprec;
1553 g_assert_not_reached();
1555 switch (tsprecision) {
1556 case WTAP_TSPREC_SEC:
1557 display_epoch_time(buf, COL_MAX_LEN,
1558 fd->abs_ts.secs, fd->abs_ts.nsecs / 1000000000, TO_STR_TIME_RES_T_SECS);
1560 case WTAP_TSPREC_DSEC:
1561 display_epoch_time(buf, COL_MAX_LEN,
1562 fd->abs_ts.secs, fd->abs_ts.nsecs / 100000000, TO_STR_TIME_RES_T_DSECS);
1564 case WTAP_TSPREC_CSEC:
1565 display_epoch_time(buf, COL_MAX_LEN,
1566 fd->abs_ts.secs, fd->abs_ts.nsecs / 10000000, TO_STR_TIME_RES_T_CSECS);
1568 case WTAP_TSPREC_MSEC:
1569 display_epoch_time(buf, COL_MAX_LEN,
1570 fd->abs_ts.secs, fd->abs_ts.nsecs / 1000000, TO_STR_TIME_RES_T_MSECS);
1572 case WTAP_TSPREC_USEC:
1573 display_epoch_time(buf, COL_MAX_LEN,
1574 fd->abs_ts.secs, fd->abs_ts.nsecs / 1000, TO_STR_TIME_RES_T_USECS);
1576 case WTAP_TSPREC_NSEC:
1577 display_epoch_time(buf, COL_MAX_LEN,
1578 fd->abs_ts.secs, fd->abs_ts.nsecs, TO_STR_TIME_RES_T_NSECS);
1581 g_assert_not_reached();
1587 col_set_epoch_time(const frame_data *fd, column_info *cinfo, const int col)
1589 if (set_epoch_time(fd, cinfo->columns[col].col_buf)) {
1590 cinfo->col_expr.col_expr[col] = "frame.time_delta";
1591 g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->columns[col].col_buf,COL_MAX_LEN);
1593 cinfo->columns[col].col_data = cinfo->columns[col].col_buf;
1597 set_fd_time(const epan_t *epan, frame_data *fd, gchar *buf)
1600 switch (timestamp_get_type()) {
1602 set_abs_time(fd, buf, TRUE);
1605 case TS_ABSOLUTE_WITH_YMD:
1606 set_abs_ymd_time(fd, buf, TRUE);
1609 case TS_ABSOLUTE_WITH_YDOY:
1610 set_abs_ydoy_time(fd, buf, TRUE);
1614 if (fd->flags.has_ts) {
1615 nstime_t del_rel_ts;
1617 frame_delta_abs_time(epan, fd, fd->frame_ref_num, &del_rel_ts);
1619 switch (timestamp_get_seconds_type()) {
1620 case TS_SECONDS_DEFAULT:
1621 set_time_seconds(fd, &del_rel_ts, buf);
1623 case TS_SECONDS_HOUR_MIN_SEC:
1624 set_time_seconds(fd, &del_rel_ts, buf);
1627 g_assert_not_reached();
1635 if (fd->flags.has_ts) {
1636 nstime_t del_cap_ts;
1638 frame_delta_abs_time(epan, fd, fd->num - 1, &del_cap_ts);
1640 switch (timestamp_get_seconds_type()) {
1641 case TS_SECONDS_DEFAULT:
1642 set_time_seconds(fd, &del_cap_ts, buf);
1644 case TS_SECONDS_HOUR_MIN_SEC:
1645 set_time_hour_min_sec(fd, &del_cap_ts, buf);
1648 g_assert_not_reached();
1656 if (fd->flags.has_ts) {
1657 nstime_t del_dis_ts;
1659 frame_delta_abs_time(epan, fd, fd->prev_dis_num, &del_dis_ts);
1661 switch (timestamp_get_seconds_type()) {
1662 case TS_SECONDS_DEFAULT:
1663 set_time_seconds(fd, &del_dis_ts, buf);
1665 case TS_SECONDS_HOUR_MIN_SEC:
1666 set_time_hour_min_sec(fd, &del_dis_ts, buf);
1669 g_assert_not_reached();
1677 set_epoch_time(fd, buf);
1681 set_abs_time(fd, buf, FALSE);
1684 case TS_UTC_WITH_YMD:
1685 set_abs_ymd_time(fd, buf, FALSE);
1688 case TS_UTC_WITH_YDOY:
1689 set_abs_ydoy_time(fd, buf, FALSE);
1693 /* code is missing for this case, but I don't know which [jmayer20051219] */
1700 col_set_cls_time(const frame_data *fd, column_info *cinfo, const gint col)
1702 switch (timestamp_get_type()) {
1704 col_set_abs_time(fd, cinfo, col);
1707 case TS_ABSOLUTE_WITH_YMD:
1708 col_set_abs_ymd_time(fd, cinfo, col);
1711 case TS_ABSOLUTE_WITH_YDOY:
1712 col_set_abs_ydoy_time(fd, cinfo, col);
1716 col_set_rel_time(fd, cinfo, col);
1720 col_set_delta_time(fd, cinfo, col);
1724 col_set_delta_time_dis(fd, cinfo, col);
1728 col_set_epoch_time(fd, cinfo, col);
1732 col_set_utc_time(fd, cinfo, col);
1735 case TS_UTC_WITH_YMD:
1736 col_set_utc_ymd_time(fd, cinfo, col);
1739 case TS_UTC_WITH_YDOY:
1740 col_set_utc_ydoy_time(fd, cinfo, col);
1744 /* code is missing for this case, but I don't know which [jmayer20051219] */
1745 g_assert_not_reached();
1750 /* Set the format of the variable time format. */
1752 col_set_fmt_time(const frame_data *fd, column_info *cinfo, const gint fmt, const gint col)
1754 COL_CHECK_REF_TIME(fd, cinfo->columns[col].col_buf);
1758 col_set_cls_time(fd, cinfo, col);
1762 col_set_abs_time(fd, cinfo, col);
1765 case COL_ABS_YMD_TIME:
1766 col_set_abs_ymd_time(fd, cinfo, col);
1769 case COL_ABS_YDOY_TIME:
1770 col_set_abs_ydoy_time(fd, cinfo, col);
1774 col_set_rel_time(fd, cinfo, col);
1777 case COL_DELTA_TIME:
1778 col_set_delta_time(fd, cinfo, col);
1781 case COL_DELTA_TIME_DIS:
1782 col_set_delta_time_dis(fd, cinfo, col);
1786 col_set_utc_time(fd, cinfo, col);
1789 case COL_UTC_YMD_TIME:
1790 col_set_utc_ymd_time(fd, cinfo, col);
1793 case COL_UTC_YDOY_TIME:
1794 col_set_utc_ydoy_time(fd, cinfo, col);
1798 g_assert_not_reached();
1803 /* --------------------------- */
1804 /* Set the given (relative) time to a column element.
1806 * Used by dissectors to set the time in a column
1808 * @param cinfo the current packet row
1809 * @param el the column to use, e.g. COL_INFO
1810 * @param ts the time to set in the column
1811 * @param fieldname the fieldname to use for creating a filter (when
1812 * applying/preparing/copying as filter)
1815 col_set_time(column_info *cinfo, const gint el, const nstime_t *ts, const char *fieldname)
1818 col_item_t* col_item;
1820 if (!CHECK_COL(cinfo, el))
1823 /** @todo TODO: We don't respect fd->flags.ref_time (no way to access 'fd')
1824 COL_CHECK_REF_TIME(fd, buf);
1827 for (col = cinfo->col_first[el]; col <= cinfo->col_last[el]; col++) {
1828 col_item = &cinfo->columns[col];
1829 if (col_item->fmt_matx[el]) {
1830 switch (timestamp_get_precision()) {
1831 case TS_PREC_FIXED_SEC:
1832 display_signed_time(col_item->col_buf, COL_MAX_LEN,
1833 (gint32) ts->secs, ts->nsecs / 1000000000, TO_STR_TIME_RES_T_SECS);
1835 case TS_PREC_FIXED_DSEC:
1836 display_signed_time(col_item->col_buf, COL_MAX_LEN,
1837 (gint32) ts->secs, ts->nsecs / 100000000, TO_STR_TIME_RES_T_DSECS);
1839 case TS_PREC_FIXED_CSEC:
1840 display_signed_time(col_item->col_buf, COL_MAX_LEN,
1841 (gint32) ts->secs, ts->nsecs / 10000000, TO_STR_TIME_RES_T_CSECS);
1843 case TS_PREC_FIXED_MSEC:
1844 display_signed_time(col_item->col_buf, COL_MAX_LEN,
1845 (gint32) ts->secs, ts->nsecs / 1000000, TO_STR_TIME_RES_T_MSECS);
1847 case TS_PREC_FIXED_USEC:
1848 display_signed_time(col_item->col_buf, COL_MAX_LEN,
1849 (gint32) ts->secs, ts->nsecs / 1000, TO_STR_TIME_RES_T_USECS);
1851 case TS_PREC_FIXED_NSEC:
1852 case TS_PREC_AUTO: /* default to maximum */
1853 display_signed_time(col_item->col_buf, COL_MAX_LEN,
1854 (gint32) ts->secs, ts->nsecs, TO_STR_TIME_RES_T_NSECS);
1857 g_assert_not_reached();
1859 col_item->col_data = col_item->col_buf;
1860 cinfo->col_expr.col_expr[col] = fieldname;
1861 g_strlcpy(cinfo->col_expr.col_expr_val[col],col_item->col_buf,COL_MAX_LEN);
1867 col_set_addr(packet_info *pinfo, const int col, const address *addr, const gboolean is_src,
1868 const gboolean fill_col_exprs, const gboolean res)
1871 col_item_t* col_item = &pinfo->cinfo->columns[col];
1873 if (addr->type == AT_NONE) {
1874 /* No address, nothing to do */
1878 if (res && (name = address_to_name(addr)) != NULL)
1879 col_item->col_data = name;
1881 col_item->col_data = col_item->col_buf;
1882 address_to_str_buf(addr, col_item->col_buf, COL_MAX_LEN);
1885 if (!fill_col_exprs)
1888 pinfo->cinfo->col_expr.col_expr[col] = address_type_column_filter_string(addr, is_src);
1889 /* For address types that have a filter, create a string */
1890 if (strlen(pinfo->cinfo->col_expr.col_expr[col]) > 0)
1891 address_to_str_buf(addr, pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN);
1894 /* ------------------------ */
1896 col_set_port(packet_info *pinfo, const int col, const gboolean is_res, const gboolean is_src, const gboolean fill_col_exprs _U_)
1899 col_item_t* col_item = &pinfo->cinfo->columns[col];
1902 port = pinfo->srcport;
1904 port = pinfo->destport;
1906 /* TODO: Use fill_col_exprs */
1908 switch (pinfo->ptype) {
1911 g_strlcpy(col_item->col_buf, sctp_port_to_display(pinfo->pool, port), COL_MAX_LEN);
1913 guint32_to_str_buf(port, col_item->col_buf, COL_MAX_LEN);
1917 guint32_to_str_buf(port, pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN);
1919 g_strlcpy(col_item->col_buf, tcp_port_to_display(pinfo->pool, port), COL_MAX_LEN);
1921 g_strlcpy(col_item->col_buf, pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN);
1923 pinfo->cinfo->col_expr.col_expr[col] = "tcp.srcport";
1925 pinfo->cinfo->col_expr.col_expr[col] = "tcp.dstport";
1929 guint32_to_str_buf(port, pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN);
1931 g_strlcpy(col_item->col_buf, udp_port_to_display(pinfo->pool, port), COL_MAX_LEN);
1933 g_strlcpy(col_item->col_buf, pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN);
1935 pinfo->cinfo->col_expr.col_expr[col] = "udp.srcport";
1937 pinfo->cinfo->col_expr.col_expr[col] = "udp.dstport";
1942 pinfo->cinfo->col_expr.col_expr[col] = "ddp.src_socket";
1944 pinfo->cinfo->col_expr.col_expr[col] = "ddp.dst_socket";
1945 guint32_to_str_buf(port, pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN);
1946 g_strlcpy(col_item->col_buf, pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN);
1950 /* XXX - resolve IPX socket numbers */
1951 g_snprintf(col_item->col_buf, COL_MAX_LEN, "0x%04x", port);
1952 g_strlcpy(pinfo->cinfo->col_expr.col_expr_val[col], col_item->col_buf,COL_MAX_LEN);
1954 pinfo->cinfo->col_expr.col_expr[col] = "ipx.src.socket";
1956 pinfo->cinfo->col_expr.col_expr[col] = "ipx.dst.socket";
1960 /* XXX - resolve IDP socket numbers */
1961 g_snprintf(col_item->col_buf, COL_MAX_LEN, "0x%04x", port);
1962 g_strlcpy(pinfo->cinfo->col_expr.col_expr_val[col], col_item->col_buf,COL_MAX_LEN);
1964 pinfo->cinfo->col_expr.col_expr[col] = "idp.src.socket";
1966 pinfo->cinfo->col_expr.col_expr[col] = "idp.dst.socket";
1970 /* XXX - resolve USB endpoint numbers */
1971 g_snprintf(col_item->col_buf, COL_MAX_LEN, "0x%08x", port);
1972 g_strlcpy(pinfo->cinfo->col_expr.col_expr_val[col], col_item->col_buf,COL_MAX_LEN);
1974 pinfo->cinfo->col_expr.col_expr[col] = "usb.src.endpoint";
1976 pinfo->cinfo->col_expr.col_expr[col] = "usb.dst.endpoint";
1982 col_item->col_data = col_item->col_buf;
1986 col_based_on_frame_data(column_info *cinfo, const gint col)
1989 g_assert(col < cinfo->num_cols);
1991 switch (cinfo->columns[col].col_fmt) {
1995 case COL_ABS_YMD_TIME:
1996 case COL_ABS_YDOY_TIME:
1998 case COL_UTC_YMD_TIME:
1999 case COL_UTC_YDOY_TIME:
2001 case COL_DELTA_TIME:
2002 case COL_DELTA_TIME_DIS:
2003 case COL_PACKET_LENGTH:
2004 case COL_CUMULATIVE_BYTES:
2013 col_fill_in_frame_data(const frame_data *fd, column_info *cinfo, const gint col, const gboolean fill_col_exprs)
2015 col_item_t* col_item = &cinfo->columns[col];
2017 switch (col_item->col_fmt) {
2019 guint32_to_str_buf(fd->num, col_item->col_buf, COL_MAX_LEN);
2020 col_item->col_data = col_item->col_buf;
2025 case COL_ABS_YMD_TIME:
2026 case COL_ABS_YDOY_TIME:
2028 case COL_UTC_YMD_TIME:
2029 case COL_UTC_YDOY_TIME:
2031 case COL_DELTA_TIME:
2032 case COL_DELTA_TIME_DIS:
2033 /* TODO: Pass on fill_col_exprs */
2034 col_set_fmt_time(fd, cinfo, col_item->col_fmt, col);
2037 case COL_PACKET_LENGTH:
2038 guint32_to_str_buf(fd->pkt_len, col_item->col_buf, COL_MAX_LEN);
2039 col_item->col_data = col_item->col_buf;
2042 case COL_CUMULATIVE_BYTES:
2043 guint32_to_str_buf(fd->cum_bytes, col_item->col_buf, COL_MAX_LEN);
2044 col_item->col_data = col_item->col_buf;
2051 if (!fill_col_exprs)
2054 switch (col_item->col_fmt) {
2056 cinfo->col_expr.col_expr[col] = "frame.number";
2057 g_strlcpy(cinfo->col_expr.col_expr_val[col], col_item->col_buf, COL_MAX_LEN);
2062 case COL_ABS_YMD_TIME:
2063 case COL_ABS_YDOY_TIME:
2065 case COL_UTC_YMD_TIME:
2066 case COL_UTC_YDOY_TIME:
2068 case COL_DELTA_TIME:
2069 case COL_DELTA_TIME_DIS:
2070 /* Already handled above */
2073 case COL_PACKET_LENGTH:
2074 cinfo->col_expr.col_expr[col] = "frame.len";
2075 g_strlcpy(cinfo->col_expr.col_expr_val[col], col_item->col_buf, COL_MAX_LEN);
2078 case COL_CUMULATIVE_BYTES:
2087 col_fill_in(packet_info *pinfo, const gboolean fill_col_exprs, const gboolean fill_fd_colums)
2090 col_item_t* col_item;
2095 for (i = 0; i < pinfo->cinfo->num_cols; i++) {
2096 col_item = &pinfo->cinfo->columns[i];
2097 if (col_based_on_frame_data(pinfo->cinfo, i)) {
2099 col_fill_in_frame_data(pinfo->fd, pinfo->cinfo, i, fill_col_exprs);
2101 switch (col_item->col_fmt) {
2103 case COL_RES_SRC: /* COL_DEF_SRC is currently just like COL_RES_SRC */
2104 col_set_addr(pinfo, i, &pinfo->src, TRUE, fill_col_exprs, TRUE);
2108 col_set_addr(pinfo, i, &pinfo->src, TRUE, fill_col_exprs, FALSE);
2111 case COL_DEF_DL_SRC:
2112 case COL_RES_DL_SRC:
2113 col_set_addr(pinfo, i, &pinfo->dl_src, TRUE, fill_col_exprs, TRUE);
2116 case COL_UNRES_DL_SRC:
2117 col_set_addr(pinfo, i, &pinfo->dl_src, TRUE, fill_col_exprs, FALSE);
2120 case COL_DEF_NET_SRC:
2121 case COL_RES_NET_SRC:
2122 col_set_addr(pinfo, i, &pinfo->net_src, TRUE, fill_col_exprs, TRUE);
2125 case COL_UNRES_NET_SRC:
2126 col_set_addr(pinfo, i, &pinfo->net_src, TRUE, fill_col_exprs, FALSE);
2130 case COL_RES_DST: /* COL_DEF_DST is currently just like COL_RES_DST */
2131 col_set_addr(pinfo, i, &pinfo->dst, FALSE, fill_col_exprs, TRUE);
2135 col_set_addr(pinfo, i, &pinfo->dst, FALSE, fill_col_exprs, FALSE);
2138 case COL_DEF_DL_DST:
2139 case COL_RES_DL_DST:
2140 col_set_addr(pinfo, i, &pinfo->dl_dst, FALSE, fill_col_exprs, TRUE);
2143 case COL_UNRES_DL_DST:
2144 col_set_addr(pinfo, i, &pinfo->dl_dst, FALSE, fill_col_exprs, FALSE);
2147 case COL_DEF_NET_DST:
2148 case COL_RES_NET_DST:
2149 col_set_addr(pinfo, i, &pinfo->net_dst, FALSE, fill_col_exprs, TRUE);
2152 case COL_UNRES_NET_DST:
2153 col_set_addr(pinfo, i, &pinfo->net_dst, FALSE, fill_col_exprs, FALSE);
2156 case COL_DEF_SRC_PORT:
2157 case COL_RES_SRC_PORT: /* COL_DEF_SRC_PORT is currently just like COL_RES_SRC_PORT */
2158 col_set_port(pinfo, i, TRUE, TRUE, fill_col_exprs);
2161 case COL_UNRES_SRC_PORT:
2162 col_set_port(pinfo, i, FALSE, TRUE, fill_col_exprs);
2165 case COL_DEF_DST_PORT:
2166 case COL_RES_DST_PORT: /* COL_DEF_DST_PORT is currently just like COL_RES_DST_PORT */
2167 col_set_port(pinfo, i, TRUE, FALSE, fill_col_exprs);
2170 case COL_UNRES_DST_PORT:
2171 col_set_port(pinfo, i, FALSE, FALSE, fill_col_exprs);
2174 case NUM_COL_FMTS: /* keep compiler happy - shouldn't get here */
2175 g_assert_not_reached();
2178 if (col_item->col_fmt >= NUM_COL_FMTS) {
2179 g_assert_not_reached();
2182 * Formatting handled by col_custom_set_edt() (COL_CUSTOM), expert.c
2183 * (COL_EXPERT), or individual dissectors.
2192 * Fill in columns if we got an error reading the packet.
2193 * We set most columns to "???", fill in columns that don't need data read
2194 * from the file, and set the Info column to an error message.
2197 col_fill_in_error(column_info *cinfo, frame_data *fdata, const gboolean fill_col_exprs, const gboolean fill_fd_colums)
2200 col_item_t* col_item;
2205 for (i = 0; i < cinfo->num_cols; i++) {
2206 col_item = &cinfo->columns[i];
2207 if (col_based_on_frame_data(cinfo, i)) {
2209 col_fill_in_frame_data(fdata, cinfo, i, fill_col_exprs);
2210 } else if (col_item->col_fmt == COL_INFO) {
2211 /* XXX - say more than this */
2212 col_item->col_data = "Read error";
2214 if (col_item->col_fmt >= NUM_COL_FMTS) {
2215 g_assert_not_reached();
2218 * No dissection was done, and these columns are set as the
2219 * result of the dissection, so....
2221 col_item->col_data = "???";
2233 * indent-tabs-mode: nil
2236 * ex: set shiftwidth=2 tabstop=8 expandtab:
2237 * :indentSize=2:tabSize=8:noTabs=true: