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+*/
10 /* This module provides Protocol Column Info tap for tshark */
18 #include "epan/epan_dissect.h"
19 #include "epan/column-utils.h"
21 #include <epan/stat_tap_ui.h>
23 void register_tap_listener_protocolinfo(void);
25 typedef struct _pci_t {
32 protocolinfo_packet(void *prs, packet_info *pinfo, epan_dissect_t *edt, const void *dummy _U_)
34 pci_t *rs = (pci_t *)prs;
40 * XXX - there needs to be a way for "protocolinfo_init()" to
41 * find out whether the columns are being generated and, if not,
42 * to report an error and exit, as the whole point of this tap
43 * is to modify the columns, and if the columns aren't being
44 * displayed, that makes this tap somewhat pointless.
46 * To prevent a crash, we check whether INFO column is writable
47 * and, if not, we report that error and exit.
49 if (!col_get_writable(pinfo->cinfo, COL_INFO)) {
50 fprintf(stderr, "tshark: the proto,colinfo tap doesn't work if the INFO column isn't being printed.\n");
53 gp = proto_get_finfo_ptr_array(edt->tree, rs->hf_index);
58 for (i=0; i<gp->len; i++) {
59 str = (char *)proto_construct_match_selected_string((field_info *)gp->pdata[i], NULL);
61 col_append_fstr(pinfo->cinfo, COL_INFO, " %s", str);
71 protocolinfo_init(const char *opt_arg, void *userdata _U_)
74 const char *field = NULL;
75 const char *filter = NULL;
76 header_field_info *hfi;
77 GString *error_string;
79 if (!strncmp("proto,colinfo,", opt_arg, 14)) {
81 field = strchr(filter, ',');
83 field += 1; /* skip the ',' */
87 fprintf(stderr, "tshark: invalid \"-z proto,colinfo,<filter>,<field>\" argument\n");
91 hfi = proto_registrar_get_byname(field);
93 fprintf(stderr, "tshark: Field \"%s\" doesn't exist.\n", field);
98 rs->hf_index = hfi->id;
99 if ((field-filter) > 1) {
100 rs->filter = (char *)g_malloc(field-filter);
101 g_strlcpy(rs->filter, filter, (field-filter));
106 error_string = register_tap_listener("frame", rs, rs->filter, TL_REQUIRES_PROTO_TREE, NULL, protocolinfo_packet, NULL);
108 /* error, we failed to attach to the tap. complain and clean up */
109 fprintf(stderr, "tshark: Couldn't register proto,colinfo tap: %s\n",
111 g_string_free(error_string, TRUE);
119 static stat_tap_ui protocolinfo_ui = {
120 REGISTER_STAT_GROUP_GENERIC,
129 register_tap_listener_protocolinfo(void)
131 register_stat_tap_ui(&protocolinfo_ui, NULL);
135 * Editor modelines - http://www.wireshark.org/tools/modelines.html
140 * indent-tabs-mode: t
143 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
144 * :indentSize=8:tabSize=8:noTabs=false: