2 * Packet list display utilities
3 * Copied from gtk/packet_list.c
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
16 #include "packet_list_utils.h"
18 #include <epan/column.h>
21 right_justify_column (int col
, capture_file
*cf
)
23 header_field_info
*hfi
;
24 bool right_justify
= false;
25 unsigned num_fields
, ii
;
26 col_custom_t
*col_custom
;
27 unsigned right_justify_count
= 0;
29 if (!cf
) return false;
31 switch (cf
->cinfo
.columns
[col
].col_fmt
) {
35 case COL_PACKET_LENGTH
:
36 case COL_CUMULATIVE_BYTES
:
38 case COL_UNRES_DST_PORT
:
39 case COL_UNRES_SRC_PORT
:
40 case COL_DEF_DST_PORT
:
41 case COL_DEF_SRC_PORT
:
43 case COL_DELTA_TIME_DIS
:
48 num_fields
= g_slist_length(cf
->cinfo
.columns
[col
].col_custom_fields_ids
);
49 for (ii
= 0; ii
< num_fields
; ii
++) {
50 col_custom
= (col_custom_t
*) g_slist_nth_data(cf
->cinfo
.columns
[col
].col_custom_fields_ids
, ii
);
51 if (col_custom
->field_id
== 0) {
52 /* XXX - If there were some way to check the compiled dfilter's
53 * expected return type, we could use that.
57 hfi
= proto_registrar_get_nth(col_custom
->field_id
);
59 /* Check if this is a valid field and we have no strings lookup table */
60 /* XXX - We should check every hfi with the same abbreviation */
61 if ((hfi
!= NULL
) && (get_column_display_format(col
) != COLUMN_DISPLAY_DETAILS
) &&
62 ((hfi
->strings
== NULL
) || get_column_display_format(col
) == COLUMN_DISPLAY_VALUES
))
64 /* Check for bool, framenum, double, float, relative time and decimal/octal integer types */
65 if ((hfi
->type
== FT_BOOLEAN
) || (hfi
->type
== FT_FRAMENUM
) || (hfi
->type
== FT_DOUBLE
) ||
66 (hfi
->type
== FT_FLOAT
) || (hfi
->type
== FT_RELATIVE_TIME
) ||
67 (((FIELD_DISPLAY(hfi
->display
) == BASE_DEC
) || (FIELD_DISPLAY(hfi
->display
) == BASE_OCT
)) &&
68 (FT_IS_INT(hfi
->type
) || FT_IS_UINT(hfi
->type
))))
70 right_justify_count
++;
75 if ((num_fields
> 0) && (right_justify_count
== num_fields
)) {
76 /* All custom fields must meet the right-justify criteria */
89 display_column_strings (int col
, capture_file
*cf
)
91 header_field_info
*hfi
;
93 unsigned num_fields
, ii
;
94 col_custom_t
*col_custom
;
96 if (!cf
) return false;
98 switch (cf
->cinfo
.columns
[col
].col_fmt
) {
101 num_fields
= g_slist_length(cf
->cinfo
.columns
[col
].col_custom_fields_ids
);
102 for (ii
= 0; ii
< num_fields
; ii
++) {
103 col_custom
= (col_custom_t
*) g_slist_nth_data(cf
->cinfo
.columns
[col
].col_custom_fields_ids
, ii
);
104 if (col_custom
->field_id
== 0) {
105 /* XXX - A "resolved" string might be conceivable for certain
106 * expressions, but would require being able to know which
107 * hfinfo produced each value, if there are multiple hfi with
108 * the same abbreviation.
112 hfi
= proto_registrar_get_nth(col_custom
->field_id
);
113 /* XXX - We should check every hfi with the same abbreviation */
115 /* Check if we have an OID, a (potentially) resolvable network
116 * address, a Boolean, or a strings table with integer values */
117 /* XXX: Should this checkbox be disabled if the Name Resolution
118 * preference for a given type is off?
120 if ((hfi
->type
== FT_OID
) || (hfi
->type
== FT_REL_OID
) || (hfi
->type
== FT_ETHER
) || (hfi
->type
== FT_BYTES
) || (hfi
->type
== FT_IPv4
) || (hfi
->type
== FT_IPv6
) || (hfi
->type
== FT_FCWWN
) || (hfi
->type
== FT_BOOLEAN
) ||
121 ((hfi
->strings
!= NULL
) &&
122 (FT_IS_INT(hfi
->type
) || FT_IS_UINT(hfi
->type
))))
138 display_column_details (int col
, capture_file
*cf
)
140 header_field_info
*hfi
;
141 bool resolve
= false;
142 unsigned num_fields
, ii
;
143 col_custom_t
*col_custom
;
145 if (!cf
) return false;
147 switch (cf
->cinfo
.columns
[col
].col_fmt
) {
150 num_fields
= g_slist_length(cf
->cinfo
.columns
[col
].col_custom_fields_ids
);
151 for (ii
= 0; ii
< num_fields
; ii
++) {
152 col_custom
= (col_custom_t
*) g_slist_nth_data(cf
->cinfo
.columns
[col
].col_custom_fields_ids
, ii
);
153 if (col_custom
->field_id
== 0) {
154 /* XXX - A "resolved" string might be conceivable for certain
155 * expressions, but would require being able to know which
156 * hfinfo produced each value, if there are multiple hfi with
157 * the same abbreviation.
162 hfi
= proto_registrar_get_nth(col_custom
->field_id
);
163 if (hfi
&& !(hfi
->display
& BASE_NO_DISPLAY_VALUE
)) {