rerun pidl
[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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  */
24
25 #include "config.h"
26
27 #include <string.h>
28 #include <time.h>
29
30 #include "column-utils.h"
31 #include "timestamp.h"
32 #include "sna-utils.h"
33 #include "atalk-utils.h"
34 #include "to_str.h"
35 #include "packet_info.h"
36 #include "wsutil/pint.h"
37 #include "addr_resolv.h"
38 #include "ipv6-utils.h"
39 #include "osi-utils.h"
40 #include "value_string.h"
41 #include "column-info.h"
42 #include "proto.h"
43
44 #include <epan/strutil.h>
45 #include <epan/emem.h>
46 #include <epan/epan.h>
47
48 /* Allocate all the data structures for constructing column data, given
49    the number of columns. */
50 void
51 col_setup(column_info *cinfo, const gint num_cols)
52 {
53   int i;
54
55   cinfo->num_cols              = num_cols;
56   cinfo->col_fmt               = g_new(gint, num_cols);
57   cinfo->fmt_matx              = g_new(gboolean*, num_cols);
58   cinfo->col_first             = g_new(int, NUM_COL_FMTS);
59   cinfo->col_last              = g_new(int, NUM_COL_FMTS);
60   cinfo->col_title             = g_new(gchar*, num_cols);
61   cinfo->col_custom_field      = g_new(gchar*, num_cols);
62   cinfo->col_custom_occurrence = g_new(gint, num_cols);
63   cinfo->col_custom_field_id   = g_new(int, num_cols);
64   cinfo->col_custom_dfilter    = g_new(struct epan_dfilter*, num_cols);
65   cinfo->col_data              = g_new(const 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(const 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 /* Cleanup all the data structures for constructing column data; undoes
78    the allocations that col_setup() does. */
79 void
80 col_cleanup(column_info *cinfo)
81 {
82   g_free(cinfo->col_fmt);
83   g_free(cinfo->fmt_matx);
84   g_free(cinfo->col_first);
85   g_free(cinfo->col_last);
86   g_free(cinfo->col_title);
87   g_free(cinfo->col_custom_field);
88   g_free(cinfo->col_custom_occurrence);
89   g_free(cinfo->col_custom_field_id);
90   g_free(cinfo->col_custom_dfilter);
91   /*
92    * XXX - MSVC doesn't correctly handle the "const" qualifier; it thinks
93    * "const XXX **" means "pointer to const pointer to XXX", i.e. that
94    * it's a pointer to something that's "const"ant, not "pointer to
95    * pointer to const XXX", i.e. that it's a pointer to a pointer to
96    * something that's "const"ant.  Cast its bogus complaints away.
97    */
98   g_free((gchar **)cinfo->col_data);
99   g_free(cinfo->col_buf);
100   g_free(cinfo->col_fence);
101   /* XXX - see above */
102   g_free((gchar **)cinfo->col_expr.col_expr);
103   g_free(cinfo->col_expr.col_expr_val);
104 }
105
106 /* Initialize the data structures for constructing column data. */
107 void
108 col_init(column_info *cinfo, const struct epan_session *epan)
109 {
110   int i;
111
112   if (!cinfo)
113     return;
114
115   for (i = 0; i < cinfo->num_cols; i++) {
116     cinfo->col_buf[i][0] = '\0';
117     cinfo->col_data[i] = cinfo->col_buf[i];
118     cinfo->col_fence[i] = 0;
119     cinfo->col_expr.col_expr[i] = "";
120     cinfo->col_expr.col_expr_val[i][0] = '\0';
121   }
122   cinfo->writable = TRUE;
123   cinfo->epan = epan;
124 }
125
126 #define COL_GET_WRITABLE(cinfo) (cinfo ? cinfo->writable : FALSE)
127
128 gboolean
129 col_get_writable(column_info *cinfo)
130 {
131   return COL_GET_WRITABLE(cinfo);
132 }
133
134 void
135 col_set_writable(column_info *cinfo, const gboolean writable)
136 {
137   if (cinfo)
138     cinfo->writable = writable;
139 }
140
141 /* Checks to see if a particular packet information element is needed for the packet list */
142 #define CHECK_COL(cinfo, el) \
143     /* We are constructing columns, and they're writable */ \
144     (COL_GET_WRITABLE(cinfo) && \
145       /* There is at least one column in that format */ \
146     ((cinfo)->col_first[el] >= 0))
147
148 /* Sets the fence for a column to be at the end of the column. */
149 void
150 col_set_fence(column_info *cinfo, const gint el)
151 {
152   int i;
153
154   if (!CHECK_COL(cinfo, el))
155     return;
156
157   for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
158     if (cinfo->fmt_matx[i][el]) {
159       cinfo->col_fence[i] = (int)strlen(cinfo->col_data[i]);
160     }
161   }
162 }
163
164 /* Clear the fence for a column. */
165 void
166 col_clear_fence(column_info *cinfo, const gint el)
167 {
168   int i;
169
170   if (!CHECK_COL(cinfo, el))
171     return;
172
173   for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
174      if (cinfo->fmt_matx[i][el]) {
175         cinfo->col_fence[i] = 0;
176      }
177   }
178 }
179
180 /* Gets the text of a column */
181 const gchar *
182 col_get_text(column_info *cinfo, const gint el)
183 {
184   int i;
185   const gchar* text = NULL;
186
187   if (!(cinfo && (cinfo)->col_first[el] >= 0)) {
188     return NULL;
189   }
190
191   for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
192     if (cinfo->fmt_matx[i][el]) {
193       text = (cinfo->col_data[i]);
194     }
195   }
196   return text;
197 }
198
199
200 /* Use this to clear out a column, especially if you're going to be
201    appending to it later; at least on some platforms, it's more
202    efficient than using "col_add_str()" with a null string, and
203    more efficient than "col_set_str()" with a null string if you
204    later append to it, as the later append will cause a string
205    copy to be done. */
206 void
207 col_clear(column_info *cinfo, const gint el)
208 {
209   int    i;
210   int    fence;
211
212   if (!CHECK_COL(cinfo, el))
213     return;
214
215   for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
216     if (cinfo->fmt_matx[i][el]) {
217       /*
218        * At this point, either
219        *
220        *   1) col_data[i] is equal to col_buf[i], in which case we
221        *      don't have to worry about copying col_data[i] to
222        *      col_buf[i];
223        *
224        *   2) col_data[i] isn't equal to col_buf[i], in which case
225        *      the only thing that's been done to the column is
226        *      "col_set_str()" calls and possibly "col_set_fence()"
227        *      calls, in which case the fence is either unset and
228        *      at the beginning of the string or set and at the end
229        *      of the string - if it's at the beginning, we're just
230        *      going to clear the column, and if it's at the end,
231        *      we don't do anything.
232        */
233       fence = cinfo->col_fence[i];
234       if (cinfo->col_buf[i] == cinfo->col_data[i] || fence == 0) {
235         /*
236          * The fence isn't at the end of the column, or the column wasn't
237          * last set with "col_set_str()", so clear the column out.
238          */
239         cinfo->col_buf[i][fence] = '\0';
240         cinfo->col_data[i] = cinfo->col_buf[i];
241       }
242       cinfo->col_expr.col_expr[i] = "";
243       cinfo->col_expr.col_expr_val[i][0] = '\0';
244     }
245   }
246 }
247
248 #define COL_CHECK_APPEND(cinfo, i, max_len) \
249   if (cinfo->col_data[i] != cinfo->col_buf[i]) {        \
250     /* This was set with "col_set_str()"; copy the string they  \
251        set it to into the buffer, so we can append to it. */    \
252     g_strlcpy(cinfo->col_buf[i], cinfo->col_data[i], max_len);  \
253     cinfo->col_data[i] = cinfo->col_buf[i];         \
254   }
255
256 #define COL_CHECK_REF_TIME(fd, buf)         \
257   if (fd->flags.ref_time) {                 \
258     g_strlcpy(buf, "*REF*", COL_MAX_LEN );  \
259     return;                                 \
260   }
261
262 /* The same as CHECK_COL(), but without the check to see if the column is writable. */
263 #define HAVE_CUSTOM_COLS(cinfo) ((cinfo) && (cinfo)->col_first[COL_CUSTOM] >= 0)
264
265 gboolean
266 have_custom_cols(column_info *cinfo)
267 {
268   return HAVE_CUSTOM_COLS(cinfo);
269 }
270
271 /* search in edt tree custom fields */
272 void col_custom_set_edt(epan_dissect_t *edt, column_info *cinfo)
273 {
274   int i;
275
276   if (!HAVE_CUSTOM_COLS(cinfo))
277       return;
278
279   for (i = cinfo->col_first[COL_CUSTOM];
280        i <= cinfo->col_last[COL_CUSTOM]; i++) {
281     if (cinfo->fmt_matx[i][COL_CUSTOM] &&
282         cinfo->col_custom_field[i] &&
283         cinfo->col_custom_field_id[i] != -1) {
284        cinfo->col_data[i] = cinfo->col_buf[i];
285        cinfo->col_expr.col_expr[i] = epan_custom_set(edt, cinfo->col_custom_field_id[i],
286                                      cinfo->col_custom_occurrence[i],
287                                      cinfo->col_buf[i],
288                                      cinfo->col_expr.col_expr_val[i],
289                                      COL_MAX_LEN);
290     }
291   }
292 }
293
294 void
295 col_custom_prime_edt(epan_dissect_t *edt, column_info *cinfo)
296 {
297   int i;
298
299   if (!HAVE_CUSTOM_COLS(cinfo))
300     return;
301
302   for (i = cinfo->col_first[COL_CUSTOM];
303        i <= cinfo->col_last[COL_CUSTOM]; i++) {
304
305     cinfo->col_custom_field_id[i] = -1;
306     if (cinfo->fmt_matx[i][COL_CUSTOM] &&
307         cinfo->col_custom_dfilter[i]) {
308       epan_dissect_prime_dfilter(edt, cinfo->col_custom_dfilter[i]);
309       if (cinfo->col_custom_field) {
310         header_field_info* hfinfo = proto_registrar_get_byname(cinfo->col_custom_field[i]);
311         cinfo->col_custom_field_id[i] = hfinfo ? hfinfo->id : -1;
312       }
313     }
314   }
315 }
316
317 /*  Appends a vararg list to a packet info string.
318  *  This function's code is duplicated in col_append_sep_fstr() below because
319  *  the for() loop below requires us to call va_start/va_end so intermediate
320  *  functions are a problem.
321  */
322 void
323 col_append_fstr(column_info *cinfo, const gint el, const gchar *format, ...)
324 {
325   int  i;
326   int  len, max_len;
327   va_list ap;
328
329   if (!CHECK_COL(cinfo, el))
330     return;
331
332   if (el == COL_INFO)
333     max_len = COL_MAX_INFO_LEN;
334   else
335     max_len = COL_MAX_LEN;
336
337   for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
338     if (cinfo->fmt_matx[i][el]) {
339       /*
340        * First arrange that we can append, if necessary.
341        */
342       COL_CHECK_APPEND(cinfo, i, max_len);
343
344       len = (int) strlen(cinfo->col_buf[i]);
345
346       va_start(ap, format);
347       g_vsnprintf(&cinfo->col_buf[i][len], max_len - len, format, ap);
348       va_end(ap);
349     }
350   }
351
352 }
353
354 /*  Appends a vararg list to a packet info string.
355  *  Prefixes it with the given separator if the column is not empty.
356  *  Code is duplicated from col_append_fstr above().
357  */
358 void
359 col_append_sep_fstr(column_info *cinfo, const gint el, const gchar *separator,
360                     const gchar *format, ...)
361 {
362   int  i;
363   int  len, max_len, sep_len;
364   va_list ap;
365
366   if (!CHECK_COL(cinfo, el))
367     return;
368
369   if (separator == NULL)
370     separator = ", ";    /* default */
371
372   sep_len = (int) strlen(separator);
373
374   if (el == COL_INFO)
375     max_len = COL_MAX_INFO_LEN;
376   else
377     max_len = COL_MAX_LEN;
378
379   for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
380     if (cinfo->fmt_matx[i][el]) {
381       /*
382        * First arrange that we can append, if necessary.
383        */
384       COL_CHECK_APPEND(cinfo, i, max_len);
385
386       len = (int) strlen(cinfo->col_buf[i]);
387
388       /*
389        * If we have a separator, append it if the column isn't empty.
390        */
391       if (sep_len != 0) {
392         if (len != 0) {
393           g_strlcat(cinfo->col_buf[i], separator, max_len);
394           len += sep_len;
395         }
396       }
397       va_start(ap, format);
398       g_vsnprintf(&cinfo->col_buf[i][len], max_len - len, format, ap);
399       va_end(ap);
400     }
401   }
402 }
403
404 /* Prepends a vararg list to a packet info string. */
405 #define COL_BUF_MAX_LEN (((COL_MAX_INFO_LEN) > (COL_MAX_LEN)) ? \
406     (COL_MAX_INFO_LEN) : (COL_MAX_LEN))
407 void
408 col_prepend_fstr(column_info *cinfo, const gint el, const gchar *format, ...)
409 {
410   va_list     ap;
411   int         i;
412   char        orig_buf[COL_BUF_MAX_LEN];
413   const char *orig;
414   int         max_len;
415
416   if (!CHECK_COL(cinfo, el))
417     return;
418
419   if (el == COL_INFO)
420     max_len = COL_MAX_INFO_LEN;
421   else
422     max_len = COL_MAX_LEN;
423
424   for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
425     if (cinfo->fmt_matx[i][el]) {
426       if (cinfo->col_data[i] != cinfo->col_buf[i]) {
427         /* This was set with "col_set_str()"; which is effectively const */
428         orig = cinfo->col_data[i];
429       } else {
430         g_strlcpy(orig_buf, cinfo->col_buf[i], max_len);
431         orig = orig_buf;
432       }
433       va_start(ap, format);
434       g_vsnprintf(cinfo->col_buf[i], max_len, format, ap);
435       va_end(ap);
436
437       /*
438        * Move the fence, unless it's at the beginning of the string.
439        */
440       if (cinfo->col_fence[i] > 0)
441         cinfo->col_fence[i] += (int) strlen(cinfo->col_buf[i]);
442
443       g_strlcat(cinfo->col_buf[i], orig, max_len);
444       cinfo->col_data[i] = cinfo->col_buf[i];
445     }
446   }
447 }
448 void
449 col_prepend_fence_fstr(column_info *cinfo, const gint el, const gchar *format, ...)
450 {
451   va_list     ap;
452   int         i;
453   char        orig_buf[COL_BUF_MAX_LEN];
454   const char *orig;
455   int         max_len;
456
457   if (!CHECK_COL(cinfo, el))
458     return;
459
460   if (el == COL_INFO)
461     max_len = COL_MAX_INFO_LEN;
462   else
463     max_len = COL_MAX_LEN;
464
465   for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
466     if (cinfo->fmt_matx[i][el]) {
467       if (cinfo->col_data[i] != cinfo->col_buf[i]) {
468         /* This was set with "col_set_str()"; which is effectively const */
469         orig = cinfo->col_data[i];
470       } else {
471         g_strlcpy(orig_buf, cinfo->col_buf[i], max_len);
472         orig = orig_buf;
473       }
474       va_start(ap, format);
475       g_vsnprintf(cinfo->col_buf[i], max_len, format, ap);
476       va_end(ap);
477
478       /*
479        * Move the fence if it exists, else create a new fence at the
480        * end of the prepended data.
481        */
482       if (cinfo->col_fence[i] > 0) {
483         cinfo->col_fence[i] += (int) strlen(cinfo->col_buf[i]);
484       } else {
485         cinfo->col_fence[i]  = (int) strlen(cinfo->col_buf[i]);
486       }
487       g_strlcat(cinfo->col_buf[i], orig, max_len);
488       cinfo->col_data[i] = cinfo->col_buf[i];
489     }
490   }
491 }
492
493 /* Use this if "str" points to something that won't stay around (and
494    must thus be copied). */
495 void
496 col_add_str(column_info *cinfo, const gint el, const gchar* str)
497 {
498   int    i;
499   int    fence;
500   size_t max_len;
501
502   if (!CHECK_COL(cinfo, el))
503     return;
504
505   if (el == COL_INFO)
506     max_len = COL_MAX_INFO_LEN;
507   else
508     max_len = COL_MAX_LEN;
509
510   for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
511     if (cinfo->fmt_matx[i][el]) {
512       fence = cinfo->col_fence[i];
513       if (fence != 0) {
514         /*
515          * We will append the string after the fence.
516          * First arrange that we can append, if necessary.
517          */
518         COL_CHECK_APPEND(cinfo, i, max_len);
519       } else {
520         /*
521          * There's no fence, so we can just write to the string.
522          */
523         cinfo->col_data[i] = cinfo->col_buf[i];
524       }
525       g_strlcpy(&cinfo->col_buf[i][fence], str, max_len - fence);
526     }
527   }
528 }
529
530 /* Use this if "str" points to something that will stay around (and thus
531    needn't be copied). */
532 void
533 col_set_str(column_info *cinfo, const gint el, const gchar* str)
534 {
535   int i;
536   int fence;
537   size_t max_len;
538
539   DISSECTOR_ASSERT(str);
540
541   /* The caller is expected to pass in something that 'will stay around' and
542    * something from the ephemeral pool certainly doesn't fit the bill. */
543   DISSECTOR_ASSERT(!ep_verify_pointer(str));
544
545   if (!CHECK_COL(cinfo, el))
546     return;
547
548   if (el == COL_INFO)
549     max_len = COL_MAX_INFO_LEN;
550   else
551     max_len = COL_MAX_LEN;
552
553   for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
554     if (cinfo->fmt_matx[i][el]) {
555       fence = cinfo->col_fence[i];
556       if (fence != 0) {
557         /*
558          * We will append the string after the fence.
559          * First arrange that we can append, if necessary.
560          */
561         COL_CHECK_APPEND(cinfo, i, max_len);
562
563         g_strlcpy(&cinfo->col_buf[i][fence], str, max_len - fence);
564       } else {
565         /*
566          * There's no fence, so we can just set the column to point
567          * to the string.
568          */
569         cinfo->col_data[i] = str;
570       }
571     }
572   }
573 }
574
575 /* Adds a vararg list to a packet info string. */
576 void
577 col_add_fstr(column_info *cinfo, const gint el, const gchar *format, ...) {
578   va_list ap;
579   int     i;
580   int     fence;
581   int     max_len;
582
583   if (!CHECK_COL(cinfo, el))
584     return;
585
586   if (el == COL_INFO)
587     max_len = COL_MAX_INFO_LEN;
588   else
589     max_len = COL_MAX_LEN;
590
591   for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
592     if (cinfo->fmt_matx[i][el]) {
593       fence = cinfo->col_fence[i];
594       if (fence != 0) {
595         /*
596          * We will append the string after the fence.
597          * First arrange that we can append, if necessary.
598          */
599         COL_CHECK_APPEND(cinfo, i, max_len);
600       } else {
601         /*
602          * There's no fence, so we can just write to the string.
603          */
604         cinfo->col_data[i] = cinfo->col_buf[i];
605       }
606       va_start(ap, format);
607       g_vsnprintf(&cinfo->col_buf[i][fence], max_len - fence, format, ap);
608       va_end(ap);
609     }
610   }
611 }
612
613 static void
614 col_do_append_str(column_info *cinfo, const gint el, const gchar* separator,
615     const gchar* str)
616 {
617   int    i;
618   size_t len, max_len;
619
620   if (el == COL_INFO)
621     max_len = COL_MAX_INFO_LEN;
622   else
623     max_len = COL_MAX_LEN;
624
625   for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
626     if (cinfo->fmt_matx[i][el]) {
627       /*
628        * First arrange that we can append, if necessary.
629        */
630       COL_CHECK_APPEND(cinfo, i, max_len);
631
632       len = cinfo->col_buf[i][0];
633
634       /*
635        * If we have a separator, append it if the column isn't empty.
636        */
637       if (separator != NULL) {
638         if (len != 0) {
639           g_strlcat(cinfo->col_buf[i], separator, max_len);
640         }
641       }
642       g_strlcat(cinfo->col_buf[i], str, max_len);
643     }
644   }
645 }
646
647 void
648 col_append_str(column_info *cinfo, const gint el, const gchar* str)
649 {
650   if (!CHECK_COL(cinfo, el))
651     return;
652
653   col_do_append_str(cinfo, el, NULL, str);
654 }
655
656 void
657 col_append_sep_str(column_info *cinfo, const gint el, const gchar* separator,
658     const gchar* str)
659 {
660   if (!CHECK_COL(cinfo, el))
661     return;
662
663   if (separator == NULL)
664     separator = ", ";    /* default */
665
666   col_do_append_str(cinfo, el, separator, str);
667 }
668
669 /* --------------------------------- */
670 gboolean
671 col_has_time_fmt(column_info *cinfo, const gint col)
672 {
673   return ((cinfo->fmt_matx[col][COL_CLS_TIME]) ||
674           (cinfo->fmt_matx[col][COL_ABS_TIME]) ||
675           (cinfo->fmt_matx[col][COL_ABS_YMD_TIME]) ||
676           (cinfo->fmt_matx[col][COL_ABS_YDOY_TIME]) ||
677           (cinfo->fmt_matx[col][COL_UTC_TIME]) ||
678           (cinfo->fmt_matx[col][COL_UTC_YMD_TIME]) ||
679           (cinfo->fmt_matx[col][COL_UTC_YDOY_TIME]) ||
680           (cinfo->fmt_matx[col][COL_REL_TIME]) ||
681           (cinfo->fmt_matx[col][COL_DELTA_TIME]) ||
682           (cinfo->fmt_matx[col][COL_DELTA_TIME_DIS]));
683 }
684
685 static void
686 set_abs_ymd_time(const frame_data *fd, gchar *buf, gboolean local)
687 {
688   struct tm *tmp;
689   time_t then;
690
691   if (fd->flags.has_ts) {
692     then = fd->abs_ts.secs;
693     if (local)
694       tmp = localtime(&then);
695     else
696       tmp = gmtime(&then);
697   } else
698     tmp = NULL;
699   if (tmp != NULL) {
700     switch (timestamp_get_precision()) {
701     case TS_PREC_FIXED_SEC:
702     case TS_PREC_AUTO_SEC:
703       g_snprintf(buf, COL_MAX_LEN,"%04d-%02d-%02d %02d:%02d:%02d",
704         tmp->tm_year + 1900,
705         tmp->tm_mon + 1,
706         tmp->tm_mday,
707         tmp->tm_hour,
708         tmp->tm_min,
709         tmp->tm_sec);
710       break;
711     case TS_PREC_FIXED_DSEC:
712     case TS_PREC_AUTO_DSEC:
713       g_snprintf(buf, COL_MAX_LEN,"%04d-%02d-%02d %02d:%02d:%02d.%01d",
714         tmp->tm_year + 1900,
715         tmp->tm_mon + 1,
716         tmp->tm_mday,
717         tmp->tm_hour,
718         tmp->tm_min,
719         tmp->tm_sec,
720         fd->abs_ts.nsecs / 100000000);
721       break;
722     case TS_PREC_FIXED_CSEC:
723     case TS_PREC_AUTO_CSEC:
724       g_snprintf(buf, COL_MAX_LEN,"%04d-%02d-%02d %02d:%02d:%02d.%02d",
725         tmp->tm_year + 1900,
726         tmp->tm_mon + 1,
727         tmp->tm_mday,
728         tmp->tm_hour,
729         tmp->tm_min,
730         tmp->tm_sec,
731         fd->abs_ts.nsecs / 10000000);
732       break;
733     case TS_PREC_FIXED_MSEC:
734     case TS_PREC_AUTO_MSEC:
735       g_snprintf(buf, COL_MAX_LEN, "%04d-%02d-%02d %02d:%02d:%02d.%03d",
736         tmp->tm_year + 1900,
737         tmp->tm_mon + 1,
738         tmp->tm_mday,
739         tmp->tm_hour,
740         tmp->tm_min,
741         tmp->tm_sec,
742         fd->abs_ts.nsecs / 1000000);
743       break;
744     case TS_PREC_FIXED_USEC:
745     case TS_PREC_AUTO_USEC:
746       g_snprintf(buf, COL_MAX_LEN, "%04d-%02d-%02d %02d:%02d:%02d.%06d",
747         tmp->tm_year + 1900,
748         tmp->tm_mon + 1,
749         tmp->tm_mday,
750         tmp->tm_hour,
751         tmp->tm_min,
752         tmp->tm_sec,
753         fd->abs_ts.nsecs / 1000);
754       break;
755     case TS_PREC_FIXED_NSEC:
756     case TS_PREC_AUTO_NSEC:
757       g_snprintf(buf, COL_MAX_LEN, "%04d-%02d-%02d %02d:%02d:%02d.%09d",
758         tmp->tm_year + 1900,
759         tmp->tm_mon + 1,
760         tmp->tm_mday,
761         tmp->tm_hour,
762         tmp->tm_min,
763         tmp->tm_sec,
764         fd->abs_ts.nsecs);
765       break;
766     default:
767       g_assert_not_reached();
768     }
769   } else {
770     buf[0] = '\0';
771   }
772 }
773
774 static void
775 col_set_abs_ymd_time(const frame_data *fd, column_info *cinfo, const int col)
776 {
777   set_abs_ymd_time(fd, cinfo->col_buf[col], TRUE);
778   cinfo->col_expr.col_expr[col] = "frame.time";
779   g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->col_buf[col],COL_MAX_LEN);
780
781   cinfo->col_data[col] = cinfo->col_buf[col];
782 }
783
784 static void
785 col_set_utc_ymd_time(const frame_data *fd, column_info *cinfo, const int col)
786 {
787   set_abs_ymd_time(fd, cinfo->col_buf[col], FALSE);
788   cinfo->col_expr.col_expr[col] = "frame.time";
789   g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->col_buf[col],COL_MAX_LEN);
790
791   cinfo->col_data[col] = cinfo->col_buf[col];
792 }
793
794 static void
795 set_abs_ydoy_time(const frame_data *fd, gchar *buf, gboolean local)
796 {
797   struct tm *tmp;
798   time_t then;
799
800   if (fd->flags.has_ts) {
801     then = fd->abs_ts.secs;
802     if (local)
803       tmp = localtime(&then);
804     else
805       tmp = gmtime(&then);
806   } else
807     tmp = NULL;
808   if (tmp != NULL) {
809     switch (timestamp_get_precision()) {
810     case TS_PREC_FIXED_SEC:
811     case TS_PREC_AUTO_SEC:
812       g_snprintf(buf, COL_MAX_LEN,"%04d/%03d %02d:%02d:%02d",
813         tmp->tm_year + 1900,
814         tmp->tm_yday + 1,
815         tmp->tm_hour,
816         tmp->tm_min,
817         tmp->tm_sec);
818       break;
819     case TS_PREC_FIXED_DSEC:
820     case TS_PREC_AUTO_DSEC:
821       g_snprintf(buf, COL_MAX_LEN,"%04d/%03d %02d:%02d:%02d.%01d",
822         tmp->tm_year + 1900,
823         tmp->tm_yday + 1,
824         tmp->tm_hour,
825         tmp->tm_min,
826         tmp->tm_sec,
827         fd->abs_ts.nsecs / 100000000);
828       break;
829     case TS_PREC_FIXED_CSEC:
830     case TS_PREC_AUTO_CSEC:
831       g_snprintf(buf, COL_MAX_LEN,"%04d/%03d %02d:%02d:%02d.%02d",
832         tmp->tm_year + 1900,
833         tmp->tm_yday + 1,
834         tmp->tm_hour,
835         tmp->tm_min,
836         tmp->tm_sec,
837         fd->abs_ts.nsecs / 10000000);
838       break;
839     case TS_PREC_FIXED_MSEC:
840     case TS_PREC_AUTO_MSEC:
841       g_snprintf(buf, COL_MAX_LEN, "%04d/%03d %02d:%02d:%02d.%03d",
842         tmp->tm_year + 1900,
843         tmp->tm_yday + 1,
844         tmp->tm_hour,
845         tmp->tm_min,
846         tmp->tm_sec,
847         fd->abs_ts.nsecs / 1000000);
848       break;
849     case TS_PREC_FIXED_USEC:
850     case TS_PREC_AUTO_USEC:
851       g_snprintf(buf, COL_MAX_LEN, "%04d/%03d %02d:%02d:%02d.%06d",
852         tmp->tm_year + 1900,
853         tmp->tm_yday + 1,
854         tmp->tm_hour,
855         tmp->tm_min,
856         tmp->tm_sec,
857         fd->abs_ts.nsecs / 1000);
858       break;
859     case TS_PREC_FIXED_NSEC:
860     case TS_PREC_AUTO_NSEC:
861       g_snprintf(buf, COL_MAX_LEN, "%04d/%03d %02d:%02d:%02d.%09d",
862         tmp->tm_year + 1900,
863         tmp->tm_yday + 1,
864         tmp->tm_hour,
865         tmp->tm_min,
866         tmp->tm_sec,
867         fd->abs_ts.nsecs);
868       break;
869     default:
870       g_assert_not_reached();
871     }
872   } else {
873     buf[0] = '\0';
874   }
875 }
876
877 static void
878 col_set_abs_ydoy_time(const frame_data *fd, column_info *cinfo, const int col)
879 {
880   set_abs_ydoy_time(fd, cinfo->col_buf[col], TRUE);
881   cinfo->col_expr.col_expr[col] = "frame.time";
882   g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->col_buf[col],COL_MAX_LEN);
883
884   cinfo->col_data[col] = cinfo->col_buf[col];
885 }
886
887 static void
888 col_set_utc_ydoy_time(const frame_data *fd, column_info *cinfo, const int col)
889 {
890   set_abs_ydoy_time(fd, cinfo->col_buf[col], FALSE);
891   cinfo->col_expr.col_expr[col] = "frame.time";
892   g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->col_buf[col],COL_MAX_LEN);
893
894   cinfo->col_data[col] = cinfo->col_buf[col];
895 }
896
897 static void
898 set_time_seconds(const nstime_t *ts, gchar *buf)
899 {
900   switch (timestamp_get_precision()) {
901   case TS_PREC_FIXED_SEC:
902   case TS_PREC_AUTO_SEC:
903     display_signed_time(buf, COL_MAX_LEN,
904       (gint32) ts->secs, ts->nsecs / 1000000000, TO_STR_TIME_RES_T_SECS);
905     break;
906   case TS_PREC_FIXED_DSEC:
907   case TS_PREC_AUTO_DSEC:
908     display_signed_time(buf, COL_MAX_LEN,
909       (gint32) ts->secs, ts->nsecs / 100000000, TO_STR_TIME_RES_T_DSECS);
910     break;
911   case TS_PREC_FIXED_CSEC:
912   case TS_PREC_AUTO_CSEC:
913     display_signed_time(buf, COL_MAX_LEN,
914       (gint32) ts->secs, ts->nsecs / 10000000, TO_STR_TIME_RES_T_CSECS);
915     break;
916   case TS_PREC_FIXED_MSEC:
917   case TS_PREC_AUTO_MSEC:
918     display_signed_time(buf, COL_MAX_LEN,
919       (gint32) ts->secs, ts->nsecs / 1000000, TO_STR_TIME_RES_T_MSECS);
920     break;
921   case TS_PREC_FIXED_USEC:
922   case TS_PREC_AUTO_USEC:
923     display_signed_time(buf, COL_MAX_LEN,
924       (gint32) ts->secs, ts->nsecs / 1000, TO_STR_TIME_RES_T_USECS);
925     break;
926   case TS_PREC_FIXED_NSEC:
927   case TS_PREC_AUTO_NSEC:
928     display_signed_time(buf, COL_MAX_LEN,
929       (gint32) ts->secs, ts->nsecs, TO_STR_TIME_RES_T_NSECS);
930     break;
931   default:
932     g_assert_not_reached();
933   }
934 }
935
936 static void
937 set_time_hour_min_sec(const nstime_t *ts, gchar *buf)
938 {
939   time_t secs = ts->secs;
940   long nsecs = (long) ts->nsecs;
941   gboolean negative = FALSE;
942
943   if (secs < 0) {
944     secs = -secs;
945     negative = TRUE;
946   }
947   if (nsecs < 0) {
948     nsecs = -nsecs;
949     negative = TRUE;
950   }
951
952   switch (timestamp_get_precision()) {
953   case TS_PREC_FIXED_SEC:
954   case TS_PREC_AUTO_SEC:
955     if (secs >= (60*60)) {
956       g_snprintf(buf, COL_MAX_LEN, "%s%dh %2dm %2ds",
957                  negative ? "- " : "",
958                  (gint32) secs / (60 * 60),
959                  (gint32) (secs / 60) % 60,
960                  (gint32) secs % 60);
961     } else if (secs >= 60) {
962       g_snprintf(buf, COL_MAX_LEN, "%s%dm %2ds",
963                  negative ? "- " : "",
964                  (gint32) secs / 60,
965                  (gint32) secs % 60);
966     } else {
967       g_snprintf(buf, COL_MAX_LEN, "%s%ds",
968                  negative ? "- " : "",
969                  (gint32) secs);
970     }
971     break;
972   case TS_PREC_FIXED_DSEC:
973   case TS_PREC_AUTO_DSEC:
974     if (secs >= (60*60)) {
975       g_snprintf(buf, COL_MAX_LEN, "%s%dh %2dm %2d.%01lds",
976                  negative ? "- " : "",
977                  (gint32) secs / (60 * 60),
978                  (gint32) (secs / 60) % 60,
979                  (gint32) secs % 60,
980                  nsecs / 100000000);
981     } else if (secs >= 60) {
982       g_snprintf(buf, COL_MAX_LEN, "%s%dm %2d.%01lds",
983                  negative ? "- " : "",
984                  (gint32) secs / 60,
985                  (gint32) secs % 60,
986                  nsecs / 100000000);
987     } else {
988       g_snprintf(buf, COL_MAX_LEN, "%s%d.%01lds",
989                  negative ? "- " : "",
990                  (gint32) secs,
991                  nsecs / 100000000);
992     }
993     break;
994   case TS_PREC_FIXED_CSEC:
995   case TS_PREC_AUTO_CSEC:
996     if (secs >= (60*60)) {
997       g_snprintf(buf, COL_MAX_LEN, "%s%dh %2dm %2d.%02lds",
998                  negative ? "- " : "",
999                  (gint32) secs / (60 * 60),
1000                  (gint32) (secs / 60) % 60,
1001                  (gint32) secs % 60,
1002                  nsecs / 10000000);
1003     } else if (secs >= 60) {
1004       g_snprintf(buf, COL_MAX_LEN, "%s%dm %2d.%02lds",
1005                  negative ? "- " : "",
1006                  (gint32) secs / 60,
1007                  (gint32) secs % 60,
1008                  nsecs / 10000000);
1009     } else {
1010       g_snprintf(buf, COL_MAX_LEN, "%s%d.%02lds",
1011                  negative ? "- " : "",
1012                  (gint32) secs,
1013                  nsecs / 10000000);
1014     }
1015     break;
1016   case TS_PREC_FIXED_MSEC:
1017   case TS_PREC_AUTO_MSEC:
1018     if (secs >= (60*60)) {
1019       g_snprintf(buf, COL_MAX_LEN, "%s%dh %2dm %2d.%03lds",
1020                  negative ? "- " : "",
1021                  (gint32) secs / (60 * 60),
1022                  (gint32) (secs / 60) % 60,
1023                  (gint32) secs % 60,
1024                  nsecs / 1000000);
1025     } else if (secs >= 60) {
1026       g_snprintf(buf, COL_MAX_LEN, "%s%dm %2d.%03lds",
1027                  negative ? "- " : "",
1028                  (gint32) secs / 60,
1029                  (gint32) secs % 60,
1030                  nsecs / 1000000);
1031     } else {
1032       g_snprintf(buf, COL_MAX_LEN, "%s%d.%03lds",
1033                  negative ? "- " : "",
1034                  (gint32) secs,
1035                  nsecs / 1000000);
1036     }
1037     break;
1038   case TS_PREC_FIXED_USEC:
1039   case TS_PREC_AUTO_USEC:
1040     if (secs >= (60*60)) {
1041       g_snprintf(buf, COL_MAX_LEN, "%s%dh %2dm %2d.%06lds",
1042                  negative ? "- " : "",
1043                  (gint32) secs / (60 * 60),
1044                  (gint32) (secs / 60) % 60,
1045                  (gint32) secs % 60,
1046                  nsecs / 1000);
1047     } else if (secs >= 60) {
1048       g_snprintf(buf, COL_MAX_LEN, "%s%dm %2d.%06lds",
1049                  negative ? "- " : "",
1050                  (gint32) secs / 60,
1051                  (gint32) secs % 60,
1052                  nsecs / 1000);
1053     } else {
1054       g_snprintf(buf, COL_MAX_LEN, "%s%d.%06lds",
1055                  negative ? "- " : "",
1056                  (gint32) secs,
1057                  nsecs / 1000);
1058     }
1059     break;
1060   case TS_PREC_FIXED_NSEC:
1061   case TS_PREC_AUTO_NSEC:
1062     if (secs >= (60*60)) {
1063       g_snprintf(buf, COL_MAX_LEN, "%s%dh %2dm %2d.%09lds",
1064                  negative ? "- " : "",
1065                  (gint32) secs / (60 * 60),
1066                  (gint32) (secs / 60) % 60,
1067                  (gint32) secs % 60,
1068                  nsecs);
1069     } else if (secs >= 60) {
1070       g_snprintf(buf, COL_MAX_LEN, "%s%dm %2d.%09lds",
1071                  negative ? "- " : "",
1072                  (gint32) secs / 60,
1073                  (gint32) secs % 60,
1074                  nsecs);
1075     } else {
1076       g_snprintf(buf, COL_MAX_LEN, "%s%d.%09lds",
1077                  negative ? "- " : "",
1078                  (gint32) secs,
1079                  nsecs);
1080     }
1081     break;
1082   default:
1083     g_assert_not_reached();
1084   }
1085 }
1086
1087 static void
1088 col_set_rel_time(const frame_data *fd, column_info *cinfo, const int col)
1089 {
1090   nstime_t del_rel_ts;
1091
1092   if (!fd->flags.has_ts) {
1093     cinfo->col_buf[col][0] = '\0';
1094     return;
1095   }
1096
1097   frame_delta_abs_time(cinfo->epan, fd, fd->frame_ref_num, &del_rel_ts);
1098
1099   switch (timestamp_get_seconds_type()) {
1100   case TS_SECONDS_DEFAULT:
1101     set_time_seconds(&del_rel_ts, cinfo->col_buf[col]);
1102     cinfo->col_expr.col_expr[col] = "frame.time_relative";
1103     g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->col_buf[col],COL_MAX_LEN);
1104     break;
1105   case TS_SECONDS_HOUR_MIN_SEC:
1106     set_time_hour_min_sec(&del_rel_ts, cinfo->col_buf[col]);
1107     cinfo->col_expr.col_expr[col] = "frame.time_relative";
1108     set_time_seconds(&del_rel_ts, cinfo->col_expr.col_expr_val[col]);
1109     break;
1110   default:
1111     g_assert_not_reached();
1112   }
1113   cinfo->col_data[col] = cinfo->col_buf[col];
1114 }
1115
1116 static void
1117 col_set_delta_time(const frame_data *fd, column_info *cinfo, const int col)
1118 {
1119   nstime_t del_cap_ts;
1120
1121   frame_delta_abs_time(cinfo->epan, fd, fd->num - 1, &del_cap_ts);
1122
1123   switch (timestamp_get_seconds_type()) {
1124   case TS_SECONDS_DEFAULT:
1125     set_time_seconds(&del_cap_ts, cinfo->col_buf[col]);
1126     cinfo->col_expr.col_expr[col] = "frame.time_delta";
1127     g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->col_buf[col],COL_MAX_LEN);
1128     break;
1129   case TS_SECONDS_HOUR_MIN_SEC:
1130     set_time_hour_min_sec(&del_cap_ts, cinfo->col_buf[col]);
1131     cinfo->col_expr.col_expr[col] = "frame.time_delta";
1132     set_time_seconds(&del_cap_ts, cinfo->col_expr.col_expr_val[col]);
1133     break;
1134   default:
1135     g_assert_not_reached();
1136   }
1137
1138   cinfo->col_data[col] = cinfo->col_buf[col];
1139 }
1140
1141 static void
1142 col_set_delta_time_dis(const frame_data *fd, column_info *cinfo, const int col)
1143 {
1144   nstime_t del_dis_ts;
1145
1146   if (!fd->flags.has_ts) {
1147     cinfo->col_buf[col][0] = '\0';
1148     return;
1149   }
1150
1151   frame_delta_abs_time(cinfo->epan, fd, fd->prev_dis_num, &del_dis_ts);
1152
1153   switch (timestamp_get_seconds_type()) {
1154   case TS_SECONDS_DEFAULT:
1155     set_time_seconds(&del_dis_ts, cinfo->col_buf[col]);
1156     cinfo->col_expr.col_expr[col] = "frame.time_delta_displayed";
1157     g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->col_buf[col],COL_MAX_LEN);
1158     break;
1159   case TS_SECONDS_HOUR_MIN_SEC:
1160     set_time_hour_min_sec(&del_dis_ts, cinfo->col_buf[col]);
1161     cinfo->col_expr.col_expr[col] = "frame.time_delta_displayed";
1162     set_time_seconds(&del_dis_ts, cinfo->col_expr.col_expr_val[col]);
1163     break;
1164   default:
1165     g_assert_not_reached();
1166   }
1167
1168   cinfo->col_data[col] = cinfo->col_buf[col];
1169 }
1170
1171 static void
1172 set_abs_time(const frame_data *fd, gchar *buf, gboolean local)
1173 {
1174   struct tm *tmp;
1175   time_t then;
1176
1177   if (fd->flags.has_ts) {
1178     then = fd->abs_ts.secs;
1179     if (local)
1180       tmp = localtime(&then);
1181     else
1182       tmp = gmtime(&then);
1183   } else
1184     tmp = NULL;
1185   if (tmp != NULL) {
1186     switch (timestamp_get_precision()) {
1187     case TS_PREC_FIXED_SEC:
1188     case TS_PREC_AUTO_SEC:
1189       g_snprintf(buf, COL_MAX_LEN,"%02d:%02d:%02d",
1190         tmp->tm_hour,
1191         tmp->tm_min,
1192         tmp->tm_sec);
1193       break;
1194     case TS_PREC_FIXED_DSEC:
1195     case TS_PREC_AUTO_DSEC:
1196       g_snprintf(buf, COL_MAX_LEN,"%02d:%02d:%02d.%01d",
1197         tmp->tm_hour,
1198         tmp->tm_min,
1199         tmp->tm_sec,
1200         fd->abs_ts.nsecs / 100000000);
1201       break;
1202     case TS_PREC_FIXED_CSEC:
1203     case TS_PREC_AUTO_CSEC:
1204       g_snprintf(buf, COL_MAX_LEN,"%02d:%02d:%02d.%02d",
1205         tmp->tm_hour,
1206         tmp->tm_min,
1207         tmp->tm_sec,
1208         fd->abs_ts.nsecs / 10000000);
1209       break;
1210     case TS_PREC_FIXED_MSEC:
1211     case TS_PREC_AUTO_MSEC:
1212       g_snprintf(buf, COL_MAX_LEN,"%02d:%02d:%02d.%03d",
1213         tmp->tm_hour,
1214         tmp->tm_min,
1215         tmp->tm_sec,
1216         fd->abs_ts.nsecs / 1000000);
1217       break;
1218     case TS_PREC_FIXED_USEC:
1219     case TS_PREC_AUTO_USEC:
1220       g_snprintf(buf, COL_MAX_LEN,"%02d:%02d:%02d.%06d",
1221         tmp->tm_hour,
1222         tmp->tm_min,
1223         tmp->tm_sec,
1224         fd->abs_ts.nsecs / 1000);
1225       break;
1226     case TS_PREC_FIXED_NSEC:
1227     case TS_PREC_AUTO_NSEC:
1228       g_snprintf(buf, COL_MAX_LEN, "%02d:%02d:%02d.%09d",
1229         tmp->tm_hour,
1230         tmp->tm_min,
1231         tmp->tm_sec,
1232         fd->abs_ts.nsecs);
1233       break;
1234     default:
1235       g_assert_not_reached();
1236     }
1237
1238   } else {
1239     *buf = '\0';
1240   }
1241 }
1242
1243 static void
1244 col_set_abs_time(const frame_data *fd, column_info *cinfo, const int col)
1245 {
1246   set_abs_time(fd, cinfo->col_buf[col], TRUE);
1247   cinfo->col_expr.col_expr[col] = "frame.time";
1248   g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->col_buf[col],COL_MAX_LEN);
1249
1250   cinfo->col_data[col] = cinfo->col_buf[col];
1251 }
1252
1253 static void
1254 col_set_utc_time(const frame_data *fd, column_info *cinfo, const int col)
1255 {
1256   set_abs_time(fd, cinfo->col_buf[col], FALSE);
1257   cinfo->col_expr.col_expr[col] = "frame.time";
1258   g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->col_buf[col],COL_MAX_LEN);
1259
1260   cinfo->col_data[col] = cinfo->col_buf[col];
1261 }
1262
1263 static gboolean
1264 set_epoch_time(const frame_data *fd, gchar *buf)
1265 {
1266   if (!fd->flags.has_ts) {
1267     buf[0] = '\0';
1268     return FALSE;
1269   }
1270   switch (timestamp_get_precision()) {
1271   case TS_PREC_FIXED_SEC:
1272   case TS_PREC_AUTO_SEC:
1273     display_epoch_time(buf, COL_MAX_LEN,
1274       fd->abs_ts.secs, fd->abs_ts.nsecs / 1000000000, TO_STR_TIME_RES_T_SECS);
1275     break;
1276   case TS_PREC_FIXED_DSEC:
1277   case TS_PREC_AUTO_DSEC:
1278     display_epoch_time(buf, COL_MAX_LEN,
1279        fd->abs_ts.secs, fd->abs_ts.nsecs / 100000000, TO_STR_TIME_RES_T_DSECS);
1280     break;
1281   case TS_PREC_FIXED_CSEC:
1282   case TS_PREC_AUTO_CSEC:
1283     display_epoch_time(buf, COL_MAX_LEN,
1284        fd->abs_ts.secs, fd->abs_ts.nsecs / 10000000, TO_STR_TIME_RES_T_CSECS);
1285     break;
1286   case TS_PREC_FIXED_MSEC:
1287   case TS_PREC_AUTO_MSEC:
1288     display_epoch_time(buf, COL_MAX_LEN,
1289        fd->abs_ts.secs, fd->abs_ts.nsecs / 1000000, TO_STR_TIME_RES_T_MSECS);
1290     break;
1291   case TS_PREC_FIXED_USEC:
1292   case TS_PREC_AUTO_USEC:
1293     display_epoch_time(buf, COL_MAX_LEN,
1294        fd->abs_ts.secs, fd->abs_ts.nsecs / 1000, TO_STR_TIME_RES_T_USECS);
1295     break;
1296   case TS_PREC_FIXED_NSEC:
1297   case TS_PREC_AUTO_NSEC:
1298     display_epoch_time(buf, COL_MAX_LEN,
1299        fd->abs_ts.secs, fd->abs_ts.nsecs, TO_STR_TIME_RES_T_NSECS);
1300     break;
1301   default:
1302     g_assert_not_reached();
1303   }
1304   return TRUE;
1305 }
1306
1307 static void
1308 col_set_epoch_time(const frame_data *fd, column_info *cinfo, const int col)
1309 {
1310   if (set_epoch_time(fd, cinfo->col_buf[col])) {
1311     cinfo->col_expr.col_expr[col] = "frame.time_delta";
1312     g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->col_buf[col],COL_MAX_LEN);
1313   }
1314   cinfo->col_data[col] = cinfo->col_buf[col];
1315 }
1316
1317 void
1318 set_fd_time(const epan_t *epan, frame_data *fd, gchar *buf)
1319 {
1320
1321   switch (timestamp_get_type()) {
1322   case TS_ABSOLUTE:
1323     set_abs_time(fd, buf, TRUE);
1324     break;
1325
1326   case TS_ABSOLUTE_WITH_YMD:
1327     set_abs_ymd_time(fd, buf, TRUE);
1328     break;
1329
1330   case TS_ABSOLUTE_WITH_YDOY:
1331     set_abs_ydoy_time(fd, buf, TRUE);
1332     break;
1333
1334   case TS_RELATIVE:
1335     if (fd->flags.has_ts) {
1336       nstime_t del_rel_ts;
1337
1338       frame_delta_abs_time(epan, fd, fd->frame_ref_num, &del_rel_ts);
1339
1340       switch (timestamp_get_seconds_type()) {
1341       case TS_SECONDS_DEFAULT:
1342         set_time_seconds(&del_rel_ts, buf);
1343         break;
1344       case TS_SECONDS_HOUR_MIN_SEC:
1345         set_time_seconds(&del_rel_ts, buf);
1346         break;
1347       default:
1348         g_assert_not_reached();
1349       }
1350     } else {
1351       buf[0] = '\0';
1352     }
1353     break;
1354
1355   case TS_DELTA:
1356     if (fd->flags.has_ts) {
1357       nstime_t del_cap_ts;
1358
1359       frame_delta_abs_time(epan, fd, fd->num - 1, &del_cap_ts);
1360
1361       switch (timestamp_get_seconds_type()) {
1362       case TS_SECONDS_DEFAULT:
1363         set_time_seconds(&del_cap_ts, buf);
1364         break;
1365       case TS_SECONDS_HOUR_MIN_SEC:
1366         set_time_hour_min_sec(&del_cap_ts, buf);
1367         break;
1368       default:
1369         g_assert_not_reached();
1370       }
1371     } else {
1372       buf[0] = '\0';
1373     }
1374     break;
1375
1376   case TS_DELTA_DIS:
1377     if (fd->flags.has_ts) {
1378       nstime_t del_dis_ts;
1379
1380       frame_delta_abs_time(epan, fd, fd->prev_dis_num, &del_dis_ts);
1381
1382       switch (timestamp_get_seconds_type()) {
1383       case TS_SECONDS_DEFAULT:
1384         set_time_seconds(&del_dis_ts, buf);
1385         break;
1386       case TS_SECONDS_HOUR_MIN_SEC:
1387         set_time_hour_min_sec(&del_dis_ts, buf);
1388         break;
1389       default:
1390         g_assert_not_reached();
1391       }
1392     } else {
1393       buf[0] = '\0';
1394     }
1395     break;
1396
1397   case TS_EPOCH:
1398     set_epoch_time(fd, buf);
1399     break;
1400
1401   case TS_UTC:
1402     set_abs_time(fd, buf, FALSE);
1403     break;
1404
1405   case TS_UTC_WITH_YMD:
1406     set_abs_ymd_time(fd, buf, FALSE);
1407     break;
1408
1409   case TS_UTC_WITH_YDOY:
1410     set_abs_ydoy_time(fd, buf, FALSE);
1411     break;
1412
1413   case TS_NOT_SET:
1414     /* code is missing for this case, but I don't know which [jmayer20051219] */
1415     g_assert(FALSE);
1416     break;
1417   }
1418 }
1419
1420 static void
1421 col_set_cls_time(const frame_data *fd, column_info *cinfo, const gint col)
1422 {
1423   switch (timestamp_get_type()) {
1424   case TS_ABSOLUTE:
1425     col_set_abs_time(fd, cinfo, col);
1426     break;
1427
1428   case TS_ABSOLUTE_WITH_YMD:
1429     col_set_abs_ymd_time(fd, cinfo, col);
1430     break;
1431
1432   case TS_ABSOLUTE_WITH_YDOY:
1433     col_set_abs_ydoy_time(fd, cinfo, col);
1434     break;
1435
1436   case TS_RELATIVE:
1437     col_set_rel_time(fd, cinfo, col);
1438     break;
1439
1440   case TS_DELTA:
1441     col_set_delta_time(fd, cinfo, col);
1442     break;
1443
1444   case TS_DELTA_DIS:
1445     col_set_delta_time_dis(fd, cinfo, col);
1446     break;
1447
1448   case TS_EPOCH:
1449     col_set_epoch_time(fd, cinfo, col);
1450     break;
1451
1452   case TS_UTC:
1453     col_set_utc_time(fd, cinfo, col);
1454     break;
1455
1456   case TS_UTC_WITH_YMD:
1457     col_set_utc_ymd_time(fd, cinfo, col);
1458     break;
1459
1460   case TS_UTC_WITH_YDOY:
1461     col_set_utc_ydoy_time(fd, cinfo, col);
1462     break;
1463
1464   case TS_NOT_SET:
1465     /* code is missing for this case, but I don't know which [jmayer20051219] */
1466     g_assert_not_reached();
1467     break;
1468   }
1469 }
1470
1471 /* Set the format of the variable time format. */
1472 static void
1473 col_set_fmt_time(const frame_data *fd, column_info *cinfo, const gint fmt, const gint col)
1474 {
1475   COL_CHECK_REF_TIME(fd, cinfo->col_buf[col]);
1476
1477   switch (fmt) {
1478   case COL_CLS_TIME:
1479     col_set_cls_time(fd, cinfo, col);
1480     break;
1481
1482   case COL_ABS_TIME:
1483     col_set_abs_time(fd, cinfo, col);
1484     break;
1485
1486   case COL_ABS_YMD_TIME:
1487     col_set_abs_ymd_time(fd, cinfo, col);
1488     break;
1489
1490   case COL_ABS_YDOY_TIME:
1491     col_set_abs_ydoy_time(fd, cinfo, col);
1492     break;
1493
1494   case COL_REL_TIME:
1495     col_set_rel_time(fd, cinfo, col);
1496     break;
1497
1498   case COL_DELTA_TIME:
1499     col_set_delta_time(fd, cinfo, col);
1500     break;
1501
1502   case COL_DELTA_TIME_DIS:
1503     col_set_delta_time_dis(fd, cinfo, col);
1504     break;
1505
1506   case COL_UTC_TIME:
1507     col_set_utc_time(fd, cinfo, col);
1508     break;
1509
1510   case COL_UTC_YMD_TIME:
1511     col_set_utc_ymd_time(fd, cinfo, col);
1512     break;
1513
1514   case COL_UTC_YDOY_TIME:
1515     col_set_utc_ydoy_time(fd, cinfo, col);
1516     break;
1517
1518   default:
1519     g_assert_not_reached();
1520     break;
1521   }
1522 }
1523
1524 /* --------------------------- */
1525 /* Set the given (relative) time to a column element.
1526  *
1527  * Used by multiple dissectors to set the time in the column
1528  * COL_DELTA_CONV_TIME
1529  *
1530  * @param cinfo         the current packet row
1531  * @param el            the column to use, e.g. COL_INFO
1532  * @param ts            the time to set in the column
1533  * @param fieldname     the fieldname to use for creating a filter (when
1534  *                        applying/preparing/copying as filter)
1535  */
1536 void
1537 col_set_time(column_info *cinfo, const gint el, const nstime_t *ts, const char *fieldname)
1538 {
1539   int col;
1540
1541   if (!CHECK_COL(cinfo, el))
1542     return;
1543
1544   /** @todo TODO: We don't respect fd->flags.ref_time (no way to access 'fd')
1545   COL_CHECK_REF_TIME(fd, buf);
1546   */
1547
1548   for (col = cinfo->col_first[el]; col <= cinfo->col_last[el]; col++) {
1549     if (cinfo->fmt_matx[col][el]) {
1550       switch (timestamp_get_precision()) {
1551       case TS_PREC_FIXED_SEC:
1552       case TS_PREC_AUTO_SEC:
1553         display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
1554           (gint32) ts->secs, ts->nsecs / 1000000000, TO_STR_TIME_RES_T_SECS);
1555         break;
1556       case TS_PREC_FIXED_DSEC:
1557       case TS_PREC_AUTO_DSEC:
1558         display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
1559           (gint32) ts->secs, ts->nsecs / 100000000, TO_STR_TIME_RES_T_DSECS);
1560         break;
1561       case TS_PREC_FIXED_CSEC:
1562       case TS_PREC_AUTO_CSEC:
1563         display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
1564           (gint32) ts->secs, ts->nsecs / 10000000, TO_STR_TIME_RES_T_CSECS);
1565         break;
1566       case TS_PREC_FIXED_MSEC:
1567       case TS_PREC_AUTO_MSEC:
1568         display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
1569           (gint32) ts->secs, ts->nsecs / 1000000, TO_STR_TIME_RES_T_MSECS);
1570         break;
1571       case TS_PREC_FIXED_USEC:
1572       case TS_PREC_AUTO_USEC:
1573         display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
1574           (gint32) ts->secs, ts->nsecs / 1000, TO_STR_TIME_RES_T_USECS);
1575         break;
1576       case TS_PREC_FIXED_NSEC:
1577       case TS_PREC_AUTO_NSEC:
1578         display_signed_time(cinfo->col_buf[col], COL_MAX_LEN,
1579           (gint32) ts->secs, ts->nsecs, TO_STR_TIME_RES_T_NSECS);
1580         break;
1581       default:
1582         g_assert_not_reached();
1583       }
1584       cinfo->col_data[col] = cinfo->col_buf[col];
1585       cinfo->col_expr.col_expr[col] = fieldname;
1586       g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->col_buf[col],COL_MAX_LEN);
1587     }
1588   }
1589 }
1590
1591 static void
1592 col_set_addr(packet_info *pinfo, const int col, const address *addr, const gboolean is_src,
1593              const gboolean fill_col_exprs, const gboolean res)
1594 {
1595   if (addr->type == AT_NONE) {
1596     /* No address, nothing to do */
1597     return;
1598   }
1599
1600   if (res)
1601     pinfo->cinfo->col_data[col] = se_get_addr_name(addr);
1602   else
1603     pinfo->cinfo->col_data[col] = se_address_to_str(addr);
1604
1605   if (!fill_col_exprs)
1606     return;
1607
1608   switch (addr->type) {
1609   case AT_AX25:
1610     if (is_src)
1611       pinfo->cinfo->col_expr.col_expr[col] = "ax25.src";
1612     else
1613       pinfo->cinfo->col_expr.col_expr[col] = "ax25.dst";
1614     g_strlcpy(pinfo->cinfo->col_expr.col_expr_val[col], ax25_to_str((const guint8 *)addr->data), COL_MAX_LEN);
1615     break;
1616
1617   case AT_ETHER:
1618     if (is_src)
1619       pinfo->cinfo->col_expr.col_expr[col] = "eth.src";
1620     else
1621       pinfo->cinfo->col_expr.col_expr[col] = "eth.dst";
1622     address_to_str_buf(addr, pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN);
1623     break;
1624
1625   case AT_IPv4:
1626     if (is_src)
1627       pinfo->cinfo->col_expr.col_expr[col] = "ip.src";
1628     else
1629       pinfo->cinfo->col_expr.col_expr[col] = "ip.dst";
1630     ip_to_str_buf((const guint8 *)addr->data, pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN);
1631     break;
1632
1633   case AT_IPv6:
1634     if (is_src)
1635       pinfo->cinfo->col_expr.col_expr[col] = "ipv6.src";
1636     else
1637       pinfo->cinfo->col_expr.col_expr[col] = "ipv6.dst";
1638     address_to_str_buf(addr, pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN);
1639     break;
1640
1641   case AT_ATALK:
1642     if (is_src)
1643       pinfo->cinfo->col_expr.col_expr[col] = "ddp.src";
1644     else
1645       pinfo->cinfo->col_expr.col_expr[col] = "ddp.dst";
1646     g_strlcpy(pinfo->cinfo->col_expr.col_expr_val[col], pinfo->cinfo->col_buf[col], COL_MAX_LEN);
1647     break;
1648
1649   case AT_ARCNET:
1650     if (is_src)
1651       pinfo->cinfo->col_expr.col_expr[col] = "arcnet.src";
1652     else
1653       pinfo->cinfo->col_expr.col_expr[col] = "arcnet.dst";
1654     g_strlcpy(pinfo->cinfo->col_expr.col_expr_val[col], pinfo->cinfo->col_buf[col], COL_MAX_LEN);
1655     break;
1656
1657   case AT_URI:
1658     if (is_src)
1659       pinfo->cinfo->col_expr.col_expr[col] = "uri.src";
1660     else
1661       pinfo->cinfo->col_expr.col_expr[col] = "uri.dst";
1662     address_to_str_buf(addr, pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN);
1663     break;
1664
1665   default:
1666     break;
1667   }
1668
1669   /* Some addresses (e.g. ieee80211) use a standard format like AT_ETHER but
1670    * don't use the same hf_ value (and thus don't use the same filter string).
1671    * Such address can use the SET_ADDRESS_HF macro to pass in the specific hf_
1672    * value they use. If they did so, we overwrite the default filter string
1673    * with their specific one here. See bug #7728 for further discussion.
1674    * https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=7728 */
1675   if (addr->hf != -1) {
1676     pinfo->cinfo->col_expr.col_expr[col] = proto_registrar_get_nth(addr->hf)->abbrev;
1677   }
1678
1679 }
1680
1681 /* ------------------------ */
1682 static void
1683 col_set_port(packet_info *pinfo, const int col, const gboolean is_res, const gboolean is_src, const gboolean fill_col_exprs _U_)
1684 {
1685   guint32 port;
1686
1687   if (is_src)
1688     port = pinfo->srcport;
1689   else
1690     port = pinfo->destport;
1691
1692   /* TODO: Use fill_col_exprs */
1693
1694   switch (pinfo->ptype) {
1695   case PT_SCTP:
1696     if (is_res)
1697       g_strlcpy(pinfo->cinfo->col_buf[col], get_sctp_port(port), COL_MAX_LEN);
1698     else
1699       guint32_to_str_buf(port, pinfo->cinfo->col_buf[col], COL_MAX_LEN);
1700     break;
1701
1702   case PT_TCP:
1703     guint32_to_str_buf(port, pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN);
1704     if (is_res)
1705       g_strlcpy(pinfo->cinfo->col_buf[col], get_tcp_port(port), COL_MAX_LEN);
1706     else
1707       g_strlcpy(pinfo->cinfo->col_buf[col], pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN);
1708     if (is_src)
1709       pinfo->cinfo->col_expr.col_expr[col] = "tcp.srcport";
1710     else
1711       pinfo->cinfo->col_expr.col_expr[col] = "tcp.dstport";
1712     break;
1713
1714   case PT_UDP:
1715     guint32_to_str_buf(port, pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN);
1716     if (is_res)
1717       g_strlcpy(pinfo->cinfo->col_buf[col], get_udp_port(port), COL_MAX_LEN);
1718     else
1719       g_strlcpy(pinfo->cinfo->col_buf[col], pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN);
1720     if (is_src)
1721       pinfo->cinfo->col_expr.col_expr[col] = "udp.srcport";
1722     else
1723       pinfo->cinfo->col_expr.col_expr[col] = "udp.dstport";
1724     break;
1725
1726   case PT_DDP:
1727     if (is_src)
1728       pinfo->cinfo->col_expr.col_expr[col] = "ddp.src_socket";
1729     else
1730       pinfo->cinfo->col_expr.col_expr[col] = "ddp.dst_socket";
1731     guint32_to_str_buf(port, pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN);
1732     g_strlcpy(pinfo->cinfo->col_buf[col], pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN);
1733     break;
1734
1735   case PT_IPX:
1736     /* XXX - resolve IPX socket numbers */
1737     g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "0x%04x", port);
1738     g_strlcpy(pinfo->cinfo->col_expr.col_expr_val[col], pinfo->cinfo->col_buf[col],COL_MAX_LEN);
1739     if (is_src)
1740       pinfo->cinfo->col_expr.col_expr[col] = "ipx.src.socket";
1741     else
1742       pinfo->cinfo->col_expr.col_expr[col] = "ipx.dst.socket";
1743     break;
1744
1745   case PT_IDP:
1746     /* XXX - resolve IDP socket numbers */
1747     g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "0x%04x", port);
1748     g_strlcpy(pinfo->cinfo->col_expr.col_expr_val[col], pinfo->cinfo->col_buf[col],COL_MAX_LEN);
1749     if (is_src)
1750       pinfo->cinfo->col_expr.col_expr[col] = "idp.src.socket";
1751     else
1752       pinfo->cinfo->col_expr.col_expr[col] = "idp.dst.socket";
1753     break;
1754
1755   case PT_USB:
1756     /* XXX - resolve USB endpoint numbers */
1757     g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "0x%08x", port);
1758     g_strlcpy(pinfo->cinfo->col_expr.col_expr_val[col], pinfo->cinfo->col_buf[col],COL_MAX_LEN);
1759     if (is_src)
1760       pinfo->cinfo->col_expr.col_expr[col] = "usb.src.endpoint";
1761     else
1762       pinfo->cinfo->col_expr.col_expr[col] = "usb.dst.endpoint";
1763     break;
1764
1765   default:
1766     break;
1767   }
1768   pinfo->cinfo->col_data[col] = pinfo->cinfo->col_buf[col];
1769 }
1770
1771 gboolean
1772 col_based_on_frame_data(column_info *cinfo, const gint col)
1773 {
1774   g_assert(cinfo);
1775   g_assert(col < cinfo->num_cols);
1776
1777   switch (cinfo->col_fmt[col]) {
1778   case COL_NUMBER:
1779   case COL_CLS_TIME:
1780   case COL_ABS_TIME:
1781   case COL_ABS_YMD_TIME:
1782   case COL_ABS_YDOY_TIME:
1783   case COL_UTC_TIME:
1784   case COL_UTC_YMD_TIME:
1785   case COL_UTC_YDOY_TIME:
1786   case COL_REL_TIME:
1787   case COL_DELTA_TIME:
1788   case COL_DELTA_TIME_DIS:
1789   case COL_PACKET_LENGTH:
1790   case COL_CUMULATIVE_BYTES:
1791     return TRUE;
1792
1793   default:
1794     return FALSE;
1795   }
1796 }
1797
1798 void
1799 col_fill_in_frame_data(const frame_data *fd, column_info *cinfo, const gint col, const gboolean fill_col_exprs)
1800 {
1801   switch (cinfo->col_fmt[col]) {
1802   case COL_NUMBER:
1803     guint32_to_str_buf(fd->num, cinfo->col_buf[col], COL_MAX_LEN);
1804     cinfo->col_data[col] = cinfo->col_buf[col];
1805     break;
1806
1807   case COL_CLS_TIME:
1808   case COL_ABS_TIME:
1809   case COL_ABS_YMD_TIME:
1810   case COL_ABS_YDOY_TIME:
1811   case COL_UTC_TIME:
1812   case COL_UTC_YMD_TIME:
1813   case COL_UTC_YDOY_TIME:
1814   case COL_REL_TIME:
1815   case COL_DELTA_TIME:
1816   case COL_DELTA_TIME_DIS:
1817     /* TODO: Pass on fill_col_exprs */
1818     col_set_fmt_time(fd, cinfo, cinfo->col_fmt[col], col);
1819     break;
1820
1821   case COL_PACKET_LENGTH:
1822     guint32_to_str_buf(fd->pkt_len, cinfo->col_buf[col], COL_MAX_LEN);
1823     cinfo->col_data[col] = cinfo->col_buf[col];
1824     break;
1825
1826   case COL_CUMULATIVE_BYTES:
1827     guint32_to_str_buf(fd->cum_bytes, cinfo->col_buf[col], COL_MAX_LEN);
1828     cinfo->col_data[col] = cinfo->col_buf[col];
1829     break;
1830
1831   default:
1832     break;
1833   }
1834
1835   if (!fill_col_exprs)
1836     return;
1837
1838   switch (cinfo->col_fmt[col]) {
1839   case COL_NUMBER:
1840     cinfo->col_expr.col_expr[col] = "frame.number";
1841     g_strlcpy(cinfo->col_expr.col_expr_val[col], cinfo->col_buf[col], COL_MAX_LEN);
1842     break;
1843
1844   case COL_CLS_TIME:
1845   case COL_ABS_TIME:
1846   case COL_ABS_YMD_TIME:
1847   case COL_ABS_YDOY_TIME:
1848   case COL_UTC_TIME:
1849   case COL_UTC_YMD_TIME:
1850   case COL_UTC_YDOY_TIME:
1851   case COL_REL_TIME:
1852   case COL_DELTA_TIME:
1853   case COL_DELTA_TIME_DIS:
1854     /* Already handled above */
1855     break;
1856
1857   case COL_PACKET_LENGTH:
1858     cinfo->col_expr.col_expr[col] = "frame.len";
1859     g_strlcpy(cinfo->col_expr.col_expr_val[col], cinfo->col_buf[col], COL_MAX_LEN);
1860     break;
1861
1862   case COL_CUMULATIVE_BYTES:
1863     break;
1864
1865   default:
1866     break;
1867   }
1868 }
1869
1870 void
1871 col_fill_in(packet_info *pinfo, const gboolean fill_col_exprs, const gboolean fill_fd_colums)
1872 {
1873   int i;
1874
1875   if (!pinfo->cinfo)
1876     return;
1877
1878   for (i = 0; i < pinfo->cinfo->num_cols; i++) {
1879     if (col_based_on_frame_data(pinfo->cinfo, i)) {
1880       if (fill_fd_colums)
1881         col_fill_in_frame_data(pinfo->fd, pinfo->cinfo, i, fill_col_exprs);
1882     } else {
1883       switch (pinfo->cinfo->col_fmt[i]) {
1884       case COL_DEF_SRC:
1885       case COL_RES_SRC:   /* COL_DEF_SRC is currently just like COL_RES_SRC */
1886         col_set_addr(pinfo, i, &pinfo->src, TRUE, fill_col_exprs, TRUE);
1887         break;
1888
1889       case COL_UNRES_SRC:
1890         col_set_addr(pinfo, i, &pinfo->src, TRUE, fill_col_exprs, FALSE);
1891         break;
1892
1893       case COL_DEF_DL_SRC:
1894       case COL_RES_DL_SRC:
1895         col_set_addr(pinfo, i, &pinfo->dl_src, TRUE, fill_col_exprs, TRUE);
1896         break;
1897
1898       case COL_UNRES_DL_SRC:
1899         col_set_addr(pinfo, i, &pinfo->dl_src, TRUE, fill_col_exprs, FALSE);
1900         break;
1901
1902       case COL_DEF_NET_SRC:
1903       case COL_RES_NET_SRC:
1904         col_set_addr(pinfo, i, &pinfo->net_src, TRUE, fill_col_exprs, TRUE);
1905         break;
1906
1907       case COL_UNRES_NET_SRC:
1908         col_set_addr(pinfo, i, &pinfo->net_src, TRUE, fill_col_exprs, FALSE);
1909         break;
1910
1911       case COL_DEF_DST:
1912       case COL_RES_DST:   /* COL_DEF_DST is currently just like COL_RES_DST */
1913         col_set_addr(pinfo, i, &pinfo->dst, FALSE, fill_col_exprs, TRUE);
1914         break;
1915
1916       case COL_UNRES_DST:
1917         col_set_addr(pinfo, i, &pinfo->dst, FALSE, fill_col_exprs, FALSE);
1918         break;
1919
1920       case COL_DEF_DL_DST:
1921       case COL_RES_DL_DST:
1922         col_set_addr(pinfo, i, &pinfo->dl_dst, FALSE, fill_col_exprs, TRUE);
1923         break;
1924
1925       case COL_UNRES_DL_DST:
1926         col_set_addr(pinfo, i, &pinfo->dl_dst, FALSE, fill_col_exprs, FALSE);
1927         break;
1928
1929       case COL_DEF_NET_DST:
1930       case COL_RES_NET_DST:
1931         col_set_addr(pinfo, i, &pinfo->net_dst, FALSE, fill_col_exprs, TRUE);
1932         break;
1933
1934       case COL_UNRES_NET_DST:
1935         col_set_addr(pinfo, i, &pinfo->net_dst, FALSE, fill_col_exprs, FALSE);
1936         break;
1937
1938       case COL_DEF_SRC_PORT:
1939       case COL_RES_SRC_PORT:  /* COL_DEF_SRC_PORT is currently just like COL_RES_SRC_PORT */
1940         col_set_port(pinfo, i, TRUE, TRUE, fill_col_exprs);
1941         break;
1942
1943       case COL_UNRES_SRC_PORT:
1944         col_set_port(pinfo, i, FALSE, TRUE, fill_col_exprs);
1945         break;
1946
1947       case COL_DEF_DST_PORT:
1948       case COL_RES_DST_PORT:  /* COL_DEF_DST_PORT is currently just like COL_RES_DST_PORT */
1949         col_set_port(pinfo, i, TRUE, FALSE, fill_col_exprs);
1950         break;
1951
1952       case COL_UNRES_DST_PORT:
1953         col_set_port(pinfo, i, FALSE, FALSE, fill_col_exprs);
1954         break;
1955
1956       case NUM_COL_FMTS:  /* keep compiler happy - shouldn't get here */
1957         g_assert_not_reached();
1958         break;
1959       default:
1960         if (pinfo->cinfo->col_fmt[i] >= NUM_COL_FMTS) {
1961           g_assert_not_reached();
1962         }
1963         /*
1964          * Formatting handled by col_custom_set_edt() (COL_CUSTOM), expert.c
1965          * (COL_EXPERT), or individual dissectors.
1966          */
1967         break;
1968       }
1969     }
1970   }
1971 }
1972
1973 /*
1974  * Fill in columns if we got an error reading the packet.
1975  * We set most columns to "???", fill in columns that don't need data read
1976  * from the file, and set the Info column to an error message.
1977  */
1978 void
1979 col_fill_in_error(column_info *cinfo, frame_data *fdata, const gboolean fill_col_exprs, const gboolean fill_fd_colums)
1980 {
1981   int i;
1982
1983   if (!cinfo)
1984     return;
1985
1986   for (i = 0; i < cinfo->num_cols; i++) {
1987     if (col_based_on_frame_data(cinfo, i)) {
1988       if (fill_fd_colums)
1989         col_fill_in_frame_data(fdata, cinfo, i, fill_col_exprs);
1990     } else if (cinfo->col_fmt[i] == COL_INFO) {
1991       /* XXX - say more than this */
1992       cinfo->col_data[i] = "Read error";
1993     } else {
1994       if (cinfo->col_fmt[i] >= NUM_COL_FMTS) {
1995         g_assert_not_reached();
1996       }
1997       /*
1998        * No dissection was done, and these columns are set as the
1999        * result of the dissection, so....
2000        */
2001       cinfo->col_data[i] = "???";
2002       break;
2003     }
2004   }
2005 }
2006
2007 /*
2008  * Editor modelines
2009  *
2010  * Local Variables:
2011  * c-basic-offset: 2
2012  * tab-width: 8
2013  * indent-tabs-mode: nil
2014  * End:
2015  *
2016  * ex: set shiftwidth=2 tabstop=8 expandtab:
2017  * :indentSize=2:tabSize=8:noTabs=true:
2018  */