2 * Routines for column utilities.
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 #include "column-utils.h"
33 #include "timestamp.h"
34 #include "sna-utils.h"
35 #include "atalk-utils.h"
37 #include "packet_info.h"
39 #include "addr_resolv.h"
40 #include "ipv6-utils.h"
41 #include "osi-utils.h"
42 #include "value_string.h"
43 #include "column_info.h"
45 #include <epan/strutil.h>
46 #include <epan/epan.h>
48 static column_info *ci;
50 /* Allocate all the data structures for constructing column data, given
51 the number of columns. */
53 col_setup(column_info *cinfo, gint num_cols)
57 cinfo->num_cols = num_cols;
58 cinfo->col_fmt = (gint *) g_malloc(sizeof(gint) * num_cols);
59 cinfo->fmt_matx = (gboolean **) g_malloc(sizeof(gboolean *) * num_cols);
60 cinfo->col_first = (int *) g_malloc(sizeof(int) * (NUM_COL_FMTS));
61 cinfo->col_last = (int *) g_malloc(sizeof(int) * (NUM_COL_FMTS));
62 cinfo->col_title = (gchar **) g_malloc(sizeof(gchar *) * num_cols);
63 cinfo->col_custom_field = (gchar **) g_malloc(sizeof(gchar *) * num_cols);
64 cinfo->col_data = (const gchar **) g_malloc(sizeof(gchar *) * num_cols);
65 cinfo->col_buf = (gchar **) g_malloc(sizeof(gchar *) * num_cols);
66 cinfo->col_fence = (int *) g_malloc(sizeof(int) * num_cols);
67 cinfo->col_expr = (gchar **) g_malloc(sizeof(gchar *) * num_cols);
68 cinfo->col_expr_val = (gchar **) g_malloc(sizeof(gchar *) * num_cols);
70 for (i = 0; i < NUM_COL_FMTS; i++) {
71 cinfo->col_first[i] = -1;
72 cinfo->col_last[i] = -1;
76 /* Initialize the data structures for constructing column data. */
78 col_init(column_info *cinfo)
82 for (i = 0; i < cinfo->num_cols; i++) {
83 cinfo->col_buf[i][0] = '\0';
84 cinfo->col_data[i] = cinfo->col_buf[i];
85 cinfo->col_fence[i] = 0;
86 cinfo->col_expr[i][0] = '\0';
87 cinfo->col_expr_val[i][0] = '\0';
89 cinfo->writable = TRUE;
93 col_get_writable(column_info *cinfo)
95 return (cinfo ? cinfo->writable : FALSE);
99 col_set_writable(column_info *cinfo, gboolean writable)
102 cinfo->writable = writable;
105 /* Checks to see if a particular packet information element is needed for
108 check_col(column_info *cinfo, gint el) {
110 if (cinfo && cinfo->writable) {
111 /* We are constructing columns, and they're writable */
112 if (cinfo->col_first[el] >= 0) {
113 /* There is at least one column in that format */
120 /* Sets the fence for a column to be at the end of the column. */
122 col_set_fence(column_info *cinfo, gint el)
126 if (cinfo && cinfo->writable) {
127 /* We are constructing columns, and they're writable */
128 if (cinfo->col_first[el] >= 0) {
129 /* There is at least one column in that format */
130 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
131 if (cinfo->fmt_matx[i][el]) {
132 cinfo->col_fence[i] = strlen(cinfo->col_data[i]);
139 /* Use this to clear out a column, especially if you're going to be
140 appending to it later; at least on some platforms, it's more
141 efficient than using "col_add_str()" with a null string, and
142 more efficient than "col_set_str()" with a null string if you
143 later append to it, as the later append will cause a string
146 col_clear(column_info *cinfo, gint el)
151 g_assert(cinfo->col_first[el] >= 0);
152 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
153 if (cinfo->fmt_matx[i][el]) {
155 * At this point, either
157 * 1) col_data[i] is equal to col_buf[i], in which case we
158 * don't have to worry about copying col_data[i] to
161 * 2) col_data[i] isn't equal to col_buf[i], in which case
162 * the only thing that's been done to the column is
163 * "col_set_str()" calls and possibly "col_set_fence()"
164 * calls, in which case the fence is either unset and
165 * at the beginning of the string or set and at the end
166 * of the string - if it's at the beginning, we're just
167 * going to clear the column, and if it's at the end,
168 * we don't do anything.
170 fence = cinfo->col_fence[i];
171 if (fence == 0 || cinfo->col_buf[i] == cinfo->col_data[i]) {
173 * The fence isn't at the end of the column, or the column wasn't
174 * last set with "col_set_str()", so clear the column out.
176 cinfo->col_buf[i][fence] = '\0';
177 cinfo->col_data[i] = cinfo->col_buf[i];
179 cinfo->col_expr[i][0] = '\0';
180 cinfo->col_expr_val[i][0] = '\0';
185 #define COL_CHECK_APPEND(cinfo, i, max_len) \
186 if (cinfo->col_data[i] != cinfo->col_buf[i]) { \
187 /* This was set with "col_set_str()"; copy the string they \
188 set it to into the buffer, so we can append to it. */ \
189 g_strlcpy(cinfo->col_buf[i], cinfo->col_data[i], max_len); \
190 cinfo->col_data[i] = cinfo->col_buf[i]; \
193 #define COL_CHECK_REF_TIME(fd, cinfo, col) \
194 if(fd->flags.ref_time){ \
195 g_snprintf(cinfo->col_buf[col], COL_MAX_LEN, "*REF*"); \
196 cinfo->col_data[col] = cinfo->col_buf[col]; \
200 /* Use this if "str" points to something that will stay around (and thus
201 needn't be copied). */
203 col_set_str(column_info *cinfo, gint el, const gchar* str)
210 max_len = COL_MAX_INFO_LEN;
212 max_len = COL_MAX_LEN;
214 g_assert(cinfo->col_first[el] >= 0);
215 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
216 if (cinfo->fmt_matx[i][el]) {
217 fence = cinfo->col_fence[i];
220 * We will append the string after the fence.
221 * First arrange that we can append, if necessary.
223 COL_CHECK_APPEND(cinfo, i, max_len);
225 g_strlcpy(&cinfo->col_buf[i][fence], str, max_len - fence);
228 * There's no fence, so we can just set the column to point
231 cinfo->col_data[i] = str;
237 /* Adds a vararg list to a packet info string. */
239 col_add_fstr(column_info *cinfo, gint el, const gchar *format, ...) {
245 g_assert(cinfo->col_first[el] >= 0);
247 max_len = COL_MAX_INFO_LEN;
249 max_len = COL_MAX_LEN;
251 va_start(ap, format);
252 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
253 if (cinfo->fmt_matx[i][el]) {
254 fence = cinfo->col_fence[i];
257 * We will append the string after the fence.
258 * First arrange that we can append, if necessary.
260 COL_CHECK_APPEND(cinfo, i, max_len);
263 * There's no fence, so we can just write to the string.
265 cinfo->col_data[i] = cinfo->col_buf[i];
267 g_vsnprintf(&cinfo->col_buf[i][fence], max_len - fence, format, ap);
268 cinfo->col_buf[i][max_len - 1] = '\0';
275 col_custom_set_fstr(const gchar *field_name, const gchar *format, ...)
280 if (!have_custom_cols(ci))
283 va_start(ap, format);
284 for (i = ci->col_first[COL_CUSTOM];
285 i <= ci->col_last[COL_CUSTOM]; i++) {
286 if (ci->fmt_matx[i][COL_CUSTOM] &&
287 strcmp(ci->col_custom_field[i], field_name) == 0) {
288 ci->col_data[i] = ci->col_buf[i];
289 g_vsnprintf(ci->col_buf[i], COL_MAX_LEN, format, ap);
290 strncpy(ci->col_expr[i], field_name, COL_MAX_LEN);
291 strncpy(ci->col_expr_val[i], ci->col_buf[i], COL_MAX_LEN);
298 col_custom_prime_edt(epan_dissect_t *edt, column_info *cinfo)
301 dfilter_t *dfilter_code;
303 ci = cinfo; /* Save this into the static variable ci for use by
304 * col_custom_set_fstr() later. */
306 if(!have_custom_cols(cinfo))
309 for (i = cinfo->col_first[COL_CUSTOM];
310 i <= cinfo->col_last[COL_CUSTOM]; i++) {
311 if (cinfo->fmt_matx[i][COL_CUSTOM] &&
312 strlen(cinfo->col_custom_field[i]) > 0) {
313 if(dfilter_compile(cinfo->col_custom_field[i], &dfilter_code))
314 epan_dissect_prime_dfilter(edt, dfilter_code);
320 have_custom_cols(column_info *cinfo)
322 /* The same as check_col(), but without the check to see if the column
324 if (cinfo && cinfo->col_first[COL_CUSTOM] >= 0)
331 col_do_append_sep_va_fstr(column_info *cinfo, gint el, const gchar *separator,
332 const gchar *format, va_list ap)
335 size_t len, max_len, sep_len;
337 g_assert(cinfo->col_first[el] >= 0);
339 max_len = COL_MAX_INFO_LEN;
341 max_len = COL_MAX_LEN;
343 if (separator == NULL)
346 sep_len = strlen(separator);
347 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
348 if (cinfo->fmt_matx[i][el]) {
350 * First arrange that we can append, if necessary.
352 COL_CHECK_APPEND(cinfo, i, max_len);
354 len = strlen(cinfo->col_buf[i]);
357 * If we have a separator, append it if the column isn't empty.
359 if (separator != NULL) {
361 g_strlcat(cinfo->col_buf[i], separator, max_len);
365 g_vsnprintf(&cinfo->col_buf[i][len], max_len - len, format, ap);
366 cinfo->col_buf[i][max_len-1] = 0;
371 /* Appends a vararg list to a packet info string. */
373 col_append_fstr(column_info *cinfo, gint el, const gchar *format, ...)
377 va_start(ap, format);
378 col_do_append_sep_va_fstr(cinfo, el, NULL, format, ap);
382 /* Appends a vararg list to a packet info string.
383 * Prefixes it with the given separator if the column is not empty. */
385 col_append_sep_fstr(column_info *cinfo, gint el, const gchar *separator,
386 const gchar *format, ...)
390 if (separator == NULL)
391 separator = ", "; /* default */
392 va_start(ap, format);
393 col_do_append_sep_va_fstr(cinfo, el, separator, format, ap);
399 /* Prepends a vararg list to a packet info string. */
400 #define COL_BUF_MAX_LEN (((COL_MAX_INFO_LEN) > (COL_MAX_LEN)) ? \
401 (COL_MAX_INFO_LEN) : (COL_MAX_LEN))
403 col_prepend_fstr(column_info *cinfo, gint el, const gchar *format, ...)
407 char orig_buf[COL_BUF_MAX_LEN];
411 g_assert(cinfo->col_first[el] >= 0);
413 max_len = COL_MAX_INFO_LEN;
415 max_len = COL_MAX_LEN;
417 va_start(ap, format);
418 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
419 if (cinfo->fmt_matx[i][el]) {
420 if (cinfo->col_data[i] != cinfo->col_buf[i]) {
421 /* This was set with "col_set_str()"; which is effectively const */
422 orig = cinfo->col_data[i];
424 g_strlcpy(orig_buf, cinfo->col_buf[i], max_len);
427 g_vsnprintf(cinfo->col_buf[i], max_len, format, ap);
428 cinfo->col_buf[i][max_len - 1] = '\0';
431 * Move the fence, unless it's at the beginning of the string.
433 if (cinfo->col_fence[i] > 0)
434 cinfo->col_fence[i] += strlen(cinfo->col_buf[i]);
436 g_strlcat(cinfo->col_buf[i], orig, max_len);
437 cinfo->col_data[i] = cinfo->col_buf[i];
443 col_prepend_fence_fstr(column_info *cinfo, gint el, const gchar *format, ...)
447 char orig_buf[COL_BUF_MAX_LEN];
451 g_assert(cinfo->col_first[el] >= 0);
453 max_len = COL_MAX_INFO_LEN;
455 max_len = COL_MAX_LEN;
457 va_start(ap, format);
458 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
459 if (cinfo->fmt_matx[i][el]) {
460 if (cinfo->col_data[i] != cinfo->col_buf[i]) {
461 /* This was set with "col_set_str()"; which is effectively const */
462 orig = cinfo->col_data[i];
464 g_strlcpy(orig_buf, cinfo->col_buf[i], max_len);
467 g_vsnprintf(cinfo->col_buf[i], max_len, format, ap);
468 cinfo->col_buf[i][max_len - 1] = '\0';
471 * Move the fence if it exists, else create a new fence at the
472 * end of the prepended data.
474 if (cinfo->col_fence[i] > 0) {
475 cinfo->col_fence[i] += strlen(cinfo->col_buf[i]);
477 cinfo->col_fence[i] = strlen(cinfo->col_buf[i]);
479 g_strlcat(cinfo->col_buf[i], orig, max_len);
480 cinfo->col_data[i] = cinfo->col_buf[i];
486 /* Use this if "str" points to something that won't stay around (and
487 must thus be copied). */
489 col_add_str(column_info *cinfo, gint el, const gchar* str)
495 g_assert(cinfo->col_first[el] >= 0);
497 max_len = COL_MAX_INFO_LEN;
499 max_len = COL_MAX_LEN;
501 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
502 if (cinfo->fmt_matx[i][el]) {
503 fence = cinfo->col_fence[i];
506 * We will append the string after the fence.
507 * First arrange that we can append, if necessary.
509 COL_CHECK_APPEND(cinfo, i, max_len);
512 * There's no fence, so we can just write to the string.
514 cinfo->col_data[i] = cinfo->col_buf[i];
516 g_strlcpy(&cinfo->col_buf[i][fence], str, max_len - fence);
522 col_do_append_str(column_info *cinfo, gint el, const gchar* separator,
526 size_t len, max_len, sep_len;
528 g_assert(cinfo->col_first[el] >= 0);
530 max_len = COL_MAX_INFO_LEN;
532 max_len = COL_MAX_LEN;
534 if (separator == NULL)
537 sep_len = strlen(separator);
539 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
540 if (cinfo->fmt_matx[i][el]) {
542 * First arrange that we can append, if necessary.
544 COL_CHECK_APPEND(cinfo, i, max_len);
546 len = cinfo->col_buf[i][0];
549 * If we have a separator, append it if the column isn't empty.
551 if (separator != NULL) {
553 g_strlcat(cinfo->col_buf[i], separator, max_len);
556 g_strlcat(cinfo->col_buf[i], str, max_len);
562 col_append_str(column_info *cinfo, gint el, const gchar* str)
564 col_do_append_str(cinfo, el, NULL, str);
568 col_append_sep_str(column_info *cinfo, gint el, const gchar* separator,
571 if (separator == NULL)
572 separator = ", "; /* default */
573 col_do_append_str(cinfo, el, separator, str);
577 col_set_abs_date_time(frame_data *fd, column_info *cinfo, int col)
582 COL_CHECK_REF_TIME(fd, cinfo, col);
584 then = fd->abs_ts.secs;
585 tmp = localtime(&then);
587 switch(timestamp_get_precision()) {
588 case(TS_PREC_FIXED_SEC):
589 case(TS_PREC_AUTO_SEC):
590 g_snprintf(cinfo->col_buf[col], COL_MAX_LEN,
591 "%04d-%02d-%02d %02d:%02d:%02d",
599 case(TS_PREC_FIXED_DSEC):
600 case(TS_PREC_AUTO_DSEC):
601 g_snprintf(cinfo->col_buf[col], COL_MAX_LEN,
602 "%04d-%02d-%02d %02d:%02d:%02d.%01ld",
609 (long)fd->abs_ts.nsecs / 100000000);
611 case(TS_PREC_FIXED_CSEC):
612 case(TS_PREC_AUTO_CSEC):
613 g_snprintf(cinfo->col_buf[col], COL_MAX_LEN,
614 "%04d-%02d-%02d %02d:%02d:%02d.%02ld",
621 (long)fd->abs_ts.nsecs / 10000000);
623 case(TS_PREC_FIXED_MSEC):
624 case(TS_PREC_AUTO_MSEC):
625 g_snprintf(cinfo->col_buf[col], COL_MAX_LEN,
626 "%04d-%02d-%02d %02d:%02d:%02d.%03ld",
633 (long)fd->abs_ts.nsecs / 1000000);
635 case(TS_PREC_FIXED_USEC):
636 case(TS_PREC_AUTO_USEC):
637 g_snprintf(cinfo->col_buf[col], COL_MAX_LEN,
638 "%04d-%02d-%02d %02d:%02d:%02d.%06ld",
645 (long)fd->abs_ts.nsecs / 1000);
647 case(TS_PREC_FIXED_NSEC):
648 case(TS_PREC_AUTO_NSEC):
649 g_snprintf(cinfo->col_buf[col], COL_MAX_LEN,
650 "%04d-%02d-%02d %02d:%02d:%02d.%09ld",
657 (long)fd->abs_ts.nsecs);
660 g_assert_not_reached();
663 cinfo->col_buf[col][0] = '\0';
665 cinfo->col_data[col] = cinfo->col_buf[col];
666 strcpy(cinfo->col_expr[col],"frame.time");
667 strcpy(cinfo->col_expr_val[col],cinfo->col_buf[col]);
671 col_set_rel_time(frame_data *fd, column_info *cinfo, int col)
673 COL_CHECK_REF_TIME(fd, cinfo, col);
675 switch(timestamp_get_precision()) {
676 case(TS_PREC_FIXED_SEC):
677 case(TS_PREC_AUTO_SEC):
678 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
679 (gint32) fd->rel_ts.secs, fd->rel_ts.nsecs / 1000000000, SECS);
681 case(TS_PREC_FIXED_DSEC):
682 case(TS_PREC_AUTO_DSEC):
683 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
684 (gint32) fd->rel_ts.secs, fd->rel_ts.nsecs / 100000000, DSECS);
686 case(TS_PREC_FIXED_CSEC):
687 case(TS_PREC_AUTO_CSEC):
688 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
689 (gint32) fd->rel_ts.secs, fd->rel_ts.nsecs / 10000000, CSECS);
691 case(TS_PREC_FIXED_MSEC):
692 case(TS_PREC_AUTO_MSEC):
693 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
694 (gint32) fd->rel_ts.secs, fd->rel_ts.nsecs / 1000000, MSECS);
696 case(TS_PREC_FIXED_USEC):
697 case(TS_PREC_AUTO_USEC):
698 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
699 (gint32) fd->rel_ts.secs, fd->rel_ts.nsecs / 1000, USECS);
701 case(TS_PREC_FIXED_NSEC):
702 case(TS_PREC_AUTO_NSEC):
703 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
704 (gint32) fd->rel_ts.secs, fd->rel_ts.nsecs, NSECS);
707 g_assert_not_reached();
709 cinfo->col_data[col] = cinfo->col_buf[col];
710 strcpy(cinfo->col_expr[col],"frame.time_relative");
711 strcpy(cinfo->col_expr_val[col],cinfo->col_buf[col]);
715 col_set_delta_time(frame_data *fd, column_info *cinfo, int col)
717 COL_CHECK_REF_TIME(fd, cinfo, col);
719 switch(timestamp_get_precision()) {
720 case(TS_PREC_FIXED_SEC):
721 case(TS_PREC_AUTO_SEC):
722 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
723 (gint32) fd->del_cap_ts.secs, fd->del_cap_ts.nsecs / 1000000000, SECS);
725 case(TS_PREC_FIXED_DSEC):
726 case(TS_PREC_AUTO_DSEC):
727 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
728 (gint32) fd->del_cap_ts.secs, fd->del_cap_ts.nsecs / 100000000, DSECS);
730 case(TS_PREC_FIXED_CSEC):
731 case(TS_PREC_AUTO_CSEC):
732 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
733 (gint32) fd->del_cap_ts.secs, fd->del_cap_ts.nsecs / 10000000, CSECS);
735 case(TS_PREC_FIXED_MSEC):
736 case(TS_PREC_AUTO_MSEC):
737 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
738 (gint32) fd->del_cap_ts.secs, fd->del_cap_ts.nsecs / 1000000, MSECS);
740 case(TS_PREC_FIXED_USEC):
741 case(TS_PREC_AUTO_USEC):
742 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
743 (gint32) fd->del_cap_ts.secs, fd->del_cap_ts.nsecs / 1000, USECS);
745 case(TS_PREC_FIXED_NSEC):
746 case(TS_PREC_AUTO_NSEC):
747 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
748 (gint32) fd->del_cap_ts.secs, fd->del_cap_ts.nsecs, NSECS);
751 g_assert_not_reached();
753 cinfo->col_data[col] = cinfo->col_buf[col];
754 strcpy(cinfo->col_expr[col],"frame.time_delta");
755 strcpy(cinfo->col_expr_val[col],cinfo->col_buf[col]);
759 col_set_delta_time_dis(frame_data *fd, column_info *cinfo, int col)
761 COL_CHECK_REF_TIME(fd, cinfo, col);
763 switch(timestamp_get_precision()) {
764 case(TS_PREC_FIXED_SEC):
765 case(TS_PREC_AUTO_SEC):
766 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
767 (gint32) fd->del_dis_ts.secs, fd->del_dis_ts.nsecs / 1000000000, SECS);
769 case(TS_PREC_FIXED_DSEC):
770 case(TS_PREC_AUTO_DSEC):
771 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
772 (gint32) fd->del_dis_ts.secs, fd->del_dis_ts.nsecs / 100000000, DSECS);
774 case(TS_PREC_FIXED_CSEC):
775 case(TS_PREC_AUTO_CSEC):
776 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
777 (gint32) fd->del_dis_ts.secs, fd->del_dis_ts.nsecs / 10000000, CSECS);
779 case(TS_PREC_FIXED_MSEC):
780 case(TS_PREC_AUTO_MSEC):
781 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
782 (gint32) fd->del_dis_ts.secs, fd->del_dis_ts.nsecs / 1000000, MSECS);
784 case(TS_PREC_FIXED_USEC):
785 case(TS_PREC_AUTO_USEC):
786 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
787 (gint32) fd->del_dis_ts.secs, fd->del_dis_ts.nsecs / 1000, USECS);
789 case(TS_PREC_FIXED_NSEC):
790 case(TS_PREC_AUTO_NSEC):
791 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
792 (gint32) fd->del_dis_ts.secs, fd->del_dis_ts.nsecs, NSECS);
795 g_assert_not_reached();
797 cinfo->col_data[col] = cinfo->col_buf[col];
798 strcpy(cinfo->col_expr[col],"frame.time_delta_displayed");
799 strcpy(cinfo->col_expr_val[col],cinfo->col_buf[col]);
802 /* To do: Add check_col checks to the col_add* routines */
805 col_set_abs_time(frame_data *fd, column_info *cinfo, int col)
810 COL_CHECK_REF_TIME(fd, cinfo, col);
812 then = fd->abs_ts.secs;
813 tmp = localtime(&then);
815 switch(timestamp_get_precision()) {
816 case(TS_PREC_FIXED_SEC):
817 case(TS_PREC_AUTO_SEC):
818 g_snprintf(cinfo->col_buf[col], COL_MAX_LEN,
824 case(TS_PREC_FIXED_DSEC):
825 case(TS_PREC_AUTO_DSEC):
826 g_snprintf(cinfo->col_buf[col], COL_MAX_LEN,
827 "%02d:%02d:%02d.%01ld",
831 (long)fd->abs_ts.nsecs / 100000000);
833 case(TS_PREC_FIXED_CSEC):
834 case(TS_PREC_AUTO_CSEC):
835 g_snprintf(cinfo->col_buf[col], COL_MAX_LEN,
836 "%02d:%02d:%02d.%02ld",
840 (long)fd->abs_ts.nsecs / 10000000);
842 case(TS_PREC_FIXED_MSEC):
843 case(TS_PREC_AUTO_MSEC):
844 g_snprintf(cinfo->col_buf[col], COL_MAX_LEN,
845 "%02d:%02d:%02d.%03ld",
849 (long)fd->abs_ts.nsecs / 1000000);
851 case(TS_PREC_FIXED_USEC):
852 case(TS_PREC_AUTO_USEC):
853 g_snprintf(cinfo->col_buf[col], COL_MAX_LEN,
854 "%02d:%02d:%02d.%06ld",
858 (long)fd->abs_ts.nsecs / 1000);
860 case(TS_PREC_FIXED_NSEC):
861 case(TS_PREC_AUTO_NSEC):
862 g_snprintf(cinfo->col_buf[col], COL_MAX_LEN,
863 "%02d:%02d:%02d.%09ld",
867 (long)fd->abs_ts.nsecs);
870 g_assert_not_reached();
873 cinfo->col_buf[col][0] = '\0';
875 cinfo->col_data[col] = cinfo->col_buf[col];
876 strcpy(cinfo->col_expr[col],"frame.time");
877 strcpy(cinfo->col_expr_val[col],cinfo->col_buf[col]);
881 col_set_epoch_time(frame_data *fd, column_info *cinfo, int col)
884 COL_CHECK_REF_TIME(fd, cinfo, col);
886 switch(timestamp_get_precision()) {
887 case(TS_PREC_FIXED_SEC):
888 case(TS_PREC_AUTO_SEC):
889 display_epoch_time(cinfo->col_buf[col], COL_MAX_LEN,
890 fd->abs_ts.secs, fd->abs_ts.nsecs / 1000000000, SECS);
892 case(TS_PREC_FIXED_DSEC):
893 case(TS_PREC_AUTO_DSEC):
894 display_epoch_time(cinfo->col_buf[col], COL_MAX_LEN,
895 fd->abs_ts.secs, fd->abs_ts.nsecs / 100000000, DSECS);
897 case(TS_PREC_FIXED_CSEC):
898 case(TS_PREC_AUTO_CSEC):
899 display_epoch_time(cinfo->col_buf[col], COL_MAX_LEN,
900 fd->abs_ts.secs, fd->abs_ts.nsecs / 10000000, CSECS);
902 case(TS_PREC_FIXED_MSEC):
903 case(TS_PREC_AUTO_MSEC):
904 display_epoch_time(cinfo->col_buf[col], COL_MAX_LEN,
905 fd->abs_ts.secs, fd->abs_ts.nsecs / 1000000, MSECS);
907 case(TS_PREC_FIXED_USEC):
908 case(TS_PREC_AUTO_USEC):
909 display_epoch_time(cinfo->col_buf[col], COL_MAX_LEN,
910 fd->abs_ts.secs, fd->abs_ts.nsecs / 1000, USECS);
912 case(TS_PREC_FIXED_NSEC):
913 case(TS_PREC_AUTO_NSEC):
914 display_epoch_time(cinfo->col_buf[col], COL_MAX_LEN,
915 fd->abs_ts.secs, fd->abs_ts.nsecs, NSECS);
918 g_assert_not_reached();
920 cinfo->col_data[col] = cinfo->col_buf[col];
921 strcpy(cinfo->col_expr[col],"frame.time_delta");
922 strcpy(cinfo->col_expr_val[col],cinfo->col_buf[col]);
924 /* Set the format of the variable time format.
925 XXX - this is called from "file.c" when the user changes the time
926 format they want for "command-line-specified" time; it's a bit ugly
927 that we have to export it, but if we go to a CList-like widget that
928 invokes callbacks to get the text for the columns rather than
929 requiring us to stuff the text into the widget from outside, we
930 might be able to clean this up. */
932 col_set_cls_time(frame_data *fd, column_info *cinfo, gint col)
934 switch (timestamp_get_type()) {
936 col_set_abs_time(fd, cinfo, col);
939 case TS_ABSOLUTE_WITH_DATE:
940 col_set_abs_date_time(fd, cinfo, col);
944 col_set_rel_time(fd, cinfo, col);
948 col_set_delta_time(fd, cinfo, col);
952 col_set_delta_time_dis(fd, cinfo, col);
956 col_set_epoch_time(fd, cinfo, col);
960 /* code is missing for this case, but I don't know which [jmayer20051219] */
967 col_set_time(column_info *cinfo, gint el, nstime_t *ts, char *fieldname)
971 g_assert(cinfo->col_first[el] >= 0);
973 for (col = cinfo->col_first[el]; col <= cinfo->col_last[el]; col++) {
974 if (cinfo->fmt_matx[col][el]) {
975 switch(timestamp_get_precision()) {
976 case(TS_PREC_FIXED_SEC):
977 case(TS_PREC_AUTO_SEC):
978 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
979 (gint32) ts->secs, ts->nsecs / 1000000000, SECS);
981 case(TS_PREC_FIXED_DSEC):
982 case(TS_PREC_AUTO_DSEC):
983 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
984 (gint32) ts->secs, ts->nsecs / 100000000, DSECS);
986 case(TS_PREC_FIXED_CSEC):
987 case(TS_PREC_AUTO_CSEC):
988 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
989 (gint32) ts->secs, ts->nsecs / 10000000, CSECS);
991 case(TS_PREC_FIXED_MSEC):
992 case(TS_PREC_AUTO_MSEC):
993 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
994 (gint32) ts->secs, ts->nsecs / 1000000, MSECS);
996 case(TS_PREC_FIXED_USEC):
997 case(TS_PREC_AUTO_USEC):
998 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
999 (gint32) ts->secs, ts->nsecs / 1000, USECS);
1001 case(TS_PREC_FIXED_NSEC):
1002 case(TS_PREC_AUTO_NSEC):
1003 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
1004 (gint32) ts->secs, ts->nsecs, NSECS);
1007 g_assert_not_reached();
1009 cinfo->col_data[col] = cinfo->col_buf[col];
1010 strcpy(cinfo->col_expr[col],fieldname);
1011 strcpy(cinfo->col_expr_val[col],cinfo->col_buf[col]);
1017 col_set_addr(packet_info *pinfo, int col, address *addr, gboolean is_res,
1020 struct e_in6_addr ipv6_addr;
1022 pinfo->cinfo->col_expr[col][0] = '\0';
1023 pinfo->cinfo->col_expr_val[col][0] = '\0';
1025 if (addr->type == AT_NONE)
1026 return; /* no address, nothing to do */
1029 get_addr_name_buf(addr, pinfo->cinfo->col_buf[col], COL_MAX_LEN);
1031 address_to_str_buf(addr, pinfo->cinfo->col_buf[col], COL_MAX_LEN);
1033 pinfo->cinfo->col_data[col] = pinfo->cinfo->col_buf[col];
1035 switch (addr->type) {
1039 strcpy(pinfo->cinfo->col_expr[col], "eth.src");
1041 strcpy(pinfo->cinfo->col_expr[col], "eth.dst");
1042 g_strlcpy(pinfo->cinfo->col_expr_val[col], ether_to_str(addr->data), COL_MAX_LEN);
1047 strcpy(pinfo->cinfo->col_expr[col], "ip.src");
1049 strcpy(pinfo->cinfo->col_expr[col], "ip.dst");
1050 g_strlcpy(pinfo->cinfo->col_expr_val[col], ip_to_str(addr->data), COL_MAX_LEN);
1055 strcpy(pinfo->cinfo->col_expr[col], "ipv6.src");
1057 strcpy(pinfo->cinfo->col_expr[col], "ipv6.dst");
1058 g_strlcpy(pinfo->cinfo->col_expr_val[col], ip6_to_str(&ipv6_addr), COL_MAX_LEN);
1063 strcpy(pinfo->cinfo->col_expr[col], "ddp.src");
1065 strcpy(pinfo->cinfo->col_expr[col], "ddp.dst");
1066 strcpy(pinfo->cinfo->col_expr_val[col], pinfo->cinfo->col_buf[col]);
1071 strcpy(pinfo->cinfo->col_expr[col], "arcnet.src");
1073 strcpy(pinfo->cinfo->col_expr[col], "arcnet.dst");
1074 strcpy(pinfo->cinfo->col_expr_val[col], pinfo->cinfo->col_buf[col]);
1079 strcpy(pinfo->cinfo->col_expr[col], "uri.src");
1081 strcpy(pinfo->cinfo->col_expr[col], "uri.dst");
1082 address_to_str_buf(addr, pinfo->cinfo->col_expr_val[col], COL_MAX_LEN);
1091 col_set_port(packet_info *pinfo, int col, gboolean is_res, gboolean is_src)
1096 port = pinfo->srcport;
1098 port = pinfo->destport;
1099 pinfo->cinfo->col_expr[col][0] = '\0';
1100 pinfo->cinfo->col_expr_val[col][0] = '\0';
1101 switch (pinfo->ptype) {
1105 g_strlcpy(pinfo->cinfo->col_buf[col], get_sctp_port(port), COL_MAX_LEN);
1107 g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "%u", port);
1112 g_strlcpy(pinfo->cinfo->col_buf[col], get_tcp_port(port), COL_MAX_LEN);
1114 g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "%u", port);
1116 strcpy(pinfo->cinfo->col_expr[col], "tcp.srcport");
1118 strcpy(pinfo->cinfo->col_expr[col], "tcp.dstport");
1119 g_snprintf(pinfo->cinfo->col_expr_val[col], COL_MAX_LEN, "%u", port);
1120 pinfo->cinfo->col_expr_val[col][COL_MAX_LEN - 1] = '\0';
1125 g_strlcpy(pinfo->cinfo->col_buf[col], get_udp_port(port), COL_MAX_LEN);
1127 g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "%u", port);
1129 strcpy(pinfo->cinfo->col_expr[col], "udp.srcport");
1131 strcpy(pinfo->cinfo->col_expr[col], "udp.dstport");
1132 g_snprintf(pinfo->cinfo->col_expr_val[col], COL_MAX_LEN, "%u", port);
1133 pinfo->cinfo->col_expr_val[col][COL_MAX_LEN - 1] = '\0';
1138 strcpy(pinfo->cinfo->col_expr[col], "ddp.src_socket");
1140 strcpy(pinfo->cinfo->col_expr[col], "ddp.dst_socket");
1141 g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "%u", port);
1142 g_snprintf(pinfo->cinfo->col_expr_val[col], COL_MAX_LEN, "%u", port);
1143 pinfo->cinfo->col_expr_val[col][COL_MAX_LEN - 1] = '\0';
1147 /* XXX - resolve IPX socket numbers */
1148 g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "0x%04x", port);
1150 strcpy(pinfo->cinfo->col_expr[col], "ipx.src.socket");
1152 strcpy(pinfo->cinfo->col_expr[col], "ipx.dst.socket");
1153 g_snprintf(pinfo->cinfo->col_expr_val[col], COL_MAX_LEN, "0x%04x", port);
1154 pinfo->cinfo->col_expr_val[col][COL_MAX_LEN - 1] = '\0';
1158 /* XXX - resolve IDP socket numbers */
1159 g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "0x%04x", port);
1161 strcpy(pinfo->cinfo->col_expr[col], "idp.src.socket");
1163 strcpy(pinfo->cinfo->col_expr[col], "idp.dst.socket");
1164 g_snprintf(pinfo->cinfo->col_expr_val[col], COL_MAX_LEN, "0x%04x", port);
1165 pinfo->cinfo->col_expr_val[col][COL_MAX_LEN - 1] = '\0';
1169 /* XXX - resolve USB endpoint numbers */
1170 g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "0x%08x", port);
1172 strcpy(pinfo->cinfo->col_expr[col], "usb.src.endpoint");
1174 strcpy(pinfo->cinfo->col_expr[col], "usb.dst.endpoint");
1175 g_snprintf(pinfo->cinfo->col_expr_val[col], COL_MAX_LEN, "0x%08x", port);
1176 pinfo->cinfo->col_expr_val[col][COL_MAX_LEN - 1] = '\0';
1182 pinfo->cinfo->col_buf[col][COL_MAX_LEN - 1] = '\0';
1183 pinfo->cinfo->col_data[col] = pinfo->cinfo->col_buf[col];
1187 * XXX - this should be in some common code in the epan directory, shared
1188 * by this code and packet-isdn.c.
1190 static const value_string channel_vals[] = {
1226 col_set_circuit_id(packet_info *pinfo, int col)
1228 pinfo->cinfo->col_expr[col][0] = '\0';
1229 pinfo->cinfo->col_expr_val[col][0] = '\0';
1230 switch (pinfo->ctype) {
1233 g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "%u", pinfo->circuit_id);
1234 strcpy(pinfo->cinfo->col_expr[col], "fr.dlci");
1235 g_snprintf(pinfo->cinfo->col_expr_val[col], COL_MAX_LEN, "%u", pinfo->circuit_id);
1236 pinfo->cinfo->col_expr_val[col][COL_MAX_LEN - 1] = '\0';
1240 g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "%s",
1241 val_to_str(pinfo->circuit_id, channel_vals, "Unknown (%u)"));
1242 strcpy(pinfo->cinfo->col_expr[col], "isdn.channel");
1243 g_snprintf(pinfo->cinfo->col_expr_val[col], COL_MAX_LEN, "%u", pinfo->circuit_id);
1244 pinfo->cinfo->col_expr_val[col][COL_MAX_LEN - 1] = '\0';
1248 g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "%u", pinfo->circuit_id);
1252 g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "%u", pinfo->circuit_id);
1253 strcpy(pinfo->cinfo->col_expr[col], "isup.cic");
1254 g_snprintf(pinfo->cinfo->col_expr_val[col], COL_MAX_LEN, "%u", pinfo->circuit_id);
1255 pinfo->cinfo->col_expr_val[col][COL_MAX_LEN - 1] = '\0';
1261 pinfo->cinfo->col_buf[col][COL_MAX_LEN - 1] = '\0';
1262 pinfo->cinfo->col_data[col] = pinfo->cinfo->col_buf[col];
1266 col_fill_in(packet_info *pinfo)
1270 for (i = 0; i < pinfo->cinfo->num_cols; i++) {
1271 switch (pinfo->cinfo->col_fmt[i]) {
1274 g_snprintf(pinfo->cinfo->col_buf[i], COL_MAX_LEN, "%u", pinfo->fd->num);
1275 pinfo->cinfo->col_data[i] = pinfo->cinfo->col_buf[i];
1276 strcpy(pinfo->cinfo->col_expr[i], "frame.number");
1277 strcpy(pinfo->cinfo->col_expr_val[i], pinfo->cinfo->col_buf[i]);
1281 col_set_cls_time(pinfo->fd, pinfo->cinfo, i);
1285 col_set_abs_time(pinfo->fd, pinfo->cinfo, i);
1288 case COL_ABS_DATE_TIME:
1289 col_set_abs_date_time(pinfo->fd, pinfo->cinfo, i);
1293 col_set_rel_time(pinfo->fd, pinfo->cinfo, i);
1296 case COL_DELTA_TIME:
1297 col_set_delta_time(pinfo->fd, pinfo->cinfo, i);
1300 case COL_DELTA_TIME_DIS:
1301 col_set_delta_time_dis(pinfo->fd, pinfo->cinfo, i);
1304 case COL_REL_CONV_TIME:
1305 case COL_DELTA_CONV_TIME:
1306 break; /* Will be set by various dissectors */
1309 case COL_RES_SRC: /* COL_DEF_SRC is currently just like COL_RES_SRC */
1310 col_set_addr(pinfo, i, &pinfo->src, TRUE, TRUE);
1314 col_set_addr(pinfo, i, &pinfo->src, FALSE, TRUE);
1317 case COL_DEF_DL_SRC:
1318 case COL_RES_DL_SRC:
1319 col_set_addr(pinfo, i, &pinfo->dl_src, TRUE, TRUE);
1322 case COL_UNRES_DL_SRC:
1323 col_set_addr(pinfo, i, &pinfo->dl_src, FALSE, TRUE);
1326 case COL_DEF_NET_SRC:
1327 case COL_RES_NET_SRC:
1328 col_set_addr(pinfo, i, &pinfo->net_src, TRUE, TRUE);
1331 case COL_UNRES_NET_SRC:
1332 col_set_addr(pinfo, i, &pinfo->net_src, FALSE, TRUE);
1336 case COL_RES_DST: /* COL_DEF_DST is currently just like COL_RES_DST */
1337 col_set_addr(pinfo, i, &pinfo->dst, TRUE, FALSE);
1341 col_set_addr(pinfo, i, &pinfo->dst, FALSE, FALSE);
1344 case COL_DEF_DL_DST:
1345 case COL_RES_DL_DST:
1346 col_set_addr(pinfo, i, &pinfo->dl_dst, TRUE, FALSE);
1349 case COL_UNRES_DL_DST:
1350 col_set_addr(pinfo, i, &pinfo->dl_dst, FALSE, FALSE);
1353 case COL_DEF_NET_DST:
1354 case COL_RES_NET_DST:
1355 col_set_addr(pinfo, i, &pinfo->net_dst, TRUE, FALSE);
1358 case COL_UNRES_NET_DST:
1359 col_set_addr(pinfo, i, &pinfo->net_dst, FALSE, FALSE);
1362 case COL_DEF_SRC_PORT:
1363 case COL_RES_SRC_PORT: /* COL_DEF_SRC_PORT is currently just like COL_RES_SRC_PORT */
1364 col_set_port(pinfo, i, TRUE, TRUE);
1367 case COL_UNRES_SRC_PORT:
1368 col_set_port(pinfo, i, FALSE, TRUE);
1371 case COL_DEF_DST_PORT:
1372 case COL_RES_DST_PORT: /* COL_DEF_DST_PORT is currently just like COL_RES_DST_PORT */
1373 col_set_port(pinfo, i, TRUE, FALSE);
1376 case COL_UNRES_DST_PORT:
1377 col_set_port(pinfo, i, FALSE, FALSE);
1380 case COL_PROTOCOL: /* currently done by dissectors */
1381 case COL_INFO: /* currently done by dissectors */
1384 case COL_PACKET_LENGTH:
1385 g_snprintf(pinfo->cinfo->col_buf[i], COL_MAX_LEN, "%u", pinfo->fd->pkt_len);
1386 pinfo->cinfo->col_data[i] = pinfo->cinfo->col_buf[i];
1387 strcpy(pinfo->cinfo->col_expr[i], "frame.pkt_len");
1388 strcpy(pinfo->cinfo->col_expr_val[i], pinfo->cinfo->col_buf[i]);
1391 case COL_CUMULATIVE_BYTES:
1392 g_snprintf(pinfo->cinfo->col_buf[i], COL_MAX_LEN, "%u", pinfo->fd->cum_bytes);
1393 pinfo->cinfo->col_data[i] = pinfo->cinfo->col_buf[i];
1397 g_snprintf(pinfo->cinfo->col_buf[i], COL_MAX_LEN, "0x%x", pinfo->oxid);
1398 pinfo->cinfo->col_buf[i][COL_MAX_LEN - 1] = '\0';
1399 pinfo->cinfo->col_data[i] = pinfo->cinfo->col_buf[i];
1403 g_snprintf(pinfo->cinfo->col_buf[i], COL_MAX_LEN, "0x%x", pinfo->rxid);
1404 pinfo->cinfo->col_buf[i][COL_MAX_LEN - 1] = '\0';
1405 pinfo->cinfo->col_data[i] = pinfo->cinfo->col_buf[i];
1408 case COL_IF_DIR: /* currently done by dissectors */
1411 case COL_CIRCUIT_ID:
1412 col_set_circuit_id(pinfo, i);
1416 g_snprintf(pinfo->cinfo->col_buf[i], COL_MAX_LEN, "0x%x", pinfo->src_idx);
1417 pinfo->cinfo->col_buf[i][COL_MAX_LEN - 1] = '\0';
1418 pinfo->cinfo->col_data[i] = pinfo->cinfo->col_buf[i];
1422 g_snprintf(pinfo->cinfo->col_buf[i], COL_MAX_LEN, "0x%x", pinfo->dst_idx);
1423 pinfo->cinfo->col_buf[i][COL_MAX_LEN - 1] = '\0';
1424 pinfo->cinfo->col_data[i] = pinfo->cinfo->col_buf[i];
1428 g_snprintf(pinfo->cinfo->col_buf[i], COL_MAX_LEN, "%u", pinfo->vsan);
1429 pinfo->cinfo->col_buf[i][COL_MAX_LEN - 1] = '\0';
1430 pinfo->cinfo->col_data[i] = pinfo->cinfo->col_buf[i];
1433 case COL_HPUX_SUBSYS: /* done by nettl disector */
1434 case COL_HPUX_DEVID: /* done by nettl disector */
1437 case COL_DCE_CALL: /* done by dcerpc */
1440 case COL_DCE_CTX: /* done by dcerpc */
1443 case COL_8021Q_VLAN_ID:
1446 case COL_DSCP_VALUE: /* done by packet-ip.c */
1449 case COL_COS_VALUE: /* done by packet-vlan.c */
1452 case COL_FR_DLCI: /* done by packet-fr.c */
1453 case COL_BSSGP_TLLI: /* done by packet-bssgp.c */
1456 case COL_EXPERT: /* done by expert.c */
1459 case COL_FREQ_CHAN: /* done by radio dissectors */
1462 case COL_CUSTOM: /* done by col_custom_set_fstr() called from proto.c */
1465 case NUM_COL_FMTS: /* keep compiler happy - shouldn't get here */
1466 g_assert_not_reached();