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
11 /* This module provides Protocol Column Info tap for tshark */
19 #include "epan/epan_dissect.h"
20 #include "epan/column-utils.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
{
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
;
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.");
58 gp
= proto_get_finfo_ptr_array(edt
->tree
, rs
->hf_index
);
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
);
66 col_append_fstr(pinfo
->cinfo
, COL_INFO
, " %s", str
);
70 return TAP_PACKET_DONT_REDRAW
;
76 protocolinfo_init(const char *opt_arg
, void *userdata _U_
)
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)) {
86 field
= strchr(filter
, ',');
88 field
+= 1; /* skip the ',' */
92 cmdarg_err("invalid \"-z proto,colinfo,<filter>,<field>\" argument");
96 hfi
= proto_registrar_get_byname(field
);
98 cmdarg_err("Field \"%s\" doesn't exist.", field
);
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
));
111 error_string
= register_tap_listener("frame", rs
, rs
->filter
, TL_REQUIRES_PROTO_TREE
, NULL
, protocolinfo_packet
, NULL
, NULL
);
113 /* error, we failed to attach to the tap. complain and clean up */
114 cmdarg_err("Couldn't register proto,colinfo tap: %s",
116 g_string_free(error_string
, TRUE
);
124 static stat_tap_ui protocolinfo_ui
= {
125 REGISTER_STAT_GROUP_GENERIC
,
134 register_tap_listener_protocolinfo(void)
136 register_stat_tap_ui(&protocolinfo_ui
, NULL
);
140 * Editor modelines - https://www.wireshark.org/tools/modelines.html
145 * indent-tabs-mode: t
148 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
149 * :indentSize=8:tabSize=8:noTabs=false: