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