Kerberos: add kerberos_inject_longterm_key() helper function
[wireshark-sm.git] / ui / packet_list_utils.c
blob1dc2a3aa47c4fb9b0552034aca49eb205828b53a
1 /* packet_list_utils.c
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
12 #include "config.h"
14 #include <stdint.h>
15 #include <stdbool.h>
16 #include "packet_list_utils.h"
18 #include <epan/column.h>
20 bool
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) {
33 case COL_NUMBER:
34 case COL_NUMBER_DIS:
35 case COL_PACKET_LENGTH:
36 case COL_CUMULATIVE_BYTES:
37 case COL_DSCP_VALUE:
38 case COL_UNRES_DST_PORT:
39 case COL_UNRES_SRC_PORT:
40 case COL_DEF_DST_PORT:
41 case COL_DEF_SRC_PORT:
42 case COL_DELTA_TIME:
43 case COL_DELTA_TIME_DIS:
44 right_justify = true;
45 break;
47 case COL_CUSTOM:
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.
55 return false;
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 */
77 right_justify = true;
79 break;
81 default:
82 break;
85 return right_justify;
88 bool
89 display_column_strings (int col, capture_file *cf)
91 header_field_info *hfi;
92 bool resolve = false;
93 unsigned num_fields, ii;
94 col_custom_t *col_custom;
96 if (!cf) return false;
98 switch (cf->cinfo.columns[col].col_fmt) {
100 case COL_CUSTOM:
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.
110 continue;
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))))
124 resolve = true;
125 break;
128 break;
130 default:
131 break;
134 return resolve;
137 bool
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) {
149 case COL_CUSTOM:
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.
159 continue;
162 hfi = proto_registrar_get_nth(col_custom->field_id);
163 if (hfi && !(hfi->display & BASE_NO_DISPLAY_VALUE)) {
164 resolve = true;
165 break;
168 break;
170 default:
171 break;
174 return resolve;