Improved custom columns with custom title.
[metze/wireshark/wip.git] / epan / column-utils.c
1 /* column-utils.c
2  * Routines for column utilities.
3  *
4  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 1998 Gerald Combs
9  *
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.
14  *
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.
19  *
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.
23  */
24
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #include <string.h>
30 #include <time.h>
31
32 #include "column-utils.h"
33 #include "timestamp.h"
34 #include "sna-utils.h"
35 #include "atalk-utils.h"
36 #include "to_str.h"
37 #include "packet_info.h"
38 #include "pint.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"
44
45 #include <epan/strutil.h>
46 #include <epan/epan.h>
47
48 static column_info *ci;
49
50 /* Allocate all the data structures for constructing column data, given
51    the number of columns. */
52 void
53 col_setup(column_info *cinfo, gint num_cols)
54 {
55   int i;
56
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);
69
70   for (i = 0; i < NUM_COL_FMTS; i++) {
71     cinfo->col_first[i] = -1;
72     cinfo->col_last[i] = -1;
73   }
74 }
75
76 /* Initialize the data structures for constructing column data. */
77 void
78 col_init(column_info *cinfo)
79 {
80   int i;
81
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';
88   }
89   cinfo->writable = TRUE;
90 }
91
92 gboolean
93 col_get_writable(column_info *cinfo)
94 {
95         return (cinfo ? cinfo->writable : FALSE);
96 }
97
98 void
99 col_set_writable(column_info *cinfo, gboolean writable)
100 {
101         if (cinfo)
102                 cinfo->writable = writable;
103 }
104
105 /* Checks to see if a particular packet information element is needed for
106    the packet list */
107 gint
108 check_col(column_info *cinfo, gint el) {
109
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 */
114       return TRUE;
115     }
116   }
117   return FALSE;
118 }
119
120 /* Sets the fence for a column to be at the end of the column. */
121 void
122 col_set_fence(column_info *cinfo, gint el)
123 {
124   int i;
125
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]);
133         }
134       }
135     }
136   }
137 }
138
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
144    copy to be done. */
145 void
146 col_clear(column_info *cinfo, gint el)
147 {
148   int    i;
149   int    fence;
150
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]) {
154       /*
155        * At this point, either
156        *
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
159        *      col_buf[i];
160        *
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.
169        */
170       fence = cinfo->col_fence[i];
171       if (fence == 0 || cinfo->col_buf[i] == cinfo->col_data[i]) {
172         /*
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.
175          */
176         cinfo->col_buf[i][fence] = '\0';
177         cinfo->col_data[i] = cinfo->col_buf[i];
178       }
179       cinfo->col_expr[i][0] = '\0';
180       cinfo->col_expr_val[i][0] = '\0';
181     }
182   }
183 }
184
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];                     \
191   }
192
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];                 \
197     return;                                                     \
198   }
199
200 /* Use this if "str" points to something that will stay around (and thus
201    needn't be copied). */
202 void
203 col_set_str(column_info *cinfo, gint el, const gchar* str)
204 {
205   int i;
206   int fence;
207   size_t max_len;
208
209   if (el == COL_INFO)
210         max_len = COL_MAX_INFO_LEN;
211   else
212         max_len = COL_MAX_LEN;
213
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];
218       if (fence != 0) {
219         /*
220          * We will append the string after the fence.
221          * First arrange that we can append, if necessary.
222          */
223         COL_CHECK_APPEND(cinfo, i, max_len);
224
225         g_strlcpy(&cinfo->col_buf[i][fence], str, max_len - fence);
226       } else {
227         /*
228          * There's no fence, so we can just set the column to point
229          * to the string.
230          */
231         cinfo->col_data[i] = str;
232       }
233     }
234   }
235 }
236
237 /* Adds a vararg list to a packet info string. */
238 void
239 col_add_fstr(column_info *cinfo, gint el, const gchar *format, ...) {
240   va_list ap;
241   int     i;
242   int     fence;
243   size_t  max_len;
244
245   g_assert(cinfo->col_first[el] >= 0);
246   if (el == COL_INFO)
247         max_len = COL_MAX_INFO_LEN;
248   else
249         max_len = COL_MAX_LEN;
250
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];
255       if (fence != 0) {
256         /*
257          * We will append the string after the fence.
258          * First arrange that we can append, if necessary.
259          */
260         COL_CHECK_APPEND(cinfo, i, max_len);
261       } else {
262         /*
263          * There's no fence, so we can just write to the string.
264          */
265         cinfo->col_data[i] = cinfo->col_buf[i];
266       }
267       g_vsnprintf(&cinfo->col_buf[i][fence], max_len - fence, format, ap);
268       cinfo->col_buf[i][max_len - 1] = '\0';
269     }
270   }
271   va_end(ap);
272 }
273
274 void
275 col_custom_set_fstr(const gchar *field_name, const gchar *format, ...)
276 {
277   va_list ap;
278   int     i;
279
280   if (!have_custom_cols(ci))
281     return;
282
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);
292     }
293   }
294   va_end(ap);
295 }
296
297 void
298 col_custom_prime_edt(epan_dissect_t *edt, column_info *cinfo)
299 {
300   int i;
301   dfilter_t *dfilter_code;
302
303   ci = cinfo; /* Save this into the static variable ci for use by
304                * col_custom_set_fstr() later. */
305
306   if(!have_custom_cols(cinfo))
307       return;
308
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);
315     }
316   }
317 }
318
319 gboolean
320 have_custom_cols(column_info *cinfo)
321 {
322   /* The same as check_col(), but without the check to see if the column
323    * is writable. */
324   if (cinfo && cinfo->col_first[COL_CUSTOM] >= 0)
325     return TRUE;
326   else
327     return FALSE;
328 }
329
330 static void
331 col_do_append_sep_va_fstr(column_info *cinfo, gint el, const gchar *separator,
332                           const gchar *format, va_list ap)
333 {
334   int     i;
335   size_t  len, max_len, sep_len;
336
337   g_assert(cinfo->col_first[el] >= 0);
338   if (el == COL_INFO)
339         max_len = COL_MAX_INFO_LEN;
340   else
341         max_len = COL_MAX_LEN;
342
343   if (separator == NULL)
344     sep_len = 0;
345   else
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]) {
349       /*
350        * First arrange that we can append, if necessary.
351        */
352       COL_CHECK_APPEND(cinfo, i, max_len);
353
354       len = strlen(cinfo->col_buf[i]);
355
356       /*
357        * If we have a separator, append it if the column isn't empty.
358        */
359       if (separator != NULL) {
360         if (len != 0) {
361           g_strlcat(cinfo->col_buf[i], separator, max_len);
362           len += sep_len;
363         }
364       }
365       g_vsnprintf(&cinfo->col_buf[i][len], max_len - len, format, ap);
366       cinfo->col_buf[i][max_len-1] = 0;
367     }
368   }
369 }
370
371 /* Appends a vararg list to a packet info string. */
372 void
373 col_append_fstr(column_info *cinfo, gint el, const gchar *format, ...)
374 {
375   va_list ap;
376
377   va_start(ap, format);
378   col_do_append_sep_va_fstr(cinfo, el, NULL, format, ap);
379   va_end(ap);
380 }
381
382 /* Appends a vararg list to a packet info string.
383  * Prefixes it with the given separator if the column is not empty. */
384 void
385 col_append_sep_fstr(column_info *cinfo, gint el, const gchar *separator,
386                 const gchar *format, ...)
387 {
388   va_list ap;
389
390   if (separator == NULL)
391     separator = ", ";    /* default */
392   va_start(ap, format);
393   col_do_append_sep_va_fstr(cinfo, el, separator, format, ap);
394   va_end(ap);
395 }
396
397
398
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))
402 void
403 col_prepend_fstr(column_info *cinfo, gint el, const gchar *format, ...)
404 {
405   va_list     ap;
406   int         i;
407   char        orig_buf[COL_BUF_MAX_LEN];
408   const char *orig;
409   size_t      max_len;
410
411   g_assert(cinfo->col_first[el] >= 0);
412   if (el == COL_INFO)
413         max_len = COL_MAX_INFO_LEN;
414   else
415         max_len = COL_MAX_LEN;
416
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];
423       } else {
424         g_strlcpy(orig_buf, cinfo->col_buf[i], max_len);
425         orig = orig_buf;
426       }
427       g_vsnprintf(cinfo->col_buf[i], max_len, format, ap);
428       cinfo->col_buf[i][max_len - 1] = '\0';
429
430       /*
431        * Move the fence, unless it's at the beginning of the string.
432        */
433       if (cinfo->col_fence[i] > 0)
434         cinfo->col_fence[i] += strlen(cinfo->col_buf[i]);
435
436       g_strlcat(cinfo->col_buf[i], orig, max_len);
437       cinfo->col_data[i] = cinfo->col_buf[i];
438     }
439   }
440   va_end(ap);
441 }
442 void
443 col_prepend_fence_fstr(column_info *cinfo, gint el, const gchar *format, ...)
444 {
445   va_list     ap;
446   int         i;
447   char        orig_buf[COL_BUF_MAX_LEN];
448   const char *orig;
449   size_t      max_len;
450
451   g_assert(cinfo->col_first[el] >= 0);
452   if (el == COL_INFO)
453         max_len = COL_MAX_INFO_LEN;
454   else
455         max_len = COL_MAX_LEN;
456
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];
463       } else {
464         g_strlcpy(orig_buf, cinfo->col_buf[i], max_len);
465         orig = orig_buf;
466       }
467       g_vsnprintf(cinfo->col_buf[i], max_len, format, ap);
468       cinfo->col_buf[i][max_len - 1] = '\0';
469
470       /*
471        * Move the fence if it exists, else create a new fence at the
472        * end of the prepended data.
473        */
474       if (cinfo->col_fence[i] > 0) {
475         cinfo->col_fence[i] += strlen(cinfo->col_buf[i]);
476       } else {
477         cinfo->col_fence[i]  = strlen(cinfo->col_buf[i]);
478       }
479       g_strlcat(cinfo->col_buf[i], orig, max_len);
480       cinfo->col_data[i] = cinfo->col_buf[i];
481     }
482   }
483   va_end(ap);
484 }
485
486 /* Use this if "str" points to something that won't stay around (and
487    must thus be copied). */
488 void
489 col_add_str(column_info *cinfo, gint el, const gchar* str)
490 {
491   int    i;
492   int    fence;
493   size_t max_len;
494
495   g_assert(cinfo->col_first[el] >= 0);
496   if (el == COL_INFO)
497         max_len = COL_MAX_INFO_LEN;
498   else
499         max_len = COL_MAX_LEN;
500
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];
504       if (fence != 0) {
505         /*
506          * We will append the string after the fence.
507          * First arrange that we can append, if necessary.
508          */
509         COL_CHECK_APPEND(cinfo, i, max_len);
510       } else {
511         /*
512          * There's no fence, so we can just write to the string.
513          */
514         cinfo->col_data[i] = cinfo->col_buf[i];
515       }
516       g_strlcpy(&cinfo->col_buf[i][fence], str, max_len - fence);
517     }
518   }
519 }
520
521 static void
522 col_do_append_str(column_info *cinfo, gint el, const gchar* separator,
523     const gchar* str)
524 {
525   int    i;
526   size_t len, max_len, sep_len;
527
528   g_assert(cinfo->col_first[el] >= 0);
529   if (el == COL_INFO)
530         max_len = COL_MAX_INFO_LEN;
531   else
532         max_len = COL_MAX_LEN;
533
534   if (separator == NULL)
535     sep_len = 0;
536   else
537     sep_len = strlen(separator);
538
539   for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
540     if (cinfo->fmt_matx[i][el]) {
541       /*
542        * First arrange that we can append, if necessary.
543        */
544       COL_CHECK_APPEND(cinfo, i, max_len);
545
546       len = cinfo->col_buf[i][0];
547
548       /*
549        * If we have a separator, append it if the column isn't empty.
550        */
551       if (separator != NULL) {
552         if (len != 0) {
553           g_strlcat(cinfo->col_buf[i], separator, max_len);
554         }
555       }
556       g_strlcat(cinfo->col_buf[i], str, max_len);
557     }
558   }
559 }
560
561 void
562 col_append_str(column_info *cinfo, gint el, const gchar* str)
563 {
564   col_do_append_str(cinfo, el, NULL, str);
565 }
566
567 void
568 col_append_sep_str(column_info *cinfo, gint el, const gchar* separator,
569     const gchar* str)
570 {
571   if (separator == NULL)
572     separator = ", ";    /* default */
573   col_do_append_str(cinfo, el, separator, str);
574 }
575
576 static void
577 col_set_abs_date_time(frame_data *fd, column_info *cinfo, int col)
578 {
579   struct tm *tmp;
580   time_t then;
581
582   COL_CHECK_REF_TIME(fd, cinfo, col);
583
584   then = fd->abs_ts.secs;
585   tmp = localtime(&then);
586   if (tmp != NULL) {
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",
592              tmp->tm_year + 1900,
593              tmp->tm_mon + 1,
594              tmp->tm_mday,
595              tmp->tm_hour,
596              tmp->tm_min,
597              tmp->tm_sec);
598                   break;
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",
603              tmp->tm_year + 1900,
604              tmp->tm_mon + 1,
605              tmp->tm_mday,
606              tmp->tm_hour,
607              tmp->tm_min,
608              tmp->tm_sec,
609              (long)fd->abs_ts.nsecs / 100000000);
610                   break;
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",
615              tmp->tm_year + 1900,
616              tmp->tm_mon + 1,
617              tmp->tm_mday,
618              tmp->tm_hour,
619              tmp->tm_min,
620              tmp->tm_sec,
621              (long)fd->abs_ts.nsecs / 10000000);
622                   break;
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",
627              tmp->tm_year + 1900,
628              tmp->tm_mon + 1,
629              tmp->tm_mday,
630              tmp->tm_hour,
631              tmp->tm_min,
632              tmp->tm_sec,
633              (long)fd->abs_ts.nsecs / 1000000);
634                   break;
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",
639              tmp->tm_year + 1900,
640              tmp->tm_mon + 1,
641              tmp->tm_mday,
642              tmp->tm_hour,
643              tmp->tm_min,
644              tmp->tm_sec,
645              (long)fd->abs_ts.nsecs / 1000);
646                   break;
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",
651              tmp->tm_year + 1900,
652              tmp->tm_mon + 1,
653              tmp->tm_mday,
654              tmp->tm_hour,
655              tmp->tm_min,
656              tmp->tm_sec,
657              (long)fd->abs_ts.nsecs);
658                   break;
659           default:
660                   g_assert_not_reached();
661           }
662   } else {
663     cinfo->col_buf[col][0] = '\0';
664   }
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]);
668 }
669
670 static void
671 col_set_rel_time(frame_data *fd, column_info *cinfo, int col)
672 {
673   COL_CHECK_REF_TIME(fd, cinfo, col);
674
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);
680                   break;
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);
685                   break;
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);
690                   break;
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);
695                   break;
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);
700                   break;
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);
705                   break;
706           default:
707                   g_assert_not_reached();
708   }
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]);
712 }
713
714 static void
715 col_set_delta_time(frame_data *fd, column_info *cinfo, int col)
716 {
717   COL_CHECK_REF_TIME(fd, cinfo, col);
718
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);
724                   break;
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);
729                   break;
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);
734                   break;
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);
739                   break;
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);
744                   break;
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);
749                   break;
750           default:
751                   g_assert_not_reached();
752   }
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]);
756 }
757
758 static void
759 col_set_delta_time_dis(frame_data *fd, column_info *cinfo, int col)
760 {
761   COL_CHECK_REF_TIME(fd, cinfo, col);
762
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);
768                   break;
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);
773                   break;
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);
778                   break;
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);
783                   break;
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);
788                   break;
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);
793                   break;
794           default:
795                   g_assert_not_reached();
796   }
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]);
800 }
801
802 /* To do: Add check_col checks to the col_add* routines */
803
804 static void
805 col_set_abs_time(frame_data *fd, column_info *cinfo, int col)
806 {
807   struct tm *tmp;
808   time_t then;
809
810   COL_CHECK_REF_TIME(fd, cinfo, col);
811
812   then = fd->abs_ts.secs;
813   tmp = localtime(&then);
814   if (tmp != NULL) {
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,
819              "%02d:%02d:%02d",
820              tmp->tm_hour,
821              tmp->tm_min,
822              tmp->tm_sec);
823                   break;
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",
828              tmp->tm_hour,
829              tmp->tm_min,
830              tmp->tm_sec,
831              (long)fd->abs_ts.nsecs / 100000000);
832                   break;
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",
837              tmp->tm_hour,
838              tmp->tm_min,
839              tmp->tm_sec,
840              (long)fd->abs_ts.nsecs / 10000000);
841                   break;
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",
846              tmp->tm_hour,
847              tmp->tm_min,
848              tmp->tm_sec,
849              (long)fd->abs_ts.nsecs / 1000000);
850                   break;
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",
855              tmp->tm_hour,
856              tmp->tm_min,
857              tmp->tm_sec,
858              (long)fd->abs_ts.nsecs / 1000);
859                   break;
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",
864              tmp->tm_hour,
865              tmp->tm_min,
866              tmp->tm_sec,
867              (long)fd->abs_ts.nsecs);
868                   break;
869           default:
870                   g_assert_not_reached();
871           }
872   } else {
873     cinfo->col_buf[col][0] = '\0';
874   }
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]);
878 }
879
880 static void
881 col_set_epoch_time(frame_data *fd, column_info *cinfo, int col)
882 {
883
884   COL_CHECK_REF_TIME(fd, cinfo, col);
885
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);
891                   break;
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);
896                   break;
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);
901                   break;
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);
906                   break;
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);
911                   break;
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);
916                   break;
917           default:
918                   g_assert_not_reached();
919   }
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]);
923 }
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. */
931 void
932 col_set_cls_time(frame_data *fd, column_info *cinfo, gint col)
933 {
934   switch (timestamp_get_type()) {
935     case TS_ABSOLUTE:
936       col_set_abs_time(fd, cinfo, col);
937       break;
938
939     case TS_ABSOLUTE_WITH_DATE:
940       col_set_abs_date_time(fd, cinfo, col);
941       break;
942
943     case TS_RELATIVE:
944       col_set_rel_time(fd, cinfo, col);
945       break;
946
947     case TS_DELTA:
948       col_set_delta_time(fd, cinfo, col);
949       break;
950
951     case TS_DELTA_DIS:
952       col_set_delta_time_dis(fd, cinfo, col);
953       break;
954
955     case TS_EPOCH:
956       col_set_epoch_time(fd, cinfo, col);
957       break;
958
959     case TS_NOT_SET:
960         /* code is missing for this case, but I don't know which [jmayer20051219] */
961         g_assert(FALSE);
962         break;
963   }
964 }
965
966 void
967 col_set_time(column_info *cinfo, gint el, nstime_t *ts, char *fieldname)
968 {
969   int   col;
970
971   g_assert(cinfo->col_first[el] >= 0);
972
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);
980           break;
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);
985           break;
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);
990           break;
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);
995           break;
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);
1000           break;
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);
1005           break;
1006         default:
1007           g_assert_not_reached();
1008       }
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]);
1012     }
1013   }
1014 }
1015
1016 static void
1017 col_set_addr(packet_info *pinfo, int col, address *addr, gboolean is_res,
1018              gboolean is_src)
1019 {
1020   struct e_in6_addr ipv6_addr;
1021
1022   pinfo->cinfo->col_expr[col][0] = '\0';
1023   pinfo->cinfo->col_expr_val[col][0] = '\0';
1024
1025   if (addr->type == AT_NONE)
1026     return;     /* no address, nothing to do */
1027
1028   if (is_res) {
1029     get_addr_name_buf(addr, pinfo->cinfo->col_buf[col], COL_MAX_LEN);
1030   } else {
1031     address_to_str_buf(addr, pinfo->cinfo->col_buf[col], COL_MAX_LEN);
1032   }
1033   pinfo->cinfo->col_data[col] = pinfo->cinfo->col_buf[col];
1034
1035   switch (addr->type) {
1036
1037   case AT_ETHER:
1038     if (is_src)
1039       strcpy(pinfo->cinfo->col_expr[col], "eth.src");
1040     else
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);
1043     break;
1044
1045   case AT_IPv4:
1046     if (is_src)
1047       strcpy(pinfo->cinfo->col_expr[col], "ip.src");
1048     else
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);
1051     break;
1052
1053   case AT_IPv6:
1054     if (is_src)
1055       strcpy(pinfo->cinfo->col_expr[col], "ipv6.src");
1056     else
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);
1059     break;
1060
1061   case AT_ATALK:
1062     if (is_src)
1063       strcpy(pinfo->cinfo->col_expr[col], "ddp.src");
1064     else
1065       strcpy(pinfo->cinfo->col_expr[col], "ddp.dst");
1066     strcpy(pinfo->cinfo->col_expr_val[col], pinfo->cinfo->col_buf[col]);
1067     break;
1068
1069   case AT_ARCNET:
1070     if (is_src)
1071       strcpy(pinfo->cinfo->col_expr[col], "arcnet.src");
1072     else
1073       strcpy(pinfo->cinfo->col_expr[col], "arcnet.dst");
1074     strcpy(pinfo->cinfo->col_expr_val[col], pinfo->cinfo->col_buf[col]);
1075     break;
1076
1077   case AT_URI:
1078     if (is_src)
1079       strcpy(pinfo->cinfo->col_expr[col], "uri.src");
1080     else
1081       strcpy(pinfo->cinfo->col_expr[col], "uri.dst");
1082     address_to_str_buf(addr, pinfo->cinfo->col_expr_val[col], COL_MAX_LEN);
1083     break;
1084
1085   default:
1086     break;
1087   }
1088 }
1089
1090 static void
1091 col_set_port(packet_info *pinfo, int col, gboolean is_res, gboolean is_src)
1092 {
1093   guint32 port;
1094
1095   if (is_src)
1096     port = pinfo->srcport;
1097   else
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) {
1102
1103   case PT_SCTP:
1104     if (is_res)
1105       g_strlcpy(pinfo->cinfo->col_buf[col], get_sctp_port(port), COL_MAX_LEN);
1106     else
1107       g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "%u", port);
1108     break;
1109
1110   case PT_TCP:
1111     if (is_res)
1112       g_strlcpy(pinfo->cinfo->col_buf[col], get_tcp_port(port), COL_MAX_LEN);
1113     else
1114       g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "%u", port);
1115     if (is_src)
1116       strcpy(pinfo->cinfo->col_expr[col], "tcp.srcport");
1117     else
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';
1121     break;
1122
1123   case PT_UDP:
1124     if (is_res)
1125       g_strlcpy(pinfo->cinfo->col_buf[col], get_udp_port(port), COL_MAX_LEN);
1126     else
1127       g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "%u", port);
1128     if (is_src)
1129       strcpy(pinfo->cinfo->col_expr[col], "udp.srcport");
1130     else
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';
1134     break;
1135
1136   case PT_DDP:
1137     if (is_src)
1138       strcpy(pinfo->cinfo->col_expr[col], "ddp.src_socket");
1139     else
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';
1144     break;
1145
1146   case PT_IPX:
1147     /* XXX - resolve IPX socket numbers */
1148     g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "0x%04x", port);
1149     if (is_src)
1150       strcpy(pinfo->cinfo->col_expr[col], "ipx.src.socket");
1151     else
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';
1155     break;
1156
1157   case PT_IDP:
1158     /* XXX - resolve IDP socket numbers */
1159     g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "0x%04x", port);
1160     if (is_src)
1161       strcpy(pinfo->cinfo->col_expr[col], "idp.src.socket");
1162     else
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';
1166     break;
1167
1168   case PT_USB:
1169     /* XXX - resolve USB endpoint numbers */
1170     g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "0x%08x", port);
1171     if (is_src)
1172       strcpy(pinfo->cinfo->col_expr[col], "usb.src.endpoint");
1173     else
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';
1177     break;
1178
1179   default:
1180     break;
1181   }
1182   pinfo->cinfo->col_buf[col][COL_MAX_LEN - 1] = '\0';
1183   pinfo->cinfo->col_data[col] = pinfo->cinfo->col_buf[col];
1184 }
1185
1186 /*
1187  * XXX - this should be in some common code in the epan directory, shared
1188  * by this code and packet-isdn.c.
1189  */
1190 static const value_string channel_vals[] = {
1191         { 0,    "D" },
1192         { 1,    "B1" },
1193         { 2,    "B2" },
1194         { 3,    "B3" },
1195         { 4,    "B4" },
1196         { 5,    "B5" },
1197         { 6,    "B6" },
1198         { 7,    "B7" },
1199         { 8,    "B8" },
1200         { 9,    "B9" },
1201         { 10,   "B10" },
1202         { 11,   "B11" },
1203         { 12,   "B12" },
1204         { 13,   "B13" },
1205         { 14,   "B14" },
1206         { 15,   "B15" },
1207         { 16,   "B16" },
1208         { 17,   "B17" },
1209         { 18,   "B19" },
1210         { 19,   "B19" },
1211         { 20,   "B20" },
1212         { 21,   "B21" },
1213         { 22,   "B22" },
1214         { 23,   "B23" },
1215         { 24,   "B24" },
1216         { 25,   "B25" },
1217         { 26,   "B26" },
1218         { 27,   "B27" },
1219         { 28,   "B29" },
1220         { 29,   "B29" },
1221         { 30,   "B30" },
1222         { 0,    NULL }
1223 };
1224
1225 static void
1226 col_set_circuit_id(packet_info *pinfo, int col)
1227 {
1228   pinfo->cinfo->col_expr[col][0] = '\0';
1229   pinfo->cinfo->col_expr_val[col][0] = '\0';
1230   switch (pinfo->ctype) {
1231
1232   case CT_DLCI:
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';
1237     break;
1238
1239   case CT_ISDN:
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';
1245     break;
1246
1247   case CT_X25:
1248     g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "%u", pinfo->circuit_id);
1249     break;
1250
1251   case CT_ISUP:
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';
1256     break;
1257
1258   default:
1259     break;
1260   }
1261   pinfo->cinfo->col_buf[col][COL_MAX_LEN - 1] = '\0';
1262   pinfo->cinfo->col_data[col] = pinfo->cinfo->col_buf[col];
1263 }
1264
1265 void
1266 col_fill_in(packet_info *pinfo)
1267 {
1268   int i;
1269
1270   for (i = 0; i < pinfo->cinfo->num_cols; i++) {
1271     switch (pinfo->cinfo->col_fmt[i]) {
1272
1273     case COL_NUMBER:
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]);
1278       break;
1279
1280     case COL_CLS_TIME:
1281        col_set_cls_time(pinfo->fd, pinfo->cinfo, i);
1282       break;
1283
1284     case COL_ABS_TIME:
1285       col_set_abs_time(pinfo->fd, pinfo->cinfo, i);
1286       break;
1287
1288     case COL_ABS_DATE_TIME:
1289       col_set_abs_date_time(pinfo->fd, pinfo->cinfo, i);
1290       break;
1291
1292     case COL_REL_TIME:
1293       col_set_rel_time(pinfo->fd, pinfo->cinfo, i);
1294       break;
1295
1296     case COL_DELTA_TIME:
1297       col_set_delta_time(pinfo->fd, pinfo->cinfo, i);
1298       break;
1299
1300     case COL_DELTA_TIME_DIS:
1301       col_set_delta_time_dis(pinfo->fd, pinfo->cinfo, i);
1302       break;
1303
1304     case COL_REL_CONV_TIME:
1305     case COL_DELTA_CONV_TIME:
1306       break;            /* Will be set by various dissectors */
1307
1308     case COL_DEF_SRC:
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);
1311       break;
1312
1313     case COL_UNRES_SRC:
1314       col_set_addr(pinfo, i, &pinfo->src, FALSE, TRUE);
1315       break;
1316
1317     case COL_DEF_DL_SRC:
1318     case COL_RES_DL_SRC:
1319       col_set_addr(pinfo, i, &pinfo->dl_src, TRUE, TRUE);
1320       break;
1321
1322     case COL_UNRES_DL_SRC:
1323       col_set_addr(pinfo, i, &pinfo->dl_src, FALSE, TRUE);
1324       break;
1325
1326     case COL_DEF_NET_SRC:
1327     case COL_RES_NET_SRC:
1328       col_set_addr(pinfo, i, &pinfo->net_src, TRUE, TRUE);
1329       break;
1330
1331     case COL_UNRES_NET_SRC:
1332       col_set_addr(pinfo, i, &pinfo->net_src, FALSE, TRUE);
1333       break;
1334
1335     case COL_DEF_DST:
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);
1338       break;
1339
1340     case COL_UNRES_DST:
1341       col_set_addr(pinfo, i, &pinfo->dst, FALSE, FALSE);
1342       break;
1343
1344     case COL_DEF_DL_DST:
1345     case COL_RES_DL_DST:
1346       col_set_addr(pinfo, i, &pinfo->dl_dst, TRUE, FALSE);
1347       break;
1348
1349     case COL_UNRES_DL_DST:
1350       col_set_addr(pinfo, i, &pinfo->dl_dst, FALSE, FALSE);
1351       break;
1352
1353     case COL_DEF_NET_DST:
1354     case COL_RES_NET_DST:
1355       col_set_addr(pinfo, i, &pinfo->net_dst, TRUE, FALSE);
1356       break;
1357
1358     case COL_UNRES_NET_DST:
1359       col_set_addr(pinfo, i, &pinfo->net_dst, FALSE, FALSE);
1360       break;
1361
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);
1365       break;
1366
1367     case COL_UNRES_SRC_PORT:
1368       col_set_port(pinfo, i, FALSE, TRUE);
1369       break;
1370
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);
1374       break;
1375
1376     case COL_UNRES_DST_PORT:
1377       col_set_port(pinfo, i, FALSE, FALSE);
1378       break;
1379
1380     case COL_PROTOCOL:  /* currently done by dissectors */
1381     case COL_INFO:      /* currently done by dissectors */
1382       break;
1383
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]);
1389       break;
1390
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];
1394       break;
1395
1396     case COL_OXID:
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];
1400       break;
1401
1402     case COL_RXID:
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];
1406       break;
1407
1408     case COL_IF_DIR:    /* currently done by dissectors */
1409       break;
1410
1411     case COL_CIRCUIT_ID:
1412       col_set_circuit_id(pinfo, i);
1413       break;
1414
1415     case COL_SRCIDX:
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];
1419       break;
1420
1421     case COL_DSTIDX:
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];
1425       break;
1426
1427     case COL_VSAN:
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];
1431       break;
1432
1433     case COL_HPUX_SUBSYS: /* done by nettl disector */
1434     case COL_HPUX_DEVID:  /* done by nettl disector */
1435       break;
1436
1437     case COL_DCE_CALL:  /* done by dcerpc */
1438       break;
1439
1440     case COL_DCE_CTX:   /* done by dcerpc */
1441       break;
1442
1443     case COL_8021Q_VLAN_ID:
1444         break;
1445
1446     case COL_DSCP_VALUE:        /* done by packet-ip.c */
1447         break;
1448
1449     case COL_COS_VALUE:         /* done by packet-vlan.c */
1450         break;
1451
1452     case COL_FR_DLCI:   /* done by packet-fr.c */
1453     case COL_BSSGP_TLLI: /* done by packet-bssgp.c */
1454         break;
1455
1456     case COL_EXPERT:    /* done by expert.c */
1457         break;
1458
1459     case COL_FREQ_CHAN:    /* done by radio dissectors */
1460         break;
1461
1462     case COL_CUSTOM:     /* done by col_custom_set_fstr() called from proto.c */
1463         break;
1464
1465     case NUM_COL_FMTS:  /* keep compiler happy - shouldn't get here */
1466       g_assert_not_reached();
1467       break;
1468     }
1469   }
1470 }