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"
44 /* Allocate all the data structures for constructing column data, given
45 the number of columns. */
47 col_setup(column_info *cinfo, gint num_cols)
51 cinfo->num_cols = num_cols;
52 cinfo->col_fmt = (gint *) g_malloc(sizeof(gint) * num_cols);
53 cinfo->fmt_matx = (gboolean **) g_malloc(sizeof(gboolean *) * num_cols);
54 cinfo->col_first = (int *) g_malloc(sizeof(int) * (NUM_COL_FMTS));
55 cinfo->col_last = (int *) g_malloc(sizeof(int) * (NUM_COL_FMTS));
56 cinfo->col_title = (gchar **) g_malloc(sizeof(gchar *) * num_cols);
57 cinfo->col_data = (const gchar **) g_malloc(sizeof(gchar *) * num_cols);
58 cinfo->col_buf = (gchar **) g_malloc(sizeof(gchar *) * num_cols);
59 cinfo->col_fence = (int *) g_malloc(sizeof(int) * num_cols);
60 cinfo->col_expr = (gchar **) g_malloc(sizeof(gchar *) * num_cols);
61 cinfo->col_expr_val = (gchar **) g_malloc(sizeof(gchar *) * num_cols);
63 for (i = 0; i < NUM_COL_FMTS; i++) {
64 cinfo->col_first[i] = -1;
65 cinfo->col_last[i] = -1;
69 /* Initialize the data structures for constructing column data. */
71 col_init(column_info *cinfo)
75 for (i = 0; i < cinfo->num_cols; i++) {
76 cinfo->col_buf[i][0] = '\0';
77 cinfo->col_data[i] = cinfo->col_buf[i];
78 cinfo->col_fence[i] = 0;
79 cinfo->col_expr[i][0] = '\0';
80 cinfo->col_expr_val[i][0] = '\0';
82 cinfo->writable = TRUE;
86 col_get_writable(column_info *cinfo)
88 return (cinfo ? cinfo->writable : FALSE);
92 col_set_writable(column_info *cinfo, gboolean writable)
95 cinfo->writable = writable;
98 /* Checks to see if a particular packet information element is needed for
101 check_col(column_info *cinfo, gint el) {
103 if (cinfo && cinfo->writable) {
104 /* We are constructing columns, and they're writable */
105 if (cinfo->col_first[el] >= 0) {
106 /* There is at least one column in that format */
113 /* Sets the fence for a column to be at the end of the column. */
115 col_set_fence(column_info *cinfo, gint el)
119 if (cinfo && cinfo->writable) {
120 /* We are constructing columns, and they're writable */
121 if (cinfo->col_first[el] >= 0) {
122 /* There is at least one column in that format */
123 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
124 if (cinfo->fmt_matx[i][el]) {
125 cinfo->col_fence[i] = strlen(cinfo->col_data[i]);
132 /* Use this to clear out a column, especially if you're going to be
133 appending to it later; at least on some platforms, it's more
134 efficient than using "col_add_str()" with a null string, and
135 more efficient than "col_set_str()" with a null string if you
136 later append to it, as the later append will cause a string
139 col_clear(column_info *cinfo, gint el)
144 g_assert(cinfo->col_first[el] >= 0);
145 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
146 if (cinfo->fmt_matx[i][el]) {
148 * At this point, either
150 * 1) col_data[i] is equal to col_buf[i], in which case we
151 * don't have to worry about copying col_data[i] to
154 * 2) col_data[i] isn't equal to col_buf[i], in which case
155 * the only thing that's been done to the column is
156 * "col_set_str()" calls and possibly "col_set_fence()"
157 * calls, in which case the fence is either unset and
158 * at the beginning of the string or set and at the end
159 * of the string - if it's at the beginning, we're just
160 * going to clear the column, and if it's at the end,
161 * we don't do anything.
163 fence = cinfo->col_fence[i];
164 if (fence == 0 || cinfo->col_buf[i] == cinfo->col_data[i]) {
166 * The fence isn't at the end of the column, or the column wasn't
167 * last set with "col_set_str()", so clear the column out.
169 cinfo->col_buf[i][fence] = '\0';
170 cinfo->col_data[i] = cinfo->col_buf[i];
172 cinfo->col_expr[i][0] = '\0';
173 cinfo->col_expr_val[i][0] = '\0';
178 #define COL_CHECK_APPEND(cinfo, i, max_len) \
179 if (cinfo->col_data[i] != cinfo->col_buf[i]) { \
180 /* This was set with "col_set_str()"; copy the string they \
181 set it to into the buffer, so we can append to it. */ \
182 strncpy(cinfo->col_buf[i], cinfo->col_data[i], max_len); \
183 cinfo->col_buf[i][max_len - 1] = '\0'; \
184 cinfo->col_data[i] = cinfo->col_buf[i]; \
187 #define COL_CHECK_REF_TIME(fd, cinfo, col) \
188 if(fd->flags.ref_time){ \
189 g_snprintf(cinfo->col_buf[col], COL_MAX_LEN, "*REF*"); \
190 cinfo->col_data[col] = cinfo->col_buf[col]; \
194 /* Use this if "str" points to something that will stay around (and thus
195 needn't be copied). */
197 col_set_str(column_info *cinfo, gint el, const gchar* str)
204 max_len = COL_MAX_INFO_LEN;
206 max_len = COL_MAX_LEN;
208 g_assert(cinfo->col_first[el] >= 0);
209 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
210 if (cinfo->fmt_matx[i][el]) {
211 fence = cinfo->col_fence[i];
214 * We will append the string after the fence.
215 * First arrange that we can append, if necessary.
217 COL_CHECK_APPEND(cinfo, i, max_len);
219 strncpy(&cinfo->col_buf[i][fence], str, max_len - fence);
220 cinfo->col_buf[i][max_len - 1] = 0;
223 * There's no fence, so we can just set the column to point
226 cinfo->col_data[i] = str;
232 /* Adds a vararg list to a packet info string. */
234 col_add_fstr(column_info *cinfo, gint el, const gchar *format, ...) {
240 g_assert(cinfo->col_first[el] >= 0);
242 max_len = COL_MAX_INFO_LEN;
244 max_len = COL_MAX_LEN;
246 va_start(ap, format);
247 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
248 if (cinfo->fmt_matx[i][el]) {
249 fence = cinfo->col_fence[i];
252 * We will append the string after the fence.
253 * First arrange that we can append, if necessary.
255 COL_CHECK_APPEND(cinfo, i, max_len);
258 * There's no fence, so we can just write to the string.
260 cinfo->col_data[i] = cinfo->col_buf[i];
262 g_vsnprintf(&cinfo->col_buf[i][fence], max_len - fence, format, ap);
263 cinfo->col_buf[i][max_len - 1] = '\0';
270 col_do_append_sep_va_fstr(column_info *cinfo, gint el, const gchar *separator,
271 const gchar *format, va_list ap)
274 size_t len, max_len, sep_len;
276 g_assert(cinfo->col_first[el] >= 0);
278 max_len = COL_MAX_INFO_LEN;
280 max_len = COL_MAX_LEN;
282 if (separator == NULL)
285 sep_len = strlen(separator);
286 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
287 if (cinfo->fmt_matx[i][el]) {
289 * First arrange that we can append, if necessary.
291 COL_CHECK_APPEND(cinfo, i, max_len);
293 len = strlen(cinfo->col_buf[i]);
296 * If we have a separator, append it if the column isn't empty.
298 if (separator != NULL) {
300 strncat(cinfo->col_buf[i], separator, max_len - len);
304 g_vsnprintf(&cinfo->col_buf[i][len], max_len - len, format, ap);
305 cinfo->col_buf[i][max_len-1] = 0;
310 /* Appends a vararg list to a packet info string. */
312 col_append_fstr(column_info *cinfo, gint el, const gchar *format, ...)
316 va_start(ap, format);
317 col_do_append_sep_va_fstr(cinfo, el, NULL, format, ap);
321 /* Appends a vararg list to a packet info string.
322 * Prefixes it with the given separator if the column is not empty. */
324 col_append_sep_fstr(column_info *cinfo, gint el, const gchar *separator,
325 const gchar *format, ...)
329 if (separator == NULL)
330 separator = ", "; /* default */
331 va_start(ap, format);
332 col_do_append_sep_va_fstr(cinfo, el, separator, format, ap);
338 /* Prepends a vararg list to a packet info string. */
339 #define COL_BUF_MAX_LEN (((COL_MAX_INFO_LEN) > (COL_MAX_LEN)) ? \
340 (COL_MAX_INFO_LEN) : (COL_MAX_LEN))
342 col_prepend_fstr(column_info *cinfo, gint el, const gchar *format, ...)
346 char orig_buf[COL_BUF_MAX_LEN];
350 g_assert(cinfo->col_first[el] >= 0);
352 max_len = COL_MAX_INFO_LEN;
354 max_len = COL_MAX_LEN;
356 va_start(ap, format);
357 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
358 if (cinfo->fmt_matx[i][el]) {
359 if (cinfo->col_data[i] != cinfo->col_buf[i]) {
360 /* This was set with "col_set_str()"; which is effectively const */
361 orig = cinfo->col_data[i];
363 strncpy(orig_buf, cinfo->col_buf[i], max_len);
364 orig_buf[max_len - 1] = '\0';
367 g_vsnprintf(cinfo->col_buf[i], max_len, format, ap);
368 cinfo->col_buf[i][max_len - 1] = '\0';
371 * Move the fence, unless it's at the beginning of the string.
373 if (cinfo->col_fence[i] > 0)
374 cinfo->col_fence[i] += strlen(cinfo->col_buf[i]);
376 strncat(cinfo->col_buf[i], orig, max_len);
377 cinfo->col_buf[i][max_len - 1] = '\0';
378 cinfo->col_data[i] = cinfo->col_buf[i];
384 col_prepend_fence_fstr(column_info *cinfo, gint el, const gchar *format, ...)
388 char orig_buf[COL_BUF_MAX_LEN];
392 g_assert(cinfo->col_first[el] >= 0);
394 max_len = COL_MAX_INFO_LEN;
396 max_len = COL_MAX_LEN;
398 va_start(ap, format);
399 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
400 if (cinfo->fmt_matx[i][el]) {
401 if (cinfo->col_data[i] != cinfo->col_buf[i]) {
402 /* This was set with "col_set_str()"; which is effectively const */
403 orig = cinfo->col_data[i];
405 strncpy(orig_buf, cinfo->col_buf[i], max_len);
406 orig_buf[max_len - 1] = '\0';
409 g_vsnprintf(cinfo->col_buf[i], max_len, format, ap);
410 cinfo->col_buf[i][max_len - 1] = '\0';
413 * Move the fence if it exists, else create a new fence at the
414 * end of the prepended data.
416 if (cinfo->col_fence[i] > 0) {
417 cinfo->col_fence[i] += strlen(cinfo->col_buf[i]);
419 cinfo->col_fence[i] = strlen(cinfo->col_buf[i]);
421 strncat(cinfo->col_buf[i], orig, max_len);
422 cinfo->col_buf[i][max_len - 1] = '\0';
423 cinfo->col_data[i] = cinfo->col_buf[i];
429 /* Use this if "str" points to something that won't stay around (and
430 must thus be copied). */
432 col_add_str(column_info *cinfo, gint el, const gchar* str)
438 g_assert(cinfo->col_first[el] >= 0);
440 max_len = COL_MAX_INFO_LEN;
442 max_len = COL_MAX_LEN;
444 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
445 if (cinfo->fmt_matx[i][el]) {
446 fence = cinfo->col_fence[i];
449 * We will append the string after the fence.
450 * First arrange that we can append, if necessary.
452 COL_CHECK_APPEND(cinfo, i, max_len);
455 * There's no fence, so we can just write to the string.
457 cinfo->col_data[i] = cinfo->col_buf[i];
459 strncpy(&cinfo->col_buf[i][fence], str, max_len - fence);
460 cinfo->col_buf[i][max_len - 1] = 0;
466 col_do_append_str(column_info *cinfo, gint el, const gchar* separator,
470 size_t len, max_len, sep_len;
472 g_assert(cinfo->col_first[el] >= 0);
474 max_len = COL_MAX_INFO_LEN;
476 max_len = COL_MAX_LEN;
478 if (separator == NULL)
481 sep_len = strlen(separator);
483 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
484 if (cinfo->fmt_matx[i][el]) {
486 * First arrange that we can append, if necessary.
488 COL_CHECK_APPEND(cinfo, i, max_len);
490 len = strlen(cinfo->col_buf[i]);
493 * If we have a separator, append it if the column isn't empty.
495 if (separator != NULL) {
497 strncat(cinfo->col_buf[i], separator, max_len - len);
501 strncat(cinfo->col_buf[i], str, max_len - len);
502 cinfo->col_buf[i][max_len - 1] = 0;
508 col_append_str(column_info *cinfo, gint el, const gchar* str)
510 col_do_append_str(cinfo, el, NULL, str);
514 col_append_sep_str(column_info *cinfo, gint el, const gchar* separator,
517 if (separator == NULL)
518 separator = ", "; /* default */
519 col_do_append_str(cinfo, el, separator, str);
523 col_set_abs_date_time(frame_data *fd, column_info *cinfo, int col)
528 COL_CHECK_REF_TIME(fd, cinfo, col);
530 then = fd->abs_ts.secs;
531 tmp = localtime(&then);
533 switch(timestamp_get_precision()) {
534 case(TS_PREC_FIXED_SEC):
535 case(TS_PREC_AUTO_SEC):
536 g_snprintf(cinfo->col_buf[col], COL_MAX_LEN,
537 "%04d-%02d-%02d %02d:%02d:%02d",
545 case(TS_PREC_FIXED_DSEC):
546 case(TS_PREC_AUTO_DSEC):
547 g_snprintf(cinfo->col_buf[col], COL_MAX_LEN,
548 "%04d-%02d-%02d %02d:%02d:%02d.%01ld",
555 (long)fd->abs_ts.nsecs / 100000000);
557 case(TS_PREC_FIXED_CSEC):
558 case(TS_PREC_AUTO_CSEC):
559 g_snprintf(cinfo->col_buf[col], COL_MAX_LEN,
560 "%04d-%02d-%02d %02d:%02d:%02d.%02ld",
567 (long)fd->abs_ts.nsecs / 10000000);
569 case(TS_PREC_FIXED_MSEC):
570 case(TS_PREC_AUTO_MSEC):
571 g_snprintf(cinfo->col_buf[col], COL_MAX_LEN,
572 "%04d-%02d-%02d %02d:%02d:%02d.%03ld",
579 (long)fd->abs_ts.nsecs / 1000000);
581 case(TS_PREC_FIXED_USEC):
582 case(TS_PREC_AUTO_USEC):
583 g_snprintf(cinfo->col_buf[col], COL_MAX_LEN,
584 "%04d-%02d-%02d %02d:%02d:%02d.%06ld",
591 (long)fd->abs_ts.nsecs / 1000);
593 case(TS_PREC_FIXED_NSEC):
594 case(TS_PREC_AUTO_NSEC):
595 g_snprintf(cinfo->col_buf[col], COL_MAX_LEN,
596 "%04d-%02d-%02d %02d:%02d:%02d.%09ld",
603 (long)fd->abs_ts.nsecs);
606 g_assert_not_reached();
609 cinfo->col_buf[col][0] = '\0';
611 cinfo->col_data[col] = cinfo->col_buf[col];
612 strcpy(cinfo->col_expr[col],"frame.time");
613 strcpy(cinfo->col_expr_val[col],cinfo->col_buf[col]);
617 col_set_rel_time(frame_data *fd, column_info *cinfo, int col)
619 COL_CHECK_REF_TIME(fd, cinfo, col);
621 switch(timestamp_get_precision()) {
622 case(TS_PREC_FIXED_SEC):
623 case(TS_PREC_AUTO_SEC):
624 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
625 (gint32) fd->rel_ts.secs, fd->rel_ts.nsecs / 1000000000, SECS);
627 case(TS_PREC_FIXED_DSEC):
628 case(TS_PREC_AUTO_DSEC):
629 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
630 (gint32) fd->rel_ts.secs, fd->rel_ts.nsecs / 100000000, DSECS);
632 case(TS_PREC_FIXED_CSEC):
633 case(TS_PREC_AUTO_CSEC):
634 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
635 (gint32) fd->rel_ts.secs, fd->rel_ts.nsecs / 10000000, CSECS);
637 case(TS_PREC_FIXED_MSEC):
638 case(TS_PREC_AUTO_MSEC):
639 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
640 (gint32) fd->rel_ts.secs, fd->rel_ts.nsecs / 1000000, MSECS);
642 case(TS_PREC_FIXED_USEC):
643 case(TS_PREC_AUTO_USEC):
644 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
645 (gint32) fd->rel_ts.secs, fd->rel_ts.nsecs / 1000, USECS);
647 case(TS_PREC_FIXED_NSEC):
648 case(TS_PREC_AUTO_NSEC):
649 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
650 (gint32) fd->rel_ts.secs, fd->rel_ts.nsecs, NSECS);
653 g_assert_not_reached();
655 cinfo->col_data[col] = cinfo->col_buf[col];
656 strcpy(cinfo->col_expr[col],"frame.time_relative");
657 strcpy(cinfo->col_expr_val[col],cinfo->col_buf[col]);
661 col_set_delta_time(frame_data *fd, column_info *cinfo, int col)
663 COL_CHECK_REF_TIME(fd, cinfo, col);
665 switch(timestamp_get_precision()) {
666 case(TS_PREC_FIXED_SEC):
667 case(TS_PREC_AUTO_SEC):
668 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
669 (gint32) fd->del_cap_ts.secs, fd->del_cap_ts.nsecs / 1000000000, SECS);
671 case(TS_PREC_FIXED_DSEC):
672 case(TS_PREC_AUTO_DSEC):
673 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
674 (gint32) fd->del_cap_ts.secs, fd->del_cap_ts.nsecs / 100000000, DSECS);
676 case(TS_PREC_FIXED_CSEC):
677 case(TS_PREC_AUTO_CSEC):
678 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
679 (gint32) fd->del_cap_ts.secs, fd->del_cap_ts.nsecs / 10000000, CSECS);
681 case(TS_PREC_FIXED_MSEC):
682 case(TS_PREC_AUTO_MSEC):
683 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
684 (gint32) fd->del_cap_ts.secs, fd->del_cap_ts.nsecs / 1000000, MSECS);
686 case(TS_PREC_FIXED_USEC):
687 case(TS_PREC_AUTO_USEC):
688 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
689 (gint32) fd->del_cap_ts.secs, fd->del_cap_ts.nsecs / 1000, USECS);
691 case(TS_PREC_FIXED_NSEC):
692 case(TS_PREC_AUTO_NSEC):
693 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
694 (gint32) fd->del_cap_ts.secs, fd->del_cap_ts.nsecs, NSECS);
697 g_assert_not_reached();
699 cinfo->col_data[col] = cinfo->col_buf[col];
700 strcpy(cinfo->col_expr[col],"frame.time_delta");
701 strcpy(cinfo->col_expr_val[col],cinfo->col_buf[col]);
705 col_set_delta_time_dis(frame_data *fd, column_info *cinfo, int col)
707 COL_CHECK_REF_TIME(fd, cinfo, col);
709 switch(timestamp_get_precision()) {
710 case(TS_PREC_FIXED_SEC):
711 case(TS_PREC_AUTO_SEC):
712 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
713 fd->del_dis_ts.secs, fd->del_dis_ts.nsecs / 1000000000, SECS);
715 case(TS_PREC_FIXED_DSEC):
716 case(TS_PREC_AUTO_DSEC):
717 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
718 fd->del_dis_ts.secs, fd->del_dis_ts.nsecs / 100000000, DSECS);
720 case(TS_PREC_FIXED_CSEC):
721 case(TS_PREC_AUTO_CSEC):
722 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
723 fd->del_dis_ts.secs, fd->del_dis_ts.nsecs / 10000000, CSECS);
725 case(TS_PREC_FIXED_MSEC):
726 case(TS_PREC_AUTO_MSEC):
727 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
728 fd->del_dis_ts.secs, fd->del_dis_ts.nsecs / 1000000, MSECS);
730 case(TS_PREC_FIXED_USEC):
731 case(TS_PREC_AUTO_USEC):
732 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
733 fd->del_dis_ts.secs, fd->del_dis_ts.nsecs / 1000, USECS);
735 case(TS_PREC_FIXED_NSEC):
736 case(TS_PREC_AUTO_NSEC):
737 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
738 fd->del_dis_ts.secs, fd->del_dis_ts.nsecs, NSECS);
741 g_assert_not_reached();
743 cinfo->col_data[col] = cinfo->col_buf[col];
744 strcpy(cinfo->col_expr[col],"frame.time_delta_displayed");
745 strcpy(cinfo->col_expr_val[col],cinfo->col_buf[col]);
748 /* To do: Add check_col checks to the col_add* routines */
751 col_set_abs_time(frame_data *fd, column_info *cinfo, int col)
756 COL_CHECK_REF_TIME(fd, cinfo, col);
758 then = fd->abs_ts.secs;
759 tmp = localtime(&then);
761 switch(timestamp_get_precision()) {
762 case(TS_PREC_FIXED_SEC):
763 case(TS_PREC_AUTO_SEC):
764 g_snprintf(cinfo->col_buf[col], COL_MAX_LEN,
770 case(TS_PREC_FIXED_DSEC):
771 case(TS_PREC_AUTO_DSEC):
772 g_snprintf(cinfo->col_buf[col], COL_MAX_LEN,
773 "%02d:%02d:%02d.%01ld",
777 (long)fd->abs_ts.nsecs / 100000000);
779 case(TS_PREC_FIXED_CSEC):
780 case(TS_PREC_AUTO_CSEC):
781 g_snprintf(cinfo->col_buf[col], COL_MAX_LEN,
782 "%02d:%02d:%02d.%02ld",
786 (long)fd->abs_ts.nsecs / 10000000);
788 case(TS_PREC_FIXED_MSEC):
789 case(TS_PREC_AUTO_MSEC):
790 g_snprintf(cinfo->col_buf[col], COL_MAX_LEN,
791 "%02d:%02d:%02d.%03ld",
795 (long)fd->abs_ts.nsecs / 1000000);
797 case(TS_PREC_FIXED_USEC):
798 case(TS_PREC_AUTO_USEC):
799 g_snprintf(cinfo->col_buf[col], COL_MAX_LEN,
800 "%02d:%02d:%02d.%06ld",
804 (long)fd->abs_ts.nsecs / 1000);
806 case(TS_PREC_FIXED_NSEC):
807 case(TS_PREC_AUTO_NSEC):
808 g_snprintf(cinfo->col_buf[col], COL_MAX_LEN,
809 "%02d:%02d:%02d.%09ld",
813 (long)fd->abs_ts.nsecs);
816 g_assert_not_reached();
819 cinfo->col_buf[col][0] = '\0';
821 cinfo->col_data[col] = cinfo->col_buf[col];
822 strcpy(cinfo->col_expr[col],"frame.time");
823 strcpy(cinfo->col_expr_val[col],cinfo->col_buf[col]);
827 col_set_epoch_time(frame_data *fd, column_info *cinfo, int col)
830 COL_CHECK_REF_TIME(fd, cinfo, col);
832 switch(timestamp_get_precision()) {
833 case(TS_PREC_FIXED_SEC):
834 case(TS_PREC_AUTO_SEC):
835 display_epoch_time(cinfo->col_buf[col], COL_MAX_LEN,
836 fd->abs_ts.secs, fd->abs_ts.nsecs / 1000000000, SECS);
838 case(TS_PREC_FIXED_DSEC):
839 case(TS_PREC_AUTO_DSEC):
840 display_epoch_time(cinfo->col_buf[col], COL_MAX_LEN,
841 fd->abs_ts.secs, fd->abs_ts.nsecs / 100000000, DSECS);
843 case(TS_PREC_FIXED_CSEC):
844 case(TS_PREC_AUTO_CSEC):
845 display_epoch_time(cinfo->col_buf[col], COL_MAX_LEN,
846 fd->abs_ts.secs, fd->abs_ts.nsecs / 10000000, CSECS);
848 case(TS_PREC_FIXED_MSEC):
849 case(TS_PREC_AUTO_MSEC):
850 display_epoch_time(cinfo->col_buf[col], COL_MAX_LEN,
851 fd->abs_ts.secs, fd->abs_ts.nsecs / 1000000, MSECS);
853 case(TS_PREC_FIXED_USEC):
854 case(TS_PREC_AUTO_USEC):
855 display_epoch_time(cinfo->col_buf[col], COL_MAX_LEN,
856 fd->abs_ts.secs, fd->abs_ts.nsecs / 1000, USECS);
858 case(TS_PREC_FIXED_NSEC):
859 case(TS_PREC_AUTO_NSEC):
860 display_epoch_time(cinfo->col_buf[col], COL_MAX_LEN,
861 fd->abs_ts.secs, fd->abs_ts.nsecs, NSECS);
864 g_assert_not_reached();
866 cinfo->col_data[col] = cinfo->col_buf[col];
867 strcpy(cinfo->col_expr[col],"frame.time_delta");
868 strcpy(cinfo->col_expr_val[col],cinfo->col_buf[col]);
870 /* Set the format of the variable time format.
871 XXX - this is called from "file.c" when the user changes the time
872 format they want for "command-line-specified" time; it's a bit ugly
873 that we have to export it, but if we go to a CList-like widget that
874 invokes callbacks to get the text for the columns rather than
875 requiring us to stuff the text into the widget from outside, we
876 might be able to clean this up. */
878 col_set_cls_time(frame_data *fd, column_info *cinfo, gint col)
880 switch (timestamp_get_type()) {
882 col_set_abs_time(fd, cinfo, col);
885 case TS_ABSOLUTE_WITH_DATE:
886 col_set_abs_date_time(fd, cinfo, col);
890 col_set_rel_time(fd, cinfo, col);
894 col_set_delta_time(fd, cinfo, col);
898 col_set_delta_time_dis(fd, cinfo, col);
902 col_set_epoch_time(fd, cinfo, col);
906 /* code is missing for this case, but I don't know which [jmayer20051219] */
913 col_set_addr(packet_info *pinfo, int col, address *addr, gboolean is_res,
916 struct e_in6_addr ipv6_addr;
918 pinfo->cinfo->col_expr[col][0] = '\0';
919 pinfo->cinfo->col_expr_val[col][0] = '\0';
921 if (addr->type == AT_NONE)
922 return; /* no address, nothing to do */
925 get_addr_name_buf(addr, pinfo->cinfo->col_buf[col],COL_MAX_LEN-1);
927 switch (addr->type) {
930 /* XXX - should be done in "address_to_str_buf()", but that routine
931 doesn't know COL_MAX_LEN; it should be changed to take the
932 maximum length as an argument. */
933 strncpy(pinfo->cinfo->col_buf[col], addr->data, COL_MAX_LEN);
934 pinfo->cinfo->col_buf[col][COL_MAX_LEN - 1] = '\0';
938 address_to_str_buf(addr, pinfo->cinfo->col_buf[col], COL_MAX_LEN);
942 pinfo->cinfo->col_data[col] = pinfo->cinfo->col_buf[col];
944 switch (addr->type) {
948 strcpy(pinfo->cinfo->col_expr[col], "eth.src");
950 strcpy(pinfo->cinfo->col_expr[col], "eth.dst");
951 strncpy(pinfo->cinfo->col_expr_val[col], ether_to_str(addr->data), COL_MAX_LEN);
952 pinfo->cinfo->col_expr_val[col][COL_MAX_LEN - 1] = '\0';
957 strcpy(pinfo->cinfo->col_expr[col], "ip.src");
959 strcpy(pinfo->cinfo->col_expr[col], "ip.dst");
960 strncpy(pinfo->cinfo->col_expr_val[col], ip_to_str(addr->data), COL_MAX_LEN);
961 pinfo->cinfo->col_expr_val[col][COL_MAX_LEN - 1] = '\0';
966 strcpy(pinfo->cinfo->col_expr[col], "ipv6.src");
968 strcpy(pinfo->cinfo->col_expr[col], "ipv6.dst");
969 strncpy(pinfo->cinfo->col_expr_val[col], ip6_to_str(&ipv6_addr), COL_MAX_LEN);
970 pinfo->cinfo->col_expr_val[col][COL_MAX_LEN - 1] = '\0';
975 strcpy(pinfo->cinfo->col_expr[col], "ddp.src");
977 strcpy(pinfo->cinfo->col_expr[col], "ddp.dst");
978 strcpy(pinfo->cinfo->col_expr_val[col], pinfo->cinfo->col_buf[col]);
983 strcpy(pinfo->cinfo->col_expr[col], "arcnet.src");
985 strcpy(pinfo->cinfo->col_expr[col], "arcnet.dst");
986 strcpy(pinfo->cinfo->col_expr_val[col], pinfo->cinfo->col_buf[col]);
995 col_set_port(packet_info *pinfo, int col, gboolean is_res, gboolean is_src)
1000 port = pinfo->srcport;
1002 port = pinfo->destport;
1003 pinfo->cinfo->col_expr[col][0] = '\0';
1004 pinfo->cinfo->col_expr_val[col][0] = '\0';
1005 switch (pinfo->ptype) {
1009 strncpy(pinfo->cinfo->col_buf[col], get_sctp_port(port), COL_MAX_LEN);
1011 g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "%u", port);
1016 strncpy(pinfo->cinfo->col_buf[col], get_tcp_port(port), COL_MAX_LEN);
1018 g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "%u", port);
1020 strcpy(pinfo->cinfo->col_expr[col], "tcp.srcport");
1022 strcpy(pinfo->cinfo->col_expr[col], "tcp.dstport");
1023 g_snprintf(pinfo->cinfo->col_expr_val[col], COL_MAX_LEN, "%u", port);
1024 pinfo->cinfo->col_expr_val[col][COL_MAX_LEN - 1] = '\0';
1029 strncpy(pinfo->cinfo->col_buf[col], get_udp_port(port), COL_MAX_LEN);
1031 g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "%u", port);
1033 strcpy(pinfo->cinfo->col_expr[col], "udp.srcport");
1035 strcpy(pinfo->cinfo->col_expr[col], "udp.dstport");
1036 g_snprintf(pinfo->cinfo->col_expr_val[col], COL_MAX_LEN, "%u", port);
1037 pinfo->cinfo->col_expr_val[col][COL_MAX_LEN - 1] = '\0';
1042 strcpy(pinfo->cinfo->col_expr[col], "ddp.src_socket");
1044 strcpy(pinfo->cinfo->col_expr[col], "ddp.dst_socket");
1045 g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "%u", port);
1046 g_snprintf(pinfo->cinfo->col_expr_val[col], COL_MAX_LEN, "%u", port);
1047 pinfo->cinfo->col_expr_val[col][COL_MAX_LEN - 1] = '\0';
1051 /* XXX - resolve IPX socket numbers */
1052 g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "0x%04x", port);
1054 strcpy(pinfo->cinfo->col_expr[col], "ipx.src.socket");
1056 strcpy(pinfo->cinfo->col_expr[col], "ipx.dst.socket");
1057 g_snprintf(pinfo->cinfo->col_expr_val[col], COL_MAX_LEN, "0x%04x", port);
1058 pinfo->cinfo->col_expr_val[col][COL_MAX_LEN - 1] = '\0';
1062 /* XXX - resolve IDP socket numbers */
1063 g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "0x%04x", port);
1065 strcpy(pinfo->cinfo->col_expr[col], "idp.src.socket");
1067 strcpy(pinfo->cinfo->col_expr[col], "idp.dst.socket");
1068 g_snprintf(pinfo->cinfo->col_expr_val[col], COL_MAX_LEN, "0x%04x", port);
1069 pinfo->cinfo->col_expr_val[col][COL_MAX_LEN - 1] = '\0';
1073 /* XXX - resolve USB endpoint numbers */
1074 g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "0x%08x", port);
1076 strcpy(pinfo->cinfo->col_expr[col], "usb.src.endpoint");
1078 strcpy(pinfo->cinfo->col_expr[col], "usb.dst.endpoint");
1079 g_snprintf(pinfo->cinfo->col_expr_val[col], COL_MAX_LEN, "0x%08x", port);
1080 pinfo->cinfo->col_expr_val[col][COL_MAX_LEN - 1] = '\0';
1086 pinfo->cinfo->col_buf[col][COL_MAX_LEN - 1] = '\0';
1087 pinfo->cinfo->col_data[col] = pinfo->cinfo->col_buf[col];
1091 * XXX - this should be in some common code in the epan directory, shared
1092 * by this code and packet-isdn.c.
1094 static const value_string channel_vals[] = {
1130 col_set_circuit_id(packet_info *pinfo, int col)
1132 pinfo->cinfo->col_expr[col][0] = '\0';
1133 pinfo->cinfo->col_expr_val[col][0] = '\0';
1134 switch (pinfo->ctype) {
1137 g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "%u", pinfo->circuit_id);
1138 strcpy(pinfo->cinfo->col_expr[col], "fr.dlci");
1139 g_snprintf(pinfo->cinfo->col_expr_val[col], COL_MAX_LEN, "%u", pinfo->circuit_id);
1140 pinfo->cinfo->col_expr_val[col][COL_MAX_LEN - 1] = '\0';
1144 g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "%s",
1145 val_to_str(pinfo->circuit_id, channel_vals, "Unknown (%u)"));
1146 strcpy(pinfo->cinfo->col_expr[col], "isdn.channel");
1147 g_snprintf(pinfo->cinfo->col_expr_val[col], COL_MAX_LEN, "%u", pinfo->circuit_id);
1148 pinfo->cinfo->col_expr_val[col][COL_MAX_LEN - 1] = '\0';
1152 g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "%u", pinfo->circuit_id);
1156 g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "%u", pinfo->circuit_id);
1157 strcpy(pinfo->cinfo->col_expr[col], "isup.cic");
1158 g_snprintf(pinfo->cinfo->col_expr_val[col], COL_MAX_LEN, "%u", pinfo->circuit_id);
1159 pinfo->cinfo->col_expr_val[col][COL_MAX_LEN - 1] = '\0';
1165 pinfo->cinfo->col_buf[col][COL_MAX_LEN - 1] = '\0';
1166 pinfo->cinfo->col_data[col] = pinfo->cinfo->col_buf[col];
1170 col_fill_in(packet_info *pinfo)
1174 for (i = 0; i < pinfo->cinfo->num_cols; i++) {
1175 switch (pinfo->cinfo->col_fmt[i]) {
1178 g_snprintf(pinfo->cinfo->col_buf[i], COL_MAX_LEN, "%u", pinfo->fd->num);
1179 pinfo->cinfo->col_data[i] = pinfo->cinfo->col_buf[i];
1180 strcpy(pinfo->cinfo->col_expr[i], "frame.number");
1181 strcpy(pinfo->cinfo->col_expr_val[i], pinfo->cinfo->col_buf[i]);
1185 col_set_cls_time(pinfo->fd, pinfo->cinfo, i);
1189 col_set_abs_time(pinfo->fd, pinfo->cinfo, i);
1192 case COL_ABS_DATE_TIME:
1193 col_set_abs_date_time(pinfo->fd, pinfo->cinfo, i);
1197 col_set_rel_time(pinfo->fd, pinfo->cinfo, i);
1200 case COL_DELTA_TIME:
1201 col_set_delta_time(pinfo->fd, pinfo->cinfo, i);
1204 case COL_DELTA_TIME_DIS:
1205 col_set_delta_time_dis(pinfo->fd, pinfo->cinfo, i);
1209 case COL_RES_SRC: /* COL_DEF_SRC is currently just like COL_RES_SRC */
1210 col_set_addr(pinfo, i, &pinfo->src, TRUE, TRUE);
1214 col_set_addr(pinfo, i, &pinfo->src, FALSE, TRUE);
1217 case COL_DEF_DL_SRC:
1218 case COL_RES_DL_SRC:
1219 col_set_addr(pinfo, i, &pinfo->dl_src, TRUE, TRUE);
1222 case COL_UNRES_DL_SRC:
1223 col_set_addr(pinfo, i, &pinfo->dl_src, FALSE, TRUE);
1226 case COL_DEF_NET_SRC:
1227 case COL_RES_NET_SRC:
1228 col_set_addr(pinfo, i, &pinfo->net_src, TRUE, TRUE);
1231 case COL_UNRES_NET_SRC:
1232 col_set_addr(pinfo, i, &pinfo->net_src, FALSE, TRUE);
1236 case COL_RES_DST: /* COL_DEF_DST is currently just like COL_RES_DST */
1237 col_set_addr(pinfo, i, &pinfo->dst, TRUE, FALSE);
1241 col_set_addr(pinfo, i, &pinfo->dst, FALSE, FALSE);
1244 case COL_DEF_DL_DST:
1245 case COL_RES_DL_DST:
1246 col_set_addr(pinfo, i, &pinfo->dl_dst, TRUE, FALSE);
1249 case COL_UNRES_DL_DST:
1250 col_set_addr(pinfo, i, &pinfo->dl_dst, FALSE, FALSE);
1253 case COL_DEF_NET_DST:
1254 case COL_RES_NET_DST:
1255 col_set_addr(pinfo, i, &pinfo->net_dst, TRUE, FALSE);
1258 case COL_UNRES_NET_DST:
1259 col_set_addr(pinfo, i, &pinfo->net_dst, FALSE, FALSE);
1262 case COL_DEF_SRC_PORT:
1263 case COL_RES_SRC_PORT: /* COL_DEF_SRC_PORT is currently just like COL_RES_SRC_PORT */
1264 col_set_port(pinfo, i, TRUE, TRUE);
1267 case COL_UNRES_SRC_PORT:
1268 col_set_port(pinfo, i, FALSE, TRUE);
1271 case COL_DEF_DST_PORT:
1272 case COL_RES_DST_PORT: /* COL_DEF_DST_PORT is currently just like COL_RES_DST_PORT */
1273 col_set_port(pinfo, i, TRUE, FALSE);
1276 case COL_UNRES_DST_PORT:
1277 col_set_port(pinfo, i, FALSE, FALSE);
1280 case COL_PROTOCOL: /* currently done by dissectors */
1281 case COL_INFO: /* currently done by dissectors */
1284 case COL_PACKET_LENGTH:
1285 g_snprintf(pinfo->cinfo->col_buf[i], COL_MAX_LEN, "%u", pinfo->fd->pkt_len);
1286 pinfo->cinfo->col_data[i] = pinfo->cinfo->col_buf[i];
1287 strcpy(pinfo->cinfo->col_expr[i], "frame.pkt_len");
1288 strcpy(pinfo->cinfo->col_expr_val[i], pinfo->cinfo->col_buf[i]);
1291 case COL_CUMULATIVE_BYTES:
1292 g_snprintf(pinfo->cinfo->col_buf[i], COL_MAX_LEN, "%u", pinfo->fd->cum_bytes);
1293 pinfo->cinfo->col_data[i] = pinfo->cinfo->col_buf[i];
1297 g_snprintf(pinfo->cinfo->col_buf[i], COL_MAX_LEN, "0x%x", pinfo->oxid);
1298 pinfo->cinfo->col_buf[i][COL_MAX_LEN - 1] = '\0';
1299 pinfo->cinfo->col_data[i] = pinfo->cinfo->col_buf[i];
1303 g_snprintf(pinfo->cinfo->col_buf[i], COL_MAX_LEN, "0x%x", pinfo->rxid);
1304 pinfo->cinfo->col_buf[i][COL_MAX_LEN - 1] = '\0';
1305 pinfo->cinfo->col_data[i] = pinfo->cinfo->col_buf[i];
1308 case COL_IF_DIR: /* currently done by dissectors */
1311 case COL_CIRCUIT_ID:
1312 col_set_circuit_id(pinfo, i);
1316 g_snprintf(pinfo->cinfo->col_buf[i], COL_MAX_LEN, "0x%x", pinfo->src_idx);
1317 pinfo->cinfo->col_buf[i][COL_MAX_LEN - 1] = '\0';
1318 pinfo->cinfo->col_data[i] = pinfo->cinfo->col_buf[i];
1322 g_snprintf(pinfo->cinfo->col_buf[i], COL_MAX_LEN, "0x%x", pinfo->dst_idx);
1323 pinfo->cinfo->col_buf[i][COL_MAX_LEN - 1] = '\0';
1324 pinfo->cinfo->col_data[i] = pinfo->cinfo->col_buf[i];
1328 g_snprintf(pinfo->cinfo->col_buf[i], COL_MAX_LEN, "%u", pinfo->vsan);
1329 pinfo->cinfo->col_buf[i][COL_MAX_LEN - 1] = '\0';
1330 pinfo->cinfo->col_data[i] = pinfo->cinfo->col_buf[i];
1333 case COL_HPUX_SUBSYS: /* done by nettl disector */
1334 case COL_HPUX_DEVID: /* done by nettl disector */
1337 case COL_DCE_CALL: /* done by dcerpc */
1340 case COL_DCE_CTX: /* done by dcerpc */
1343 case COL_8021Q_VLAN_ID:
1346 case COL_DSCP_VALUE: /* done by packet-ip.c */
1349 case COL_COS_VALUE: /* done by packet-vlan.c */
1352 case COL_FR_DLCI: /* done by packet-fr.c */
1353 case COL_BSSGP_TLLI: /* done by packet-bssgp.c */
1356 case NUM_COL_FMTS: /* keep compiler happy - shouldn't get here */
1357 g_assert_not_reached();