Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / ui / cli / tap-protocolinfo.c
blob14b57a29fea4516139ea1726b9754b5cdd4193f9
1 /* tap-protocolinfo.c
2 * protohierstat 2002 Ronnie Sahlberg
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * SPDX-License-Identifier: GPL-2.0-or-later
9 */
11 /* This module provides Protocol Column Info tap for tshark */
13 #include "config.h"
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <string.h>
19 #include "epan/epan_dissect.h"
20 #include "epan/column-utils.h"
21 #include <epan/tap.h>
22 #include <epan/stat_tap_ui.h>
24 #include <wsutil/cmdarg_err.h>
26 void register_tap_listener_protocolinfo(void);
28 typedef struct _pci_t {
29 char *filter;
30 int hf_index;
31 } pci_t;
34 static tap_packet_status
35 protocolinfo_packet(void *prs, packet_info *pinfo, epan_dissect_t *edt, const void *dummy _U_, tap_flags_t flags _U_)
37 pci_t *rs = (pci_t *)prs;
38 GPtrArray *gp;
39 unsigned i;
40 char *str;
43 * XXX - there needs to be a way for "protocolinfo_init()" to
44 * find out whether the columns are being generated and, if not,
45 * to report an error and exit, as the whole point of this tap
46 * is to modify the columns, and if the columns aren't being
47 * displayed, that makes this tap somewhat pointless.
49 * To prevent a crash, we check whether INFO column is writable
50 * and, if not, we report that error and exit.
52 * XXX - report the error and just return TAP_PACKET_FAILED?
54 if (!col_get_writable(pinfo->cinfo, COL_INFO)) {
55 cmdarg_err("the proto,colinfo tap doesn't work if the INFO column isn't being printed.");
56 exit(1);
58 gp = proto_get_finfo_ptr_array(edt->tree, rs->hf_index);
59 if (!gp) {
60 return TAP_PACKET_DONT_REDRAW;
63 for (i=0; i<gp->len; i++) {
64 str = (char *)proto_construct_match_selected_string((field_info *)gp->pdata[i], NULL);
65 if (str) {
66 col_append_fstr(pinfo->cinfo, COL_INFO, " %s", str);
67 wmem_free(NULL, str);
70 return TAP_PACKET_DONT_REDRAW;
75 static void
76 protocolinfo_init(const char *opt_arg, void *userdata _U_)
78 pci_t *rs;
79 const char *field = NULL;
80 const char *filter = NULL;
81 header_field_info *hfi;
82 GString *error_string;
84 if (!strncmp("proto,colinfo,", opt_arg, 14)) {
85 filter = opt_arg+14;
86 field = strchr(filter, ',');
87 if (field) {
88 field += 1; /* skip the ',' */
91 if (!field) {
92 cmdarg_err("invalid \"-z proto,colinfo,<filter>,<field>\" argument");
93 exit(1);
96 hfi = proto_registrar_get_byname(field);
97 if (!hfi) {
98 cmdarg_err("Field \"%s\" doesn't exist.", field);
99 exit(1);
102 rs = g_new(pci_t, 1);
103 rs->hf_index = hfi->id;
104 if ((field-filter) > 1) {
105 rs->filter = (char *)g_malloc(field-filter);
106 (void) g_strlcpy(rs->filter, filter, (field-filter));
107 } else {
108 rs->filter = NULL;
111 error_string = register_tap_listener("frame", rs, rs->filter, TL_REQUIRES_PROTO_TREE, NULL, protocolinfo_packet, NULL, NULL);
112 if (error_string) {
113 /* error, we failed to attach to the tap. complain and clean up */
114 cmdarg_err("Couldn't register proto,colinfo tap: %s",
115 error_string->str);
116 g_string_free(error_string, TRUE);
117 g_free(rs->filter);
118 g_free(rs);
120 exit(1);
124 static stat_tap_ui protocolinfo_ui = {
125 REGISTER_STAT_GROUP_GENERIC,
126 NULL,
127 "proto,colinfo",
128 protocolinfo_init,
130 NULL
133 void
134 register_tap_listener_protocolinfo(void)
136 register_stat_tap_ui(&protocolinfo_ui, NULL);
140 * Editor modelines - https://www.wireshark.org/tools/modelines.html
142 * Local variables:
143 * c-basic-offset: 8
144 * tab-width: 8
145 * indent-tabs-mode: t
146 * End:
148 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
149 * :indentSize=8:tabSize=8:noTabs=false: