2 * Routines for column utilities.
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@ethereal.com>
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 *col_info, gint num_cols)
51 col_info->num_cols = num_cols;
52 col_info->col_fmt = (gint *) g_malloc(sizeof(gint) * num_cols);
53 col_info->fmt_matx = (gboolean **) g_malloc(sizeof(gboolean *) * num_cols);
54 col_info->col_first = (int *) g_malloc(sizeof(int) * (NUM_COL_FMTS));
55 col_info->col_last = (int *) g_malloc(sizeof(int) * (NUM_COL_FMTS));
56 col_info->col_title = (gchar **) g_malloc(sizeof(gchar *) * num_cols);
57 col_info->col_data = (const gchar **) g_malloc(sizeof(gchar *) * num_cols);
58 col_info->col_buf = (gchar **) g_malloc(sizeof(gchar *) * num_cols);
59 col_info->col_fence = (int *) g_malloc(sizeof(int) * num_cols);
60 col_info->col_expr = (gchar **) g_malloc(sizeof(gchar *) * num_cols);
61 col_info->col_expr_val = (gchar **) g_malloc(sizeof(gchar *) * num_cols);
63 for (i = 0; i < NUM_COL_FMTS; i++) {
64 col_info->col_first[i] = -1;
65 col_info->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 /* Use this if "str" points to something that will stay around (and thus
188 needn't be copied). */
190 col_set_str(column_info *cinfo, gint el, const gchar* str)
197 max_len = COL_MAX_INFO_LEN;
199 max_len = COL_MAX_LEN;
201 g_assert(cinfo->col_first[el] >= 0);
202 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
203 if (cinfo->fmt_matx[i][el]) {
204 fence = cinfo->col_fence[i];
207 * We will append the string after the fence.
208 * First arrange that we can append, if necessary.
210 COL_CHECK_APPEND(cinfo, i, max_len);
212 strncpy(&cinfo->col_buf[i][fence], str, max_len - fence);
213 cinfo->col_buf[i][max_len - 1] = 0;
216 * There's no fence, so we can just set the column to point
219 cinfo->col_data[i] = str;
225 /* Adds a vararg list to a packet info string. */
227 col_add_fstr(column_info *cinfo, gint el, const gchar *format, ...) {
233 g_assert(cinfo->col_first[el] >= 0);
235 max_len = COL_MAX_INFO_LEN;
237 max_len = COL_MAX_LEN;
239 va_start(ap, format);
240 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
241 if (cinfo->fmt_matx[i][el]) {
242 fence = cinfo->col_fence[i];
245 * We will append the string after the fence.
246 * First arrange that we can append, if necessary.
248 COL_CHECK_APPEND(cinfo, i, max_len);
251 * There's no fence, so we can just write to the string.
253 cinfo->col_data[i] = cinfo->col_buf[i];
255 g_vsnprintf(&cinfo->col_buf[i][fence], max_len - fence, format, ap);
256 cinfo->col_buf[i][max_len - 1] = '\0';
263 col_do_append_sep_va_fstr(column_info *cinfo, gint el, const gchar *separator,
264 const gchar *format, va_list ap)
267 size_t len, max_len, sep_len;
269 g_assert(cinfo->col_first[el] >= 0);
271 max_len = COL_MAX_INFO_LEN;
273 max_len = COL_MAX_LEN;
275 if (separator == NULL)
278 sep_len = strlen(separator);
279 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
280 if (cinfo->fmt_matx[i][el]) {
282 * First arrange that we can append, if necessary.
284 COL_CHECK_APPEND(cinfo, i, max_len);
286 len = strlen(cinfo->col_buf[i]);
289 * If we have a separator, append it if the column isn't empty.
291 if (separator != NULL) {
293 strncat(cinfo->col_buf[i], separator, max_len - len);
297 g_vsnprintf(&cinfo->col_buf[i][len], max_len - len, format, ap);
298 cinfo->col_buf[i][max_len-1] = 0;
303 /* Appends a vararg list to a packet info string. */
305 col_append_fstr(column_info *cinfo, gint el, const gchar *format, ...)
309 va_start(ap, format);
310 col_do_append_sep_va_fstr(cinfo, el, NULL, format, ap);
314 /* Appends a vararg list to a packet info string.
315 * Prefixes it with the given separator if the column is not empty. */
317 col_append_sep_fstr(column_info *cinfo, gint el, const gchar *separator,
318 const gchar *format, ...)
322 if (separator == NULL)
323 separator = ", "; /* default */
324 va_start(ap, format);
325 col_do_append_sep_va_fstr(cinfo, el, separator, format, ap);
331 /* Prepends a vararg list to a packet info string. */
332 #define COL_BUF_MAX_LEN (((COL_MAX_INFO_LEN) > (COL_MAX_LEN)) ? \
333 (COL_MAX_INFO_LEN) : (COL_MAX_LEN))
335 col_prepend_fstr(column_info *cinfo, gint el, const gchar *format, ...)
339 char orig_buf[COL_BUF_MAX_LEN];
343 g_assert(cinfo->col_first[el] >= 0);
345 max_len = COL_MAX_INFO_LEN;
347 max_len = COL_MAX_LEN;
349 va_start(ap, format);
350 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
351 if (cinfo->fmt_matx[i][el]) {
352 if (cinfo->col_data[i] != cinfo->col_buf[i]) {
353 /* This was set with "col_set_str()"; which is effectively const */
354 orig = cinfo->col_data[i];
356 strncpy(orig_buf, cinfo->col_buf[i], max_len);
357 orig_buf[max_len - 1] = '\0';
360 g_vsnprintf(cinfo->col_buf[i], max_len, format, ap);
361 cinfo->col_buf[i][max_len - 1] = '\0';
364 * Move the fence, unless it's at the beginning of the string.
366 if (cinfo->col_fence[i] > 0)
367 cinfo->col_fence[i] += strlen(cinfo->col_buf[i]);
369 strncat(cinfo->col_buf[i], orig, max_len);
370 cinfo->col_buf[i][max_len - 1] = '\0';
371 cinfo->col_data[i] = cinfo->col_buf[i];
377 /* Use this if "str" points to something that won't stay around (and
378 must thus be copied). */
380 col_add_str(column_info *cinfo, gint el, const gchar* str)
386 g_assert(cinfo->col_first[el] >= 0);
388 max_len = COL_MAX_INFO_LEN;
390 max_len = COL_MAX_LEN;
392 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
393 if (cinfo->fmt_matx[i][el]) {
394 fence = cinfo->col_fence[i];
397 * We will append the string after the fence.
398 * First arrange that we can append, if necessary.
400 COL_CHECK_APPEND(cinfo, i, max_len);
403 * There's no fence, so we can just write to the string.
405 cinfo->col_data[i] = cinfo->col_buf[i];
407 strncpy(&cinfo->col_buf[i][fence], str, max_len - fence);
408 cinfo->col_buf[i][max_len - 1] = 0;
414 col_do_append_str(column_info *cinfo, gint el, const gchar* separator,
418 size_t len, max_len, sep_len;
420 g_assert(cinfo->col_first[el] >= 0);
422 max_len = COL_MAX_INFO_LEN;
424 max_len = COL_MAX_LEN;
426 if (separator == NULL)
429 sep_len = strlen(separator);
431 for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
432 if (cinfo->fmt_matx[i][el]) {
434 * First arrange that we can append, if necessary.
436 COL_CHECK_APPEND(cinfo, i, max_len);
438 len = strlen(cinfo->col_buf[i]);
441 * If we have a separator, append it if the column isn't empty.
443 if (separator != NULL) {
445 strncat(cinfo->col_buf[i], separator, max_len - len);
449 strncat(cinfo->col_buf[i], str, max_len - len);
450 cinfo->col_buf[i][max_len - 1] = 0;
456 col_append_str(column_info *cinfo, gint el, const gchar* str)
458 col_do_append_str(cinfo, el, NULL, str);
462 col_append_sep_str(column_info *cinfo, gint el, const gchar* separator,
465 if (separator == NULL)
466 separator = ", "; /* default */
467 col_do_append_str(cinfo, el, separator, str);
471 col_set_abs_date_time(frame_data *fd, column_info *cinfo, int col)
476 then = fd->abs_ts.secs;
477 tmp = localtime(&then);
479 switch(timestamp_get_precision()) {
480 case(TS_PREC_FIXED_SEC):
481 case(TS_PREC_AUTO_SEC):
482 g_snprintf(cinfo->col_buf[col], COL_MAX_LEN,
483 "%04d-%02d-%02d %02d:%02d:%02d",
491 case(TS_PREC_FIXED_DSEC):
492 case(TS_PREC_AUTO_DSEC):
493 g_snprintf(cinfo->col_buf[col], COL_MAX_LEN,
494 "%04d-%02d-%02d %02d:%02d:%02d.%01ld",
501 (long)fd->abs_ts.nsecs / 100000000);
503 case(TS_PREC_FIXED_CSEC):
504 case(TS_PREC_AUTO_CSEC):
505 g_snprintf(cinfo->col_buf[col], COL_MAX_LEN,
506 "%04d-%02d-%02d %02d:%02d:%02d.%02ld",
513 (long)fd->abs_ts.nsecs / 10000000);
515 case(TS_PREC_FIXED_MSEC):
516 case(TS_PREC_AUTO_MSEC):
517 g_snprintf(cinfo->col_buf[col], COL_MAX_LEN,
518 "%04d-%02d-%02d %02d:%02d:%02d.%03ld",
525 (long)fd->abs_ts.nsecs / 1000000);
527 case(TS_PREC_FIXED_USEC):
528 case(TS_PREC_AUTO_USEC):
529 g_snprintf(cinfo->col_buf[col], COL_MAX_LEN,
530 "%04d-%02d-%02d %02d:%02d:%02d.%06ld",
537 (long)fd->abs_ts.nsecs / 1000);
539 case(TS_PREC_FIXED_NSEC):
540 case(TS_PREC_AUTO_NSEC):
541 g_snprintf(cinfo->col_buf[col], COL_MAX_LEN,
542 "%04d-%02d-%02d %02d:%02d:%02d.%09ld",
549 (long)fd->abs_ts.nsecs);
552 g_assert_not_reached();
555 cinfo->col_buf[col][0] = '\0';
557 cinfo->col_data[col] = cinfo->col_buf[col];
558 strcpy(cinfo->col_expr[col],"frame.time");
559 strcpy(cinfo->col_expr_val[col],cinfo->col_buf[col]);
563 col_set_rel_time(frame_data *fd, column_info *cinfo, int col)
565 switch(timestamp_get_precision()) {
566 case(TS_PREC_FIXED_SEC):
567 case(TS_PREC_AUTO_SEC):
568 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
569 fd->rel_ts.secs, fd->rel_ts.nsecs / 1000000000, SECS);
571 case(TS_PREC_FIXED_DSEC):
572 case(TS_PREC_AUTO_DSEC):
573 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
574 fd->rel_ts.secs, fd->rel_ts.nsecs / 100000000, DSECS);
576 case(TS_PREC_FIXED_CSEC):
577 case(TS_PREC_AUTO_CSEC):
578 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
579 fd->rel_ts.secs, fd->rel_ts.nsecs / 10000000, CSECS);
581 case(TS_PREC_FIXED_MSEC):
582 case(TS_PREC_AUTO_MSEC):
583 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
584 fd->rel_ts.secs, fd->rel_ts.nsecs / 1000000, MSECS);
586 case(TS_PREC_FIXED_USEC):
587 case(TS_PREC_AUTO_USEC):
588 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
589 fd->rel_ts.secs, fd->rel_ts.nsecs / 1000, USECS);
591 case(TS_PREC_FIXED_NSEC):
592 case(TS_PREC_AUTO_NSEC):
593 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
594 fd->rel_ts.secs, fd->rel_ts.nsecs, NSECS);
597 g_assert_not_reached();
599 cinfo->col_data[col] = cinfo->col_buf[col];
600 strcpy(cinfo->col_expr[col],"frame.time_relative");
601 strcpy(cinfo->col_expr_val[col],cinfo->col_buf[col]);
605 col_set_delta_time(frame_data *fd, column_info *cinfo, int col)
607 switch(timestamp_get_precision()) {
608 case(TS_PREC_FIXED_SEC):
609 case(TS_PREC_AUTO_SEC):
610 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
611 fd->del_ts.secs, fd->del_ts.nsecs / 1000000000, SECS);
613 case(TS_PREC_FIXED_DSEC):
614 case(TS_PREC_AUTO_DSEC):
615 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
616 fd->del_ts.secs, fd->del_ts.nsecs / 100000000, DSECS);
618 case(TS_PREC_FIXED_CSEC):
619 case(TS_PREC_AUTO_CSEC):
620 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
621 fd->del_ts.secs, fd->del_ts.nsecs / 10000000, CSECS);
623 case(TS_PREC_FIXED_MSEC):
624 case(TS_PREC_AUTO_MSEC):
625 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
626 fd->del_ts.secs, fd->del_ts.nsecs / 1000000, MSECS);
628 case(TS_PREC_FIXED_USEC):
629 case(TS_PREC_AUTO_USEC):
630 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
631 fd->del_ts.secs, fd->del_ts.nsecs / 1000, USECS);
633 case(TS_PREC_FIXED_NSEC):
634 case(TS_PREC_AUTO_NSEC):
635 display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
636 fd->del_ts.secs, fd->del_ts.nsecs, NSECS);
639 g_assert_not_reached();
641 cinfo->col_data[col] = cinfo->col_buf[col];
642 strcpy(cinfo->col_expr[col],"frame.time_delta");
643 strcpy(cinfo->col_expr_val[col],cinfo->col_buf[col]);
646 /* To do: Add check_col checks to the col_add* routines */
649 col_set_abs_time(frame_data *fd, column_info *cinfo, int col)
654 then = fd->abs_ts.secs;
655 tmp = localtime(&then);
657 switch(timestamp_get_precision()) {
658 case(TS_PREC_FIXED_SEC):
659 case(TS_PREC_AUTO_SEC):
660 g_snprintf(cinfo->col_buf[col], COL_MAX_LEN,
666 case(TS_PREC_FIXED_DSEC):
667 case(TS_PREC_AUTO_DSEC):
668 g_snprintf(cinfo->col_buf[col], COL_MAX_LEN,
669 "%02d:%02d:%02d.%01ld",
673 (long)fd->abs_ts.nsecs / 100000000);
675 case(TS_PREC_FIXED_CSEC):
676 case(TS_PREC_AUTO_CSEC):
677 g_snprintf(cinfo->col_buf[col], COL_MAX_LEN,
678 "%02d:%02d:%02d.%02ld",
682 (long)fd->abs_ts.nsecs / 10000000);
684 case(TS_PREC_FIXED_MSEC):
685 case(TS_PREC_AUTO_MSEC):
686 g_snprintf(cinfo->col_buf[col], COL_MAX_LEN,
687 "%02d:%02d:%02d.%03ld",
691 (long)fd->abs_ts.nsecs / 1000000);
693 case(TS_PREC_FIXED_USEC):
694 case(TS_PREC_AUTO_USEC):
695 g_snprintf(cinfo->col_buf[col], COL_MAX_LEN,
696 "%02d:%02d:%02d.%06ld",
700 (long)fd->abs_ts.nsecs / 1000);
702 case(TS_PREC_FIXED_NSEC):
703 case(TS_PREC_AUTO_NSEC):
704 g_snprintf(cinfo->col_buf[col], COL_MAX_LEN,
705 "%02d:%02d:%02d.%09ld",
709 (long)fd->abs_ts.nsecs);
712 g_assert_not_reached();
715 cinfo->col_buf[col][0] = '\0';
717 cinfo->col_data[col] = cinfo->col_buf[col];
718 strcpy(cinfo->col_expr[col],"frame.time");
719 strcpy(cinfo->col_expr_val[col],cinfo->col_buf[col]);
722 /* Add "command-line-specified" time.
723 XXX - this is called from "file.c" when the user changes the time
724 format they want for "command-line-specified" time; it's a bit ugly
725 that we have to export it, but if we go to a CList-like widget that
726 invokes callbacks to get the text for the columns rather than
727 requiring us to stuff the text into the widget from outside, we
728 might be able to clean this up. */
730 col_set_cls_time(frame_data *fd, column_info *cinfo, int col)
732 switch (timestamp_get_type()) {
734 col_set_abs_time(fd, cinfo, col);
737 case TS_ABSOLUTE_WITH_DATE:
738 col_set_abs_date_time(fd, cinfo, col);
742 col_set_rel_time(fd, cinfo, col);
746 col_set_delta_time(fd, cinfo, col);
752 col_set_addr(packet_info *pinfo, int col, address *addr, gboolean is_res,
755 struct e_in6_addr ipv6_addr;
757 pinfo->cinfo->col_expr[col][0] = '\0';
758 pinfo->cinfo->col_expr_val[col][0] = '\0';
760 if (addr->type == AT_NONE)
761 return; /* no address, nothing to do */
764 get_addr_name_buf(addr, pinfo->cinfo->col_buf[col],COL_MAX_LEN-1);
766 switch (addr->type) {
769 /* XXX - should be done in "address_to_str_buf()", but that routine
770 doesn't know COL_MAX_LEN; it should be changed to take the
771 maximum length as an argument. */
772 strncpy(pinfo->cinfo->col_buf[col], addr->data, COL_MAX_LEN);
773 pinfo->cinfo->col_buf[col][COL_MAX_LEN - 1] = '\0';
777 address_to_str_buf(addr, pinfo->cinfo->col_buf[col], COL_MAX_LEN);
781 pinfo->cinfo->col_data[col] = pinfo->cinfo->col_buf[col];
783 switch (addr->type) {
787 strcpy(pinfo->cinfo->col_expr[col], "eth.src");
789 strcpy(pinfo->cinfo->col_expr[col], "eth.dst");
790 strncpy(pinfo->cinfo->col_expr_val[col], ether_to_str(addr->data), COL_MAX_LEN);
791 pinfo->cinfo->col_expr_val[col][COL_MAX_LEN - 1] = '\0';
796 strcpy(pinfo->cinfo->col_expr[col], "ip.src");
798 strcpy(pinfo->cinfo->col_expr[col], "ip.dst");
799 strncpy(pinfo->cinfo->col_expr_val[col], ip_to_str(addr->data), COL_MAX_LEN);
800 pinfo->cinfo->col_expr_val[col][COL_MAX_LEN - 1] = '\0';
805 strcpy(pinfo->cinfo->col_expr[col], "ipv6.src");
807 strcpy(pinfo->cinfo->col_expr[col], "ipv6.dst");
808 strncpy(pinfo->cinfo->col_expr_val[col], ip6_to_str(&ipv6_addr), COL_MAX_LEN);
809 pinfo->cinfo->col_expr_val[col][COL_MAX_LEN - 1] = '\0';
814 strcpy(pinfo->cinfo->col_expr[col], "ddp.src");
816 strcpy(pinfo->cinfo->col_expr[col], "ddp.dst");
817 strcpy(pinfo->cinfo->col_expr_val[col], pinfo->cinfo->col_buf[col]);
822 strcpy(pinfo->cinfo->col_expr[col], "arcnet.src");
824 strcpy(pinfo->cinfo->col_expr[col], "arcnet.dst");
825 strcpy(pinfo->cinfo->col_expr_val[col], pinfo->cinfo->col_buf[col]);
834 col_set_port(packet_info *pinfo, int col, gboolean is_res, gboolean is_src)
839 port = pinfo->srcport;
841 port = pinfo->destport;
842 pinfo->cinfo->col_expr[col][0] = '\0';
843 pinfo->cinfo->col_expr_val[col][0] = '\0';
844 switch (pinfo->ptype) {
848 strncpy(pinfo->cinfo->col_buf[col], get_sctp_port(port), COL_MAX_LEN);
850 g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "%u", port);
855 strncpy(pinfo->cinfo->col_buf[col], get_tcp_port(port), COL_MAX_LEN);
857 g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "%u", port);
859 strcpy(pinfo->cinfo->col_expr[col], "tcp.srcport");
861 strcpy(pinfo->cinfo->col_expr[col], "tcp.dstport");
862 g_snprintf(pinfo->cinfo->col_expr_val[col], COL_MAX_LEN, "%u", port);
863 pinfo->cinfo->col_expr_val[col][COL_MAX_LEN - 1] = '\0';
868 strncpy(pinfo->cinfo->col_buf[col], get_udp_port(port), COL_MAX_LEN);
870 g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "%u", port);
872 strcpy(pinfo->cinfo->col_expr[col], "udp.srcport");
874 strcpy(pinfo->cinfo->col_expr[col], "udp.dstport");
875 g_snprintf(pinfo->cinfo->col_expr_val[col], COL_MAX_LEN, "%u", port);
876 pinfo->cinfo->col_expr_val[col][COL_MAX_LEN - 1] = '\0';
881 strcpy(pinfo->cinfo->col_expr[col], "ddp.src_socket");
883 strcpy(pinfo->cinfo->col_expr[col], "ddp.dst_socket");
884 g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "%u", port);
885 g_snprintf(pinfo->cinfo->col_expr_val[col], COL_MAX_LEN, "%u", port);
886 pinfo->cinfo->col_expr_val[col][COL_MAX_LEN - 1] = '\0';
890 /* XXX - resolve IPX socket numbers */
891 g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "0x%04x", port);
893 strcpy(pinfo->cinfo->col_expr[col], "ipx.src.socket");
895 strcpy(pinfo->cinfo->col_expr[col], "ipx.dst.socket");
896 g_snprintf(pinfo->cinfo->col_expr_val[col], COL_MAX_LEN, "0x%04x", port);
897 pinfo->cinfo->col_expr_val[col][COL_MAX_LEN - 1] = '\0';
901 /* XXX - resolve IDP socket numbers */
902 g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "0x%04x", port);
904 strcpy(pinfo->cinfo->col_expr[col], "idp.src.socket");
906 strcpy(pinfo->cinfo->col_expr[col], "idp.dst.socket");
907 g_snprintf(pinfo->cinfo->col_expr_val[col], COL_MAX_LEN, "0x%04x", port);
908 pinfo->cinfo->col_expr_val[col][COL_MAX_LEN - 1] = '\0';
914 pinfo->cinfo->col_buf[col][COL_MAX_LEN - 1] = '\0';
915 pinfo->cinfo->col_data[col] = pinfo->cinfo->col_buf[col];
919 * XXX - this should be in some common code in the epan directory, shared
920 * by this code and packet-isdn.c.
922 static const value_string channel_vals[] = {
958 col_set_circuit_id(packet_info *pinfo, int col)
960 pinfo->cinfo->col_expr[col][0] = '\0';
961 pinfo->cinfo->col_expr_val[col][0] = '\0';
962 switch (pinfo->ctype) {
965 g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "%u", pinfo->circuit_id);
966 strcpy(pinfo->cinfo->col_expr[col], "fr.dlci");
967 g_snprintf(pinfo->cinfo->col_expr_val[col], COL_MAX_LEN, "%u", pinfo->circuit_id);
968 pinfo->cinfo->col_expr_val[col][COL_MAX_LEN - 1] = '\0';
972 g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "%s",
973 val_to_str(pinfo->circuit_id, channel_vals, "Unknown (%u)"));
974 strcpy(pinfo->cinfo->col_expr[col], "isdn.channel");
975 g_snprintf(pinfo->cinfo->col_expr_val[col], COL_MAX_LEN, "%u", pinfo->circuit_id);
976 pinfo->cinfo->col_expr_val[col][COL_MAX_LEN - 1] = '\0';
980 g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "%u", pinfo->circuit_id);
984 g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "%u", pinfo->circuit_id);
985 strcpy(pinfo->cinfo->col_expr[col], "isup.cic");
986 g_snprintf(pinfo->cinfo->col_expr_val[col], COL_MAX_LEN, "%u", pinfo->circuit_id);
987 pinfo->cinfo->col_expr_val[col][COL_MAX_LEN - 1] = '\0';
993 pinfo->cinfo->col_buf[col][COL_MAX_LEN - 1] = '\0';
994 pinfo->cinfo->col_data[col] = pinfo->cinfo->col_buf[col];
998 fill_in_columns(packet_info *pinfo)
1002 for (i = 0; i < pinfo->cinfo->num_cols; i++) {
1003 switch (pinfo->cinfo->col_fmt[i]) {
1006 g_snprintf(pinfo->cinfo->col_buf[i], COL_MAX_LEN, "%u", pinfo->fd->num);
1007 pinfo->cinfo->col_data[i] = pinfo->cinfo->col_buf[i];
1008 strcpy(pinfo->cinfo->col_expr[i], "frame.number");
1009 strcpy(pinfo->cinfo->col_expr_val[i], pinfo->cinfo->col_buf[i]);
1013 if(pinfo->fd->flags.ref_time){
1014 g_snprintf(pinfo->cinfo->col_buf[i], COL_MAX_LEN, "*REF*");
1015 pinfo->cinfo->col_data[i] = pinfo->cinfo->col_buf[i];
1017 col_set_cls_time(pinfo->fd, pinfo->cinfo, i);
1022 if(pinfo->fd->flags.ref_time){
1023 g_snprintf(pinfo->cinfo->col_buf[i], COL_MAX_LEN, "*REF*");
1024 pinfo->cinfo->col_data[i] = pinfo->cinfo->col_buf[i];
1026 col_set_abs_time(pinfo->fd, pinfo->cinfo, i);
1030 case COL_ABS_DATE_TIME:
1031 if(pinfo->fd->flags.ref_time){
1032 g_snprintf(pinfo->cinfo->col_buf[i], COL_MAX_LEN, "*REF*");
1033 pinfo->cinfo->col_data[i] = pinfo->cinfo->col_buf[i];
1035 col_set_abs_date_time(pinfo->fd, pinfo->cinfo, i);
1040 if(pinfo->fd->flags.ref_time){
1041 g_snprintf(pinfo->cinfo->col_buf[i], COL_MAX_LEN, "*REF*");
1042 pinfo->cinfo->col_data[i] = pinfo->cinfo->col_buf[i];
1044 col_set_rel_time(pinfo->fd, pinfo->cinfo, i);
1048 case COL_DELTA_TIME:
1049 if(pinfo->fd->flags.ref_time){
1050 g_snprintf(pinfo->cinfo->col_buf[i], COL_MAX_LEN, "*REF*");
1051 pinfo->cinfo->col_data[i] = pinfo->cinfo->col_buf[i];
1053 col_set_delta_time(pinfo->fd, pinfo->cinfo, i);
1058 case COL_RES_SRC: /* COL_DEF_SRC is currently just like COL_RES_SRC */
1059 col_set_addr(pinfo, i, &pinfo->src, TRUE, TRUE);
1063 col_set_addr(pinfo, i, &pinfo->src, FALSE, TRUE);
1066 case COL_DEF_DL_SRC:
1067 case COL_RES_DL_SRC:
1068 col_set_addr(pinfo, i, &pinfo->dl_src, TRUE, TRUE);
1071 case COL_UNRES_DL_SRC:
1072 col_set_addr(pinfo, i, &pinfo->dl_src, FALSE, TRUE);
1075 case COL_DEF_NET_SRC:
1076 case COL_RES_NET_SRC:
1077 col_set_addr(pinfo, i, &pinfo->net_src, TRUE, TRUE);
1080 case COL_UNRES_NET_SRC:
1081 col_set_addr(pinfo, i, &pinfo->net_src, FALSE, TRUE);
1085 case COL_RES_DST: /* COL_DEF_DST is currently just like COL_RES_DST */
1086 col_set_addr(pinfo, i, &pinfo->dst, TRUE, FALSE);
1090 col_set_addr(pinfo, i, &pinfo->dst, FALSE, FALSE);
1093 case COL_DEF_DL_DST:
1094 case COL_RES_DL_DST:
1095 col_set_addr(pinfo, i, &pinfo->dl_dst, TRUE, FALSE);
1098 case COL_UNRES_DL_DST:
1099 col_set_addr(pinfo, i, &pinfo->dl_dst, FALSE, FALSE);
1102 case COL_DEF_NET_DST:
1103 case COL_RES_NET_DST:
1104 col_set_addr(pinfo, i, &pinfo->net_dst, TRUE, FALSE);
1107 case COL_UNRES_NET_DST:
1108 col_set_addr(pinfo, i, &pinfo->net_dst, FALSE, FALSE);
1111 case COL_DEF_SRC_PORT:
1112 case COL_RES_SRC_PORT: /* COL_DEF_SRC_PORT is currently just like COL_RES_SRC_PORT */
1113 col_set_port(pinfo, i, TRUE, TRUE);
1116 case COL_UNRES_SRC_PORT:
1117 col_set_port(pinfo, i, FALSE, TRUE);
1120 case COL_DEF_DST_PORT:
1121 case COL_RES_DST_PORT: /* COL_DEF_DST_PORT is currently just like COL_RES_DST_PORT */
1122 col_set_port(pinfo, i, TRUE, FALSE);
1125 case COL_UNRES_DST_PORT:
1126 col_set_port(pinfo, i, FALSE, FALSE);
1129 case COL_PROTOCOL: /* currently done by dissectors */
1130 case COL_INFO: /* currently done by dissectors */
1133 case COL_PACKET_LENGTH:
1134 g_snprintf(pinfo->cinfo->col_buf[i], COL_MAX_LEN, "%u", pinfo->fd->pkt_len);
1135 pinfo->cinfo->col_data[i] = pinfo->cinfo->col_buf[i];
1136 strcpy(pinfo->cinfo->col_expr[i], "frame.pkt_len");
1137 strcpy(pinfo->cinfo->col_expr_val[i], pinfo->cinfo->col_buf[i]);
1140 case COL_CUMULATIVE_BYTES:
1141 g_snprintf(pinfo->cinfo->col_buf[i], COL_MAX_LEN, "%u", pinfo->fd->cum_bytes);
1142 pinfo->cinfo->col_data[i] = pinfo->cinfo->col_buf[i];
1146 g_snprintf(pinfo->cinfo->col_buf[i], COL_MAX_LEN, "0x%x", pinfo->oxid);
1147 pinfo->cinfo->col_buf[i][COL_MAX_LEN - 1] = '\0';
1148 pinfo->cinfo->col_data[i] = pinfo->cinfo->col_buf[i];
1152 g_snprintf(pinfo->cinfo->col_buf[i], COL_MAX_LEN, "0x%x", pinfo->rxid);
1153 pinfo->cinfo->col_buf[i][COL_MAX_LEN - 1] = '\0';
1154 pinfo->cinfo->col_data[i] = pinfo->cinfo->col_buf[i];
1157 case COL_IF_DIR: /* currently done by dissectors */
1160 case COL_CIRCUIT_ID:
1161 col_set_circuit_id(pinfo, i);
1165 g_snprintf(pinfo->cinfo->col_buf[i], COL_MAX_LEN, "0x%x", pinfo->src_idx);
1166 pinfo->cinfo->col_buf[i][COL_MAX_LEN - 1] = '\0';
1167 pinfo->cinfo->col_data[i] = pinfo->cinfo->col_buf[i];
1171 g_snprintf(pinfo->cinfo->col_buf[i], COL_MAX_LEN, "0x%x", pinfo->dst_idx);
1172 pinfo->cinfo->col_buf[i][COL_MAX_LEN - 1] = '\0';
1173 pinfo->cinfo->col_data[i] = pinfo->cinfo->col_buf[i];
1177 g_snprintf(pinfo->cinfo->col_buf[i], COL_MAX_LEN, "%u", pinfo->vsan);
1178 pinfo->cinfo->col_buf[i][COL_MAX_LEN - 1] = '\0';
1179 pinfo->cinfo->col_data[i] = pinfo->cinfo->col_buf[i];
1182 case COL_HPUX_SUBSYS: /* done by nettl disector */
1183 case COL_HPUX_DEVID: /* done by nettl disector */
1186 case COL_DCE_CALL: /* done by dcerpc */
1189 case NUM_COL_FMTS: /* keep compiler happy - shouldn't get here */
1190 g_assert_not_reached();