Initialize ipv6_addr before we use it.
[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.col_expr = (gchar **) g_malloc(sizeof(gchar *) * num_cols);
68   cinfo->col_expr.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.col_expr[i][0] = '\0';
87     cinfo->col_expr.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.col_expr[i][0] = '\0';
180       cinfo->col_expr.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(header_field_info *hfinfo, 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], hfinfo->abbrev) == 0) {
288       ci->col_data[i] = ci->col_buf[i];
289       g_vsnprintf(ci->col_buf[i], COL_MAX_LEN, format, ap);
290
291       g_strlcpy(ci->col_expr.col_expr[i], hfinfo->abbrev, COL_MAX_LEN);
292
293       switch(hfinfo->type) {
294       case FT_STRING:
295       case FT_STRINGZ:
296         g_snprintf(ci->col_expr.col_expr_val[i], COL_MAX_LEN, "\"%s\"",
297             ci->col_buf[i]);
298         break;
299
300       default:
301         g_strlcpy(ci->col_expr.col_expr_val[i], ci->col_buf[i], COL_MAX_LEN);
302         break;
303       }
304     }
305   }
306   va_end(ap);
307 }
308
309 void
310 col_custom_prime_edt(epan_dissect_t *edt, column_info *cinfo)
311 {
312   int i;
313   dfilter_t *dfilter_code;
314
315   ci = cinfo; /* Save this into the static variable ci for use by
316                * col_custom_set_fstr() later. */
317
318   if(!have_custom_cols(cinfo))
319       return;
320
321   for (i = cinfo->col_first[COL_CUSTOM];
322        i <= cinfo->col_last[COL_CUSTOM]; i++) {
323     if (cinfo->fmt_matx[i][COL_CUSTOM] &&
324         strlen(cinfo->col_custom_field[i]) > 0) {
325       if(dfilter_compile(cinfo->col_custom_field[i], &dfilter_code)) {
326         epan_dissect_prime_dfilter(edt, dfilter_code);
327         dfilter_free(dfilter_code);
328       }
329     }
330   }
331 }
332
333 gboolean
334 have_custom_cols(column_info *cinfo)
335 {
336   /* The same as check_col(), but without the check to see if the column
337    * is writable. */
338   if (cinfo && cinfo->col_first[COL_CUSTOM] >= 0)
339     return TRUE;
340   else
341     return FALSE;
342 }
343
344 static void
345 col_do_append_sep_va_fstr(column_info *cinfo, gint el, const gchar *separator,
346                           const gchar *format, va_list ap)
347 {
348   int     i;
349   size_t  len, max_len, sep_len;
350
351   g_assert(cinfo->col_first[el] >= 0);
352   if (el == COL_INFO)
353         max_len = COL_MAX_INFO_LEN;
354   else
355         max_len = COL_MAX_LEN;
356
357   if (separator == NULL)
358     sep_len = 0;
359   else
360     sep_len = strlen(separator);
361   for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
362     if (cinfo->fmt_matx[i][el]) {
363       /*
364        * First arrange that we can append, if necessary.
365        */
366       COL_CHECK_APPEND(cinfo, i, max_len);
367
368       len = strlen(cinfo->col_buf[i]);
369
370       /*
371        * If we have a separator, append it if the column isn't empty.
372        */
373       if (separator != NULL) {
374         if (len != 0) {
375           g_strlcat(cinfo->col_buf[i], separator, max_len);
376           len += sep_len;
377         }
378       }
379       g_vsnprintf(&cinfo->col_buf[i][len], max_len - len, format, ap);
380       cinfo->col_buf[i][max_len-1] = 0;
381     }
382   }
383 }
384
385 /* Appends a vararg list to a packet info string. */
386 void
387 col_append_fstr(column_info *cinfo, gint el, const gchar *format, ...)
388 {
389   va_list ap;
390
391   va_start(ap, format);
392   col_do_append_sep_va_fstr(cinfo, el, NULL, format, ap);
393   va_end(ap);
394 }
395
396 /* Appends a vararg list to a packet info string.
397  * Prefixes it with the given separator if the column is not empty. */
398 void
399 col_append_sep_fstr(column_info *cinfo, gint el, const gchar *separator,
400                 const gchar *format, ...)
401 {
402   va_list ap;
403
404   if (separator == NULL)
405     separator = ", ";    /* default */
406   va_start(ap, format);
407   col_do_append_sep_va_fstr(cinfo, el, separator, format, ap);
408   va_end(ap);
409 }
410
411
412
413 /* Prepends a vararg list to a packet info string. */
414 #define COL_BUF_MAX_LEN (((COL_MAX_INFO_LEN) > (COL_MAX_LEN)) ? \
415         (COL_MAX_INFO_LEN) : (COL_MAX_LEN))
416 void
417 col_prepend_fstr(column_info *cinfo, gint el, const gchar *format, ...)
418 {
419   va_list     ap;
420   int         i;
421   char        orig_buf[COL_BUF_MAX_LEN];
422   const char *orig;
423   size_t      max_len;
424
425   g_assert(cinfo->col_first[el] >= 0);
426   if (el == COL_INFO)
427         max_len = COL_MAX_INFO_LEN;
428   else
429         max_len = COL_MAX_LEN;
430
431   va_start(ap, format);
432   for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
433     if (cinfo->fmt_matx[i][el]) {
434       if (cinfo->col_data[i] != cinfo->col_buf[i]) {
435         /* This was set with "col_set_str()"; which is effectively const */
436         orig = cinfo->col_data[i];
437       } else {
438         g_strlcpy(orig_buf, cinfo->col_buf[i], max_len);
439         orig = orig_buf;
440       }
441       g_vsnprintf(cinfo->col_buf[i], max_len, format, ap);
442       cinfo->col_buf[i][max_len - 1] = '\0';
443
444       /*
445        * Move the fence, unless it's at the beginning of the string.
446        */
447       if (cinfo->col_fence[i] > 0)
448         cinfo->col_fence[i] += strlen(cinfo->col_buf[i]);
449
450       g_strlcat(cinfo->col_buf[i], orig, max_len);
451       cinfo->col_data[i] = cinfo->col_buf[i];
452     }
453   }
454   va_end(ap);
455 }
456 void
457 col_prepend_fence_fstr(column_info *cinfo, gint el, const gchar *format, ...)
458 {
459   va_list     ap;
460   int         i;
461   char        orig_buf[COL_BUF_MAX_LEN];
462   const char *orig;
463   size_t      max_len;
464
465   g_assert(cinfo->col_first[el] >= 0);
466   if (el == COL_INFO)
467         max_len = COL_MAX_INFO_LEN;
468   else
469         max_len = COL_MAX_LEN;
470
471   va_start(ap, format);
472   for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
473     if (cinfo->fmt_matx[i][el]) {
474       if (cinfo->col_data[i] != cinfo->col_buf[i]) {
475         /* This was set with "col_set_str()"; which is effectively const */
476         orig = cinfo->col_data[i];
477       } else {
478         g_strlcpy(orig_buf, cinfo->col_buf[i], max_len);
479         orig = orig_buf;
480       }
481       g_vsnprintf(cinfo->col_buf[i], max_len, format, ap);
482       cinfo->col_buf[i][max_len - 1] = '\0';
483
484       /*
485        * Move the fence if it exists, else create a new fence at the
486        * end of the prepended data.
487        */
488       if (cinfo->col_fence[i] > 0) {
489         cinfo->col_fence[i] += strlen(cinfo->col_buf[i]);
490       } else {
491         cinfo->col_fence[i]  = strlen(cinfo->col_buf[i]);
492       }
493       g_strlcat(cinfo->col_buf[i], orig, max_len);
494       cinfo->col_data[i] = cinfo->col_buf[i];
495     }
496   }
497   va_end(ap);
498 }
499
500 /* Use this if "str" points to something that won't stay around (and
501    must thus be copied). */
502 void
503 col_add_str(column_info *cinfo, gint el, const gchar* str)
504 {
505   int    i;
506   int    fence;
507   size_t max_len;
508
509   g_assert(cinfo->col_first[el] >= 0);
510   if (el == COL_INFO)
511         max_len = COL_MAX_INFO_LEN;
512   else
513         max_len = COL_MAX_LEN;
514
515   for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
516     if (cinfo->fmt_matx[i][el]) {
517       fence = cinfo->col_fence[i];
518       if (fence != 0) {
519         /*
520          * We will append the string after the fence.
521          * First arrange that we can append, if necessary.
522          */
523         COL_CHECK_APPEND(cinfo, i, max_len);
524       } else {
525         /*
526          * There's no fence, so we can just write to the string.
527          */
528         cinfo->col_data[i] = cinfo->col_buf[i];
529       }
530       g_strlcpy(&cinfo->col_buf[i][fence], str, max_len - fence);
531     }
532   }
533 }
534
535 static void
536 col_do_append_str(column_info *cinfo, gint el, const gchar* separator,
537     const gchar* str)
538 {
539   int    i;
540   size_t len, max_len, sep_len;
541
542   g_assert(cinfo->col_first[el] >= 0);
543   if (el == COL_INFO)
544         max_len = COL_MAX_INFO_LEN;
545   else
546         max_len = COL_MAX_LEN;
547
548   if (separator == NULL)
549     sep_len = 0;
550   else
551     sep_len = strlen(separator);
552
553   for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
554     if (cinfo->fmt_matx[i][el]) {
555       /*
556        * First arrange that we can append, if necessary.
557        */
558       COL_CHECK_APPEND(cinfo, i, max_len);
559
560       len = cinfo->col_buf[i][0];
561
562       /*
563        * If we have a separator, append it if the column isn't empty.
564        */
565       if (separator != NULL) {
566         if (len != 0) {
567           g_strlcat(cinfo->col_buf[i], separator, max_len);
568         }
569       }
570       g_strlcat(cinfo->col_buf[i], str, max_len);
571     }
572   }
573 }
574
575 void
576 col_append_str(column_info *cinfo, gint el, const gchar* str)
577 {
578   col_do_append_str(cinfo, el, NULL, str);
579 }
580
581 void
582 col_append_sep_str(column_info *cinfo, gint el, const gchar* separator,
583     const gchar* str)
584 {
585   if (separator == NULL)
586     separator = ", ";    /* default */
587   col_do_append_str(cinfo, el, separator, str);
588 }
589
590 static void
591 col_set_abs_date_time(frame_data *fd, column_info *cinfo, int col)
592 {
593   struct tm *tmp;
594   time_t then;
595
596   COL_CHECK_REF_TIME(fd, cinfo, col);
597
598   then = fd->abs_ts.secs;
599   tmp = localtime(&then);
600   if (tmp != NULL) {
601           switch(timestamp_get_precision()) {
602           case(TS_PREC_FIXED_SEC):
603           case(TS_PREC_AUTO_SEC):
604                   g_snprintf(cinfo->col_buf[col], COL_MAX_LEN,
605              "%04d-%02d-%02d %02d:%02d:%02d",
606              tmp->tm_year + 1900,
607              tmp->tm_mon + 1,
608              tmp->tm_mday,
609              tmp->tm_hour,
610              tmp->tm_min,
611              tmp->tm_sec);
612                   break;
613           case(TS_PREC_FIXED_DSEC):
614           case(TS_PREC_AUTO_DSEC):
615                   g_snprintf(cinfo->col_buf[col], COL_MAX_LEN,
616              "%04d-%02d-%02d %02d:%02d:%02d.%01ld",
617              tmp->tm_year + 1900,
618              tmp->tm_mon + 1,
619              tmp->tm_mday,
620              tmp->tm_hour,
621              tmp->tm_min,
622              tmp->tm_sec,
623              (long)fd->abs_ts.nsecs / 100000000);
624                   break;
625           case(TS_PREC_FIXED_CSEC):
626           case(TS_PREC_AUTO_CSEC):
627                   g_snprintf(cinfo->col_buf[col], COL_MAX_LEN,
628              "%04d-%02d-%02d %02d:%02d:%02d.%02ld",
629              tmp->tm_year + 1900,
630              tmp->tm_mon + 1,
631              tmp->tm_mday,
632              tmp->tm_hour,
633              tmp->tm_min,
634              tmp->tm_sec,
635              (long)fd->abs_ts.nsecs / 10000000);
636                   break;
637           case(TS_PREC_FIXED_MSEC):
638           case(TS_PREC_AUTO_MSEC):
639                   g_snprintf(cinfo->col_buf[col], COL_MAX_LEN,
640              "%04d-%02d-%02d %02d:%02d:%02d.%03ld",
641              tmp->tm_year + 1900,
642              tmp->tm_mon + 1,
643              tmp->tm_mday,
644              tmp->tm_hour,
645              tmp->tm_min,
646              tmp->tm_sec,
647              (long)fd->abs_ts.nsecs / 1000000);
648                   break;
649           case(TS_PREC_FIXED_USEC):
650           case(TS_PREC_AUTO_USEC):
651                   g_snprintf(cinfo->col_buf[col], COL_MAX_LEN,
652              "%04d-%02d-%02d %02d:%02d:%02d.%06ld",
653              tmp->tm_year + 1900,
654              tmp->tm_mon + 1,
655              tmp->tm_mday,
656              tmp->tm_hour,
657              tmp->tm_min,
658              tmp->tm_sec,
659              (long)fd->abs_ts.nsecs / 1000);
660                   break;
661           case(TS_PREC_FIXED_NSEC):
662           case(TS_PREC_AUTO_NSEC):
663                   g_snprintf(cinfo->col_buf[col], COL_MAX_LEN,
664              "%04d-%02d-%02d %02d:%02d:%02d.%09ld",
665              tmp->tm_year + 1900,
666              tmp->tm_mon + 1,
667              tmp->tm_mday,
668              tmp->tm_hour,
669              tmp->tm_min,
670              tmp->tm_sec,
671              (long)fd->abs_ts.nsecs);
672                   break;
673           default:
674                   g_assert_not_reached();
675           }
676   } else {
677     cinfo->col_buf[col][0] = '\0';
678   }
679   cinfo->col_data[col] = cinfo->col_buf[col];
680   g_strlcpy(cinfo->col_expr.col_expr[col],"frame.time",COL_MAX_LEN);
681   g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->col_buf[col],COL_MAX_LEN);
682 }
683
684 static void
685 col_set_rel_time(frame_data *fd, column_info *cinfo, int col)
686 {
687   COL_CHECK_REF_TIME(fd, cinfo, col);
688
689   switch(timestamp_get_precision()) {
690           case(TS_PREC_FIXED_SEC):
691           case(TS_PREC_AUTO_SEC):
692                   display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
693                         (gint32) fd->rel_ts.secs, fd->rel_ts.nsecs / 1000000000, SECS);
694                   break;
695           case(TS_PREC_FIXED_DSEC):
696           case(TS_PREC_AUTO_DSEC):
697                   display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
698                         (gint32) fd->rel_ts.secs, fd->rel_ts.nsecs / 100000000, DSECS);
699                   break;
700           case(TS_PREC_FIXED_CSEC):
701           case(TS_PREC_AUTO_CSEC):
702                   display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
703                         (gint32) fd->rel_ts.secs, fd->rel_ts.nsecs / 10000000, CSECS);
704                   break;
705           case(TS_PREC_FIXED_MSEC):
706           case(TS_PREC_AUTO_MSEC):
707                   display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
708                         (gint32) fd->rel_ts.secs, fd->rel_ts.nsecs / 1000000, MSECS);
709                   break;
710           case(TS_PREC_FIXED_USEC):
711           case(TS_PREC_AUTO_USEC):
712                   display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
713                         (gint32) fd->rel_ts.secs, fd->rel_ts.nsecs / 1000, USECS);
714                   break;
715           case(TS_PREC_FIXED_NSEC):
716           case(TS_PREC_AUTO_NSEC):
717                   display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
718                         (gint32) fd->rel_ts.secs, fd->rel_ts.nsecs, NSECS);
719                   break;
720           default:
721                   g_assert_not_reached();
722   }
723   cinfo->col_data[col] = cinfo->col_buf[col];
724   g_strlcpy(cinfo->col_expr.col_expr[col],"frame.time_relative", COL_MAX_LEN);
725   g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->col_buf[col],COL_MAX_LEN);
726 }
727
728 static void
729 col_set_delta_time(frame_data *fd, column_info *cinfo, int col)
730 {
731   COL_CHECK_REF_TIME(fd, cinfo, col);
732
733   switch(timestamp_get_precision()) {
734           case(TS_PREC_FIXED_SEC):
735           case(TS_PREC_AUTO_SEC):
736                   display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
737                         (gint32) fd->del_cap_ts.secs, fd->del_cap_ts.nsecs / 1000000000, SECS);
738                   break;
739           case(TS_PREC_FIXED_DSEC):
740           case(TS_PREC_AUTO_DSEC):
741                   display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
742                         (gint32) fd->del_cap_ts.secs, fd->del_cap_ts.nsecs / 100000000, DSECS);
743                   break;
744           case(TS_PREC_FIXED_CSEC):
745           case(TS_PREC_AUTO_CSEC):
746                   display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
747                         (gint32) fd->del_cap_ts.secs, fd->del_cap_ts.nsecs / 10000000, CSECS);
748                   break;
749           case(TS_PREC_FIXED_MSEC):
750           case(TS_PREC_AUTO_MSEC):
751                   display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
752                         (gint32) fd->del_cap_ts.secs, fd->del_cap_ts.nsecs / 1000000, MSECS);
753                   break;
754           case(TS_PREC_FIXED_USEC):
755           case(TS_PREC_AUTO_USEC):
756                   display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
757                         (gint32) fd->del_cap_ts.secs, fd->del_cap_ts.nsecs / 1000, USECS);
758                   break;
759           case(TS_PREC_FIXED_NSEC):
760           case(TS_PREC_AUTO_NSEC):
761                   display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
762                         (gint32) fd->del_cap_ts.secs, fd->del_cap_ts.nsecs, NSECS);
763                   break;
764           default:
765                   g_assert_not_reached();
766   }
767   cinfo->col_data[col] = cinfo->col_buf[col];
768   g_strlcpy(cinfo->col_expr.col_expr[col],"frame.time_delta",COL_MAX_LEN);
769   g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->col_buf[col],COL_MAX_LEN);
770 }
771
772 static void
773 col_set_delta_time_dis(frame_data *fd, column_info *cinfo, int col)
774 {
775   COL_CHECK_REF_TIME(fd, cinfo, col);
776
777   switch(timestamp_get_precision()) {
778           case(TS_PREC_FIXED_SEC):
779           case(TS_PREC_AUTO_SEC):
780                   display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
781                         (gint32) fd->del_dis_ts.secs, fd->del_dis_ts.nsecs / 1000000000, SECS);
782                   break;
783           case(TS_PREC_FIXED_DSEC):
784           case(TS_PREC_AUTO_DSEC):
785                   display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
786                         (gint32) fd->del_dis_ts.secs, fd->del_dis_ts.nsecs / 100000000, DSECS);
787                   break;
788           case(TS_PREC_FIXED_CSEC):
789           case(TS_PREC_AUTO_CSEC):
790                   display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
791                         (gint32) fd->del_dis_ts.secs, fd->del_dis_ts.nsecs / 10000000, CSECS);
792                   break;
793           case(TS_PREC_FIXED_MSEC):
794           case(TS_PREC_AUTO_MSEC):
795                   display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
796                         (gint32) fd->del_dis_ts.secs, fd->del_dis_ts.nsecs / 1000000, MSECS);
797                   break;
798           case(TS_PREC_FIXED_USEC):
799           case(TS_PREC_AUTO_USEC):
800                   display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
801                         (gint32) fd->del_dis_ts.secs, fd->del_dis_ts.nsecs / 1000, USECS);
802                   break;
803           case(TS_PREC_FIXED_NSEC):
804           case(TS_PREC_AUTO_NSEC):
805                   display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
806                         (gint32) fd->del_dis_ts.secs, fd->del_dis_ts.nsecs, NSECS);
807                   break;
808           default:
809                   g_assert_not_reached();
810   }
811   cinfo->col_data[col] = cinfo->col_buf[col];
812   g_strlcpy(cinfo->col_expr.col_expr[col],"frame.time_delta_displayed",
813             COL_MAX_LEN);
814   g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->col_buf[col],COL_MAX_LEN);
815 }
816
817 /* To do: Add check_col checks to the col_add* routines */
818
819 static void
820 col_set_abs_time(frame_data *fd, column_info *cinfo, int col)
821 {
822   struct tm *tmp;
823   time_t then;
824
825   COL_CHECK_REF_TIME(fd, cinfo, col);
826
827   then = fd->abs_ts.secs;
828   tmp = localtime(&then);
829   if (tmp != NULL) {
830           switch(timestamp_get_precision()) {
831           case(TS_PREC_FIXED_SEC):
832           case(TS_PREC_AUTO_SEC):
833                   g_snprintf(cinfo->col_buf[col], COL_MAX_LEN,
834              "%02d:%02d:%02d",
835              tmp->tm_hour,
836              tmp->tm_min,
837              tmp->tm_sec);
838                   break;
839           case(TS_PREC_FIXED_DSEC):
840           case(TS_PREC_AUTO_DSEC):
841                   g_snprintf(cinfo->col_buf[col], COL_MAX_LEN,
842              "%02d:%02d:%02d.%01ld",
843              tmp->tm_hour,
844              tmp->tm_min,
845              tmp->tm_sec,
846              (long)fd->abs_ts.nsecs / 100000000);
847                   break;
848           case(TS_PREC_FIXED_CSEC):
849           case(TS_PREC_AUTO_CSEC):
850                   g_snprintf(cinfo->col_buf[col], COL_MAX_LEN,
851              "%02d:%02d:%02d.%02ld",
852              tmp->tm_hour,
853              tmp->tm_min,
854              tmp->tm_sec,
855              (long)fd->abs_ts.nsecs / 10000000);
856                   break;
857           case(TS_PREC_FIXED_MSEC):
858           case(TS_PREC_AUTO_MSEC):
859                   g_snprintf(cinfo->col_buf[col], COL_MAX_LEN,
860              "%02d:%02d:%02d.%03ld",
861              tmp->tm_hour,
862              tmp->tm_min,
863              tmp->tm_sec,
864              (long)fd->abs_ts.nsecs / 1000000);
865                   break;
866           case(TS_PREC_FIXED_USEC):
867           case(TS_PREC_AUTO_USEC):
868                   g_snprintf(cinfo->col_buf[col], COL_MAX_LEN,
869              "%02d:%02d:%02d.%06ld",
870              tmp->tm_hour,
871              tmp->tm_min,
872              tmp->tm_sec,
873              (long)fd->abs_ts.nsecs / 1000);
874                   break;
875           case(TS_PREC_FIXED_NSEC):
876           case(TS_PREC_AUTO_NSEC):
877                   g_snprintf(cinfo->col_buf[col], COL_MAX_LEN,
878              "%02d:%02d:%02d.%09ld",
879              tmp->tm_hour,
880              tmp->tm_min,
881              tmp->tm_sec,
882              (long)fd->abs_ts.nsecs);
883                   break;
884           default:
885                   g_assert_not_reached();
886           }
887   } else {
888     cinfo->col_buf[col][0] = '\0';
889   }
890   cinfo->col_data[col] = cinfo->col_buf[col];
891   g_strlcpy(cinfo->col_expr.col_expr[col],"frame.time",COL_MAX_LEN);
892   g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->col_buf[col],COL_MAX_LEN);
893 }
894
895 static void
896 col_set_epoch_time(frame_data *fd, column_info *cinfo, int col)
897 {
898
899   COL_CHECK_REF_TIME(fd, cinfo, col);
900
901   switch(timestamp_get_precision()) {
902           case(TS_PREC_FIXED_SEC):
903           case(TS_PREC_AUTO_SEC):
904                   display_epoch_time(cinfo->col_buf[col], COL_MAX_LEN,
905                         fd->abs_ts.secs, fd->abs_ts.nsecs / 1000000000, SECS);
906                   break;
907           case(TS_PREC_FIXED_DSEC):
908           case(TS_PREC_AUTO_DSEC):
909                   display_epoch_time(cinfo->col_buf[col], COL_MAX_LEN,
910                         fd->abs_ts.secs, fd->abs_ts.nsecs / 100000000, DSECS);
911                   break;
912           case(TS_PREC_FIXED_CSEC):
913           case(TS_PREC_AUTO_CSEC):
914                   display_epoch_time(cinfo->col_buf[col], COL_MAX_LEN,
915                         fd->abs_ts.secs, fd->abs_ts.nsecs / 10000000, CSECS);
916                   break;
917           case(TS_PREC_FIXED_MSEC):
918           case(TS_PREC_AUTO_MSEC):
919                   display_epoch_time(cinfo->col_buf[col], COL_MAX_LEN,
920                         fd->abs_ts.secs, fd->abs_ts.nsecs / 1000000, MSECS);
921                   break;
922           case(TS_PREC_FIXED_USEC):
923           case(TS_PREC_AUTO_USEC):
924                   display_epoch_time(cinfo->col_buf[col], COL_MAX_LEN,
925                         fd->abs_ts.secs, fd->abs_ts.nsecs / 1000, USECS);
926                   break;
927           case(TS_PREC_FIXED_NSEC):
928           case(TS_PREC_AUTO_NSEC):
929                   display_epoch_time(cinfo->col_buf[col], COL_MAX_LEN,
930                         fd->abs_ts.secs, fd->abs_ts.nsecs, NSECS);
931                   break;
932           default:
933                   g_assert_not_reached();
934   }
935   cinfo->col_data[col] = cinfo->col_buf[col];
936   g_strlcpy(cinfo->col_expr.col_expr[col],"frame.time_delta",COL_MAX_LEN);
937   g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->col_buf[col],COL_MAX_LEN);
938 }
939 /* Set the format of the variable time format.
940    XXX - this is called from "file.c" when the user changes the time
941    format they want for "command-line-specified" time; it's a bit ugly
942    that we have to export it, but if we go to a CList-like widget that
943    invokes callbacks to get the text for the columns rather than
944    requiring us to stuff the text into the widget from outside, we
945    might be able to clean this up. */
946 void
947 col_set_cls_time(frame_data *fd, column_info *cinfo, gint col)
948 {
949   switch (timestamp_get_type()) {
950     case TS_ABSOLUTE:
951       col_set_abs_time(fd, cinfo, col);
952       break;
953
954     case TS_ABSOLUTE_WITH_DATE:
955       col_set_abs_date_time(fd, cinfo, col);
956       break;
957
958     case TS_RELATIVE:
959       col_set_rel_time(fd, cinfo, col);
960       break;
961
962     case TS_DELTA:
963       col_set_delta_time(fd, cinfo, col);
964       break;
965
966     case TS_DELTA_DIS:
967       col_set_delta_time_dis(fd, cinfo, col);
968       break;
969
970     case TS_EPOCH:
971       col_set_epoch_time(fd, cinfo, col);
972       break;
973
974     case TS_NOT_SET:
975         /* code is missing for this case, but I don't know which [jmayer20051219] */
976         g_assert(FALSE);
977         break;
978   }
979 }
980
981 void
982 col_set_time(column_info *cinfo, gint el, nstime_t *ts, char *fieldname)
983 {
984   int   col;
985
986   g_assert(cinfo->col_first[el] >= 0);
987
988   for (col = cinfo->col_first[el]; col <= cinfo->col_last[el]; col++) {
989     if (cinfo->fmt_matx[col][el]) {
990       switch(timestamp_get_precision()) {
991         case(TS_PREC_FIXED_SEC):
992         case(TS_PREC_AUTO_SEC):
993           display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
994             (gint32) ts->secs, ts->nsecs / 1000000000, SECS);
995           break;
996         case(TS_PREC_FIXED_DSEC):
997         case(TS_PREC_AUTO_DSEC):
998           display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
999             (gint32) ts->secs, ts->nsecs / 100000000, DSECS);
1000           break;
1001         case(TS_PREC_FIXED_CSEC):
1002         case(TS_PREC_AUTO_CSEC):
1003           display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
1004             (gint32) ts->secs, ts->nsecs / 10000000, CSECS);
1005           break;
1006         case(TS_PREC_FIXED_MSEC):
1007         case(TS_PREC_AUTO_MSEC):
1008           display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
1009             (gint32) ts->secs, ts->nsecs / 1000000, MSECS);
1010           break;
1011         case(TS_PREC_FIXED_USEC):
1012         case(TS_PREC_AUTO_USEC):
1013           display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
1014             (gint32) ts->secs, ts->nsecs / 1000, USECS);
1015           break;
1016         case(TS_PREC_FIXED_NSEC):
1017         case(TS_PREC_AUTO_NSEC):
1018           display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
1019             (gint32) ts->secs, ts->nsecs, NSECS);
1020           break;
1021         default:
1022           g_assert_not_reached();
1023       }
1024       cinfo->col_data[col] = cinfo->col_buf[col];
1025       g_strlcpy(cinfo->col_expr.col_expr[col],fieldname,COL_MAX_LEN);
1026       g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->col_buf[col],
1027                 COL_MAX_LEN);
1028     }
1029   }
1030 }
1031
1032 static void
1033 col_set_addr(packet_info *pinfo, int col, address *addr, gboolean is_res,
1034              gboolean is_src)
1035 {
1036   struct e_in6_addr ipv6_addr;
1037
1038   pinfo->cinfo->col_expr.col_expr[col][0] = '\0';
1039   pinfo->cinfo->col_expr.col_expr_val[col][0] = '\0';
1040
1041   if (addr->type == AT_NONE)
1042     return;     /* no address, nothing to do */
1043
1044   if (is_res) {
1045     get_addr_name_buf(addr, pinfo->cinfo->col_buf[col], COL_MAX_LEN);
1046   } else {
1047     address_to_str_buf(addr, pinfo->cinfo->col_buf[col], COL_MAX_LEN);
1048   }
1049   pinfo->cinfo->col_data[col] = pinfo->cinfo->col_buf[col];
1050
1051   switch (addr->type) {
1052
1053   case AT_ETHER:
1054     if (is_src)
1055       g_strlcpy(pinfo->cinfo->col_expr.col_expr[col], "eth.src",COL_MAX_LEN);
1056     else
1057       g_strlcpy(pinfo->cinfo->col_expr.col_expr[col], "eth.dst",COL_MAX_LEN);
1058     g_strlcpy(pinfo->cinfo->col_expr.col_expr_val[col], ether_to_str(addr->data), COL_MAX_LEN);
1059     break;
1060
1061   case AT_IPv4:
1062     if (is_src)
1063       g_strlcpy(pinfo->cinfo->col_expr.col_expr[col], "ip.src", COL_MAX_LEN);
1064     else
1065       g_strlcpy(pinfo->cinfo->col_expr.col_expr[col], "ip.dst",COL_MAX_LEN);
1066     g_strlcpy(pinfo->cinfo->col_expr.col_expr_val[col], ip_to_str(addr->data), COL_MAX_LEN);
1067     break;
1068
1069   case AT_IPv6:
1070     if (is_src)
1071       g_strlcpy(pinfo->cinfo->col_expr.col_expr[col], "ipv6.src", COL_MAX_LEN);
1072     else
1073       g_strlcpy(pinfo->cinfo->col_expr.col_expr[col], "ipv6.dst", COL_MAX_LEN);
1074     memcpy(&ipv6_addr.bytes, addr->data, sizeof ipv6_addr.bytes);
1075     g_strlcpy(pinfo->cinfo->col_expr.col_expr_val[col], ip6_to_str(&ipv6_addr), COL_MAX_LEN);
1076     break;
1077
1078   case AT_ATALK:
1079     if (is_src)
1080       g_strlcpy(pinfo->cinfo->col_expr.col_expr[col], "ddp.src", COL_MAX_LEN);
1081     else
1082       g_strlcpy(pinfo->cinfo->col_expr.col_expr[col], "ddp.dst", COL_MAX_LEN);
1083     g_strlcpy(pinfo->cinfo->col_expr.col_expr_val[col], pinfo->cinfo->col_buf[col], COL_MAX_LEN);
1084     break;
1085
1086   case AT_ARCNET:
1087     if (is_src)
1088       g_strlcpy(pinfo->cinfo->col_expr.col_expr[col], "arcnet.src",
1089          COL_MAX_LEN);
1090     else
1091       g_strlcpy(pinfo->cinfo->col_expr.col_expr[col], "arcnet.dst", 
1092         COL_MAX_LEN);
1093     g_strlcpy(pinfo->cinfo->col_expr.col_expr_val[col], pinfo->cinfo->col_buf[col], COL_MAX_LEN);
1094     break;
1095
1096   case AT_URI:
1097     if (is_src)
1098       g_strlcpy(pinfo->cinfo->col_expr.col_expr[col], "uri.src", COL_MAX_LEN);
1099     else
1100       g_strlcpy(pinfo->cinfo->col_expr.col_expr[col], "uri.dst", COL_MAX_LEN);
1101     address_to_str_buf(addr, pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN);
1102     break;
1103
1104   default:
1105     break;
1106   }
1107 }
1108
1109 static void
1110 col_set_port(packet_info *pinfo, int col, gboolean is_res, gboolean is_src)
1111 {
1112   guint32 port;
1113
1114   if (is_src)
1115     port = pinfo->srcport;
1116   else
1117     port = pinfo->destport;
1118   pinfo->cinfo->col_expr.col_expr[col][0] = '\0';
1119   pinfo->cinfo->col_expr.col_expr_val[col][0] = '\0';
1120   switch (pinfo->ptype) {
1121
1122   case PT_SCTP:
1123     if (is_res)
1124       g_strlcpy(pinfo->cinfo->col_buf[col], get_sctp_port(port), COL_MAX_LEN);
1125     else
1126       g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "%u", port);
1127     break;
1128
1129   case PT_TCP:
1130     if (is_res)
1131       g_strlcpy(pinfo->cinfo->col_buf[col], get_tcp_port(port), COL_MAX_LEN);
1132     else
1133       g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "%u", port);
1134     if (is_src)
1135       g_strlcpy(pinfo->cinfo->col_expr.col_expr[col], "tcp.srcport",
1136         COL_MAX_LEN);
1137     else
1138       g_strlcpy(pinfo->cinfo->col_expr.col_expr[col], "tcp.dstport",
1139         COL_MAX_LEN);
1140     g_snprintf(pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN, "%u", port);
1141     pinfo->cinfo->col_expr.col_expr_val[col][COL_MAX_LEN - 1] = '\0';
1142     break;
1143
1144   case PT_UDP:
1145     if (is_res)
1146       g_strlcpy(pinfo->cinfo->col_buf[col], get_udp_port(port), COL_MAX_LEN);
1147     else
1148       g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "%u", port);
1149     if (is_src)
1150       g_strlcpy(pinfo->cinfo->col_expr.col_expr[col], "udp.srcport",
1151         COL_MAX_LEN);
1152     else
1153       g_strlcpy(pinfo->cinfo->col_expr.col_expr[col], "udp.dstport",
1154         COL_MAX_LEN);
1155     g_snprintf(pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN, "%u", port);
1156     pinfo->cinfo->col_expr.col_expr_val[col][COL_MAX_LEN - 1] = '\0';
1157     break;
1158
1159   case PT_DDP:
1160     if (is_src)
1161       g_strlcpy(pinfo->cinfo->col_expr.col_expr[col], "ddp.src_socket",
1162         COL_MAX_LEN);
1163     else
1164       g_strlcpy(pinfo->cinfo->col_expr.col_expr[col], "ddp.dst_socket",
1165         COL_MAX_LEN);
1166     g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "%u", port);
1167     g_snprintf(pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN, "%u", port);
1168     pinfo->cinfo->col_expr.col_expr_val[col][COL_MAX_LEN - 1] = '\0';
1169     break;
1170
1171   case PT_IPX:
1172     /* XXX - resolve IPX socket numbers */
1173     g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "0x%04x", port);
1174     if (is_src)
1175       g_strlcpy(pinfo->cinfo->col_expr.col_expr[col], "ipx.src.socket",
1176         COL_MAX_LEN);
1177     else
1178       g_strlcpy(pinfo->cinfo->col_expr.col_expr[col], "ipx.dst.socket",
1179         COL_MAX_LEN);
1180     g_snprintf(pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN, "0x%04x", port);
1181     pinfo->cinfo->col_expr.col_expr_val[col][COL_MAX_LEN - 1] = '\0';
1182     break;
1183
1184   case PT_IDP:
1185     /* XXX - resolve IDP socket numbers */
1186     g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "0x%04x", port);
1187     if (is_src)
1188       g_strlcpy(pinfo->cinfo->col_expr.col_expr[col], "idp.src.socket",
1189         COL_MAX_LEN);
1190     else
1191       g_strlcpy(pinfo->cinfo->col_expr.col_expr[col], "idp.dst.socket",
1192         COL_MAX_LEN);
1193     g_snprintf(pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN, "0x%04x", port);
1194     pinfo->cinfo->col_expr.col_expr_val[col][COL_MAX_LEN - 1] = '\0';
1195     break;
1196
1197   case PT_USB:
1198     /* XXX - resolve USB endpoint numbers */
1199     g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "0x%08x", port);
1200     if (is_src)
1201       g_strlcpy(pinfo->cinfo->col_expr.col_expr[col], "usb.src.endpoint",
1202         COL_MAX_LEN);
1203     else
1204       g_strlcpy(pinfo->cinfo->col_expr.col_expr[col], "usb.dst.endpoint",
1205         COL_MAX_LEN);
1206     g_snprintf(pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN, "0x%08x", port);
1207     pinfo->cinfo->col_expr.col_expr_val[col][COL_MAX_LEN - 1] = '\0';
1208     break;
1209
1210   default:
1211     break;
1212   }
1213   pinfo->cinfo->col_buf[col][COL_MAX_LEN - 1] = '\0';
1214   pinfo->cinfo->col_data[col] = pinfo->cinfo->col_buf[col];
1215 }
1216
1217 /*
1218  * XXX - this should be in some common code in the epan directory, shared
1219  * by this code and packet-isdn.c.
1220  */
1221 static const value_string channel_vals[] = {
1222         { 0,    "D" },
1223         { 1,    "B1" },
1224         { 2,    "B2" },
1225         { 3,    "B3" },
1226         { 4,    "B4" },
1227         { 5,    "B5" },
1228         { 6,    "B6" },
1229         { 7,    "B7" },
1230         { 8,    "B8" },
1231         { 9,    "B9" },
1232         { 10,   "B10" },
1233         { 11,   "B11" },
1234         { 12,   "B12" },
1235         { 13,   "B13" },
1236         { 14,   "B14" },
1237         { 15,   "B15" },
1238         { 16,   "B16" },
1239         { 17,   "B17" },
1240         { 18,   "B19" },
1241         { 19,   "B19" },
1242         { 20,   "B20" },
1243         { 21,   "B21" },
1244         { 22,   "B22" },
1245         { 23,   "B23" },
1246         { 24,   "B24" },
1247         { 25,   "B25" },
1248         { 26,   "B26" },
1249         { 27,   "B27" },
1250         { 28,   "B29" },
1251         { 29,   "B29" },
1252         { 30,   "B30" },
1253         { 0,    NULL }
1254 };
1255
1256 static void
1257 col_set_circuit_id(packet_info *pinfo, int col)
1258 {
1259   pinfo->cinfo->col_expr.col_expr[col][0] = '\0';
1260   pinfo->cinfo->col_expr.col_expr_val[col][0] = '\0';
1261   switch (pinfo->ctype) {
1262
1263   case CT_DLCI:
1264     g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "%u", pinfo->circuit_id);
1265     g_strlcpy(pinfo->cinfo->col_expr.col_expr[col], "fr.dlci", COL_MAX_LEN);
1266     g_snprintf(pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN, "%u", pinfo->circuit_id);
1267     pinfo->cinfo->col_expr.col_expr_val[col][COL_MAX_LEN - 1] = '\0';
1268     break;
1269
1270   case CT_ISDN:
1271     g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "%s",
1272              val_to_str(pinfo->circuit_id, channel_vals, "Unknown (%u)"));
1273     g_strlcpy(pinfo->cinfo->col_expr.col_expr[col], "isdn.channel",
1274         COL_MAX_LEN);
1275     g_snprintf(pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN, "%u", pinfo->circuit_id);
1276     pinfo->cinfo->col_expr.col_expr_val[col][COL_MAX_LEN - 1] = '\0';
1277     break;
1278
1279   case CT_X25:
1280     g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "%u", pinfo->circuit_id);
1281     break;
1282
1283   case CT_ISUP:
1284     g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "%u", pinfo->circuit_id);
1285     g_strlcpy(pinfo->cinfo->col_expr.col_expr[col], "isup.cic", COL_MAX_LEN);
1286     g_snprintf(pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN, "%u", pinfo->circuit_id);
1287     pinfo->cinfo->col_expr.col_expr_val[col][COL_MAX_LEN - 1] = '\0';
1288     break;
1289
1290   default:
1291     break;
1292   }
1293   pinfo->cinfo->col_buf[col][COL_MAX_LEN - 1] = '\0';
1294   pinfo->cinfo->col_data[col] = pinfo->cinfo->col_buf[col];
1295 }
1296
1297 void
1298 col_fill_in(packet_info *pinfo)
1299 {
1300   int i;
1301
1302   for (i = 0; i < pinfo->cinfo->num_cols; i++) {
1303     switch (pinfo->cinfo->col_fmt[i]) {
1304
1305     case COL_NUMBER:
1306       g_snprintf(pinfo->cinfo->col_buf[i], COL_MAX_LEN, "%u", pinfo->fd->num);
1307       pinfo->cinfo->col_data[i] = pinfo->cinfo->col_buf[i];
1308       g_strlcpy(pinfo->cinfo->col_expr.col_expr[i], "frame.number",
1309         COL_MAX_LEN);
1310       g_strlcpy(pinfo->cinfo->col_expr.col_expr_val[i], pinfo->cinfo->col_buf[i], COL_MAX_LEN);
1311       break;
1312
1313     case COL_CLS_TIME:
1314        col_set_cls_time(pinfo->fd, pinfo->cinfo, i);
1315       break;
1316
1317     case COL_ABS_TIME:
1318       col_set_abs_time(pinfo->fd, pinfo->cinfo, i);
1319       break;
1320
1321     case COL_ABS_DATE_TIME:
1322       col_set_abs_date_time(pinfo->fd, pinfo->cinfo, i);
1323       break;
1324
1325     case COL_REL_TIME:
1326       col_set_rel_time(pinfo->fd, pinfo->cinfo, i);
1327       break;
1328
1329     case COL_DELTA_TIME:
1330       col_set_delta_time(pinfo->fd, pinfo->cinfo, i);
1331       break;
1332
1333     case COL_DELTA_TIME_DIS:
1334       col_set_delta_time_dis(pinfo->fd, pinfo->cinfo, i);
1335       break;
1336
1337     case COL_REL_CONV_TIME:
1338     case COL_DELTA_CONV_TIME:
1339       break;            /* Will be set by various dissectors */
1340
1341     case COL_DEF_SRC:
1342     case COL_RES_SRC:   /* COL_DEF_SRC is currently just like COL_RES_SRC */
1343       col_set_addr(pinfo, i, &pinfo->src, TRUE, TRUE);
1344       break;
1345
1346     case COL_UNRES_SRC:
1347       col_set_addr(pinfo, i, &pinfo->src, FALSE, TRUE);
1348       break;
1349
1350     case COL_DEF_DL_SRC:
1351     case COL_RES_DL_SRC:
1352       col_set_addr(pinfo, i, &pinfo->dl_src, TRUE, TRUE);
1353       break;
1354
1355     case COL_UNRES_DL_SRC:
1356       col_set_addr(pinfo, i, &pinfo->dl_src, FALSE, TRUE);
1357       break;
1358
1359     case COL_DEF_NET_SRC:
1360     case COL_RES_NET_SRC:
1361       col_set_addr(pinfo, i, &pinfo->net_src, TRUE, TRUE);
1362       break;
1363
1364     case COL_UNRES_NET_SRC:
1365       col_set_addr(pinfo, i, &pinfo->net_src, FALSE, TRUE);
1366       break;
1367
1368     case COL_DEF_DST:
1369     case COL_RES_DST:   /* COL_DEF_DST is currently just like COL_RES_DST */
1370       col_set_addr(pinfo, i, &pinfo->dst, TRUE, FALSE);
1371       break;
1372
1373     case COL_UNRES_DST:
1374       col_set_addr(pinfo, i, &pinfo->dst, FALSE, FALSE);
1375       break;
1376
1377     case COL_DEF_DL_DST:
1378     case COL_RES_DL_DST:
1379       col_set_addr(pinfo, i, &pinfo->dl_dst, TRUE, FALSE);
1380       break;
1381
1382     case COL_UNRES_DL_DST:
1383       col_set_addr(pinfo, i, &pinfo->dl_dst, FALSE, FALSE);
1384       break;
1385
1386     case COL_DEF_NET_DST:
1387     case COL_RES_NET_DST:
1388       col_set_addr(pinfo, i, &pinfo->net_dst, TRUE, FALSE);
1389       break;
1390
1391     case COL_UNRES_NET_DST:
1392       col_set_addr(pinfo, i, &pinfo->net_dst, FALSE, FALSE);
1393       break;
1394
1395     case COL_DEF_SRC_PORT:
1396     case COL_RES_SRC_PORT:      /* COL_DEF_SRC_PORT is currently just like COL_RES_SRC_PORT */
1397       col_set_port(pinfo, i, TRUE, TRUE);
1398       break;
1399
1400     case COL_UNRES_SRC_PORT:
1401       col_set_port(pinfo, i, FALSE, TRUE);
1402       break;
1403
1404     case COL_DEF_DST_PORT:
1405     case COL_RES_DST_PORT:      /* COL_DEF_DST_PORT is currently just like COL_RES_DST_PORT */
1406       col_set_port(pinfo, i, TRUE, FALSE);
1407       break;
1408
1409     case COL_UNRES_DST_PORT:
1410       col_set_port(pinfo, i, FALSE, FALSE);
1411       break;
1412
1413     case COL_PROTOCOL:  /* currently done by dissectors */
1414     case COL_INFO:      /* currently done by dissectors */
1415       break;
1416
1417     case COL_PACKET_LENGTH:
1418       g_snprintf(pinfo->cinfo->col_buf[i], COL_MAX_LEN, "%u", pinfo->fd->pkt_len);
1419       pinfo->cinfo->col_data[i] = pinfo->cinfo->col_buf[i];
1420       g_strlcpy(pinfo->cinfo->col_expr.col_expr[i], "frame.pkt_len",
1421         COL_MAX_LEN);
1422       g_strlcpy(pinfo->cinfo->col_expr.col_expr_val[i], pinfo->cinfo->col_buf[i], COL_MAX_LEN);
1423       break;
1424
1425     case COL_CUMULATIVE_BYTES:
1426       g_snprintf(pinfo->cinfo->col_buf[i], COL_MAX_LEN, "%u", pinfo->fd->cum_bytes);
1427       pinfo->cinfo->col_data[i] = pinfo->cinfo->col_buf[i];
1428       break;
1429
1430     case COL_OXID:
1431       g_snprintf(pinfo->cinfo->col_buf[i], COL_MAX_LEN, "0x%x", pinfo->oxid);
1432       pinfo->cinfo->col_buf[i][COL_MAX_LEN - 1] = '\0';
1433       pinfo->cinfo->col_data[i] = pinfo->cinfo->col_buf[i];
1434       break;
1435
1436     case COL_RXID:
1437       g_snprintf(pinfo->cinfo->col_buf[i], COL_MAX_LEN, "0x%x", pinfo->rxid);
1438       pinfo->cinfo->col_buf[i][COL_MAX_LEN - 1] = '\0';
1439       pinfo->cinfo->col_data[i] = pinfo->cinfo->col_buf[i];
1440       break;
1441
1442     case COL_IF_DIR:    /* currently done by dissectors */
1443       break;
1444
1445     case COL_CIRCUIT_ID:
1446       col_set_circuit_id(pinfo, i);
1447       break;
1448
1449     case COL_SRCIDX:
1450       g_snprintf(pinfo->cinfo->col_buf[i], COL_MAX_LEN, "0x%x", pinfo->src_idx);
1451       pinfo->cinfo->col_buf[i][COL_MAX_LEN - 1] = '\0';
1452       pinfo->cinfo->col_data[i] = pinfo->cinfo->col_buf[i];
1453       break;
1454
1455     case COL_DSTIDX:
1456       g_snprintf(pinfo->cinfo->col_buf[i], COL_MAX_LEN, "0x%x", pinfo->dst_idx);
1457       pinfo->cinfo->col_buf[i][COL_MAX_LEN - 1] = '\0';
1458       pinfo->cinfo->col_data[i] = pinfo->cinfo->col_buf[i];
1459       break;
1460
1461     case COL_VSAN:
1462       g_snprintf(pinfo->cinfo->col_buf[i], COL_MAX_LEN, "%u", pinfo->vsan);
1463       pinfo->cinfo->col_buf[i][COL_MAX_LEN - 1] = '\0';
1464       pinfo->cinfo->col_data[i] = pinfo->cinfo->col_buf[i];
1465       break;
1466
1467     case COL_HPUX_SUBSYS: /* done by nettl disector */
1468     case COL_HPUX_DEVID:  /* done by nettl disector */
1469       break;
1470
1471     case COL_DCE_CALL:  /* done by dcerpc */
1472       break;
1473
1474     case COL_DCE_CTX:   /* done by dcerpc */
1475       break;
1476
1477     case COL_8021Q_VLAN_ID:
1478         break;
1479
1480     case COL_DSCP_VALUE:        /* done by packet-ip.c */
1481         break;
1482
1483     case COL_COS_VALUE:         /* done by packet-vlan.c */
1484         break;
1485
1486     case COL_FR_DLCI:   /* done by packet-fr.c */
1487     case COL_BSSGP_TLLI: /* done by packet-bssgp.c */
1488         break;
1489
1490     case COL_EXPERT:    /* done by expert.c */
1491         break;
1492
1493     case COL_FREQ_CHAN:    /* done by radio dissectors */
1494         break;
1495
1496     case COL_CUSTOM:     /* done by col_custom_set_fstr() called from proto.c */
1497         break;
1498
1499     case NUM_COL_FMTS:  /* keep compiler happy - shouldn't get here */
1500       g_assert_not_reached();
1501       break;
1502     }
1503   }
1504 }