2 * Routines for ACAP packet dissection
4 * Copyright 2003, Brad Hards <bradh@frogmouth.net>
5 * Heavily based in packet-imap.c, Copyright 1999, Richard Sharpe <rsharpe@ns.aus.com>
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * Copied from packet-imap.c
13 * SPDX-License-Identifier: GPL-2.0-or-later
16 #define NEW_PROTO_TREE_API
20 #include <epan/packet.h>
21 #include <epan/strutil.h>
23 /* Forward declarations */
24 void proto_register_acap(void);
25 void proto_reg_handoff_acap(void);
27 static dissector_handle_t acap_handle;
29 static header_field_info *hfi_acap = NULL;
31 #define HFI_ACAP HFI_INIT(proto_acap)
33 static header_field_info hfi_acap_response HFI_ACAP = {
34 "Response", "acap.response",
35 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
36 "TRUE if ACAP response", HFILL };
38 static header_field_info hfi_acap_request HFI_ACAP = {
39 "Request", "acap.request",
40 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
41 "TRUE if ACAP request", HFILL };
43 static header_field_info hfi_acap_request_tag HFI_ACAP = {
44 "Request Tag", "acap.request_tag",
45 FT_STRING, BASE_NONE, NULL, 0x0,
48 static header_field_info hfi_acap_response_tag HFI_ACAP = {
49 "Response Tag", "acap.response_tag",
50 FT_STRING, BASE_NONE, NULL, 0x0,
53 static header_field_info hfi_acap_request_data HFI_ACAP = {
54 "Request", "acap.request_data",
55 FT_STRING, BASE_NONE, NULL, 0x0,
58 static header_field_info hfi_acap_response_data HFI_ACAP = {
59 "Response", "acap.response_data",
60 FT_STRING, BASE_NONE, NULL, 0x0,
63 static gint ett_acap = -1;
64 static gint ett_acap_reqresp = -1;
66 #define TCP_PORT_ACAP 674
69 dissect_acap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
72 proto_tree *acap_tree, *reqresp_tree;
73 proto_item *ti, *hidden_item;
79 const guchar *next_token;
83 * If this should be a request or response, do this quick check to see if
84 * it begins with a string...
85 * Otherwise, looking for the end of line in a binary file can take a long time
86 * and this probably isn't ACAP
88 if (!g_ascii_isprint(tvb_get_guint8(tvb, offset))) {
92 col_set_str(pinfo->cinfo, COL_PROTOCOL, "ACAP");
95 * Find the end of the first line.
97 * Note that "tvb_find_line_end()" will return a value that is
98 * not longer than what's in the buffer, so the "tvb_get_ptr()"
99 * call won't throw an exception.
101 linelen = tvb_find_line_end(tvb, offset, -1, &next_offset, FALSE);
102 line = tvb_get_ptr(tvb, offset, linelen);
104 if (pinfo->match_uint == pinfo->destport)
110 * Put the first line from the buffer into the summary
111 * (but leave out the line terminator).
113 col_add_fstr(pinfo->cinfo, COL_INFO, "%s: %s",
114 is_request ? "Request" : "Response",
115 format_text(wmem_packet_scope(), line, linelen));
118 ti = proto_tree_add_item(tree, hfi_acap, tvb, offset, -1,
120 acap_tree = proto_item_add_subtree(ti, ett_acap);
123 hidden_item = proto_tree_add_boolean(acap_tree,
124 &hfi_acap_request, tvb, 0, 0, TRUE);
125 PROTO_ITEM_SET_HIDDEN(hidden_item);
127 hidden_item = proto_tree_add_boolean(acap_tree,
128 &hfi_acap_response, tvb, 0, 0, TRUE);
129 PROTO_ITEM_SET_HIDDEN(hidden_item);
133 * Put the line into the protocol tree.
135 ti = proto_tree_add_format_text(acap_tree, tvb, offset, next_offset - offset);
136 reqresp_tree = proto_item_add_subtree(ti, ett_acap_reqresp);
139 * Show the first line as tags + requests or replies.
143 * Extract the first token, and, if there is a first
144 * token, add it as the request or reply tag.
146 tokenlen = get_token_len(line, line + linelen, &next_token);
149 proto_tree_add_string(reqresp_tree, &hfi_acap_request_tag, tvb, offset,
150 tokenlen, format_text(wmem_packet_scope(), line, tokenlen));
152 proto_tree_add_string(reqresp_tree, &hfi_acap_response_tag, tvb, offset,
153 tokenlen, format_text(wmem_packet_scope(), line, tokenlen));
155 offset += (int)(next_token - line);
156 linelen -= (int)(next_token - line);
161 * Add the rest of the line as request or reply data.
165 proto_tree_add_string(reqresp_tree, &hfi_acap_request_data, tvb, offset,
166 linelen, format_text(wmem_packet_scope(), line, linelen));
168 proto_tree_add_string(reqresp_tree, &hfi_acap_response_data, tvb, offset,
169 linelen, format_text(wmem_packet_scope(), line, linelen));
174 * XXX - show the rest of the frame; this requires that
175 * we handle literals, quoted strings, continuation
178 * This involves a state machine, and attaching
179 * state information to the packets.
182 return tvb_captured_length(tvb);
186 proto_register_acap(void)
188 #ifndef HAVE_HFI_SECTION_INIT
189 static header_field_info *hfi[] = {
192 &hfi_acap_request_tag,
193 &hfi_acap_response_tag,
194 &hfi_acap_request_data,
195 &hfi_acap_response_data,
199 static gint *ett[] = {
206 proto_acap = proto_register_protocol("Application Configuration Access Protocol",
208 hfi_acap = proto_registrar_get_nth(proto_acap);
210 proto_register_fields(proto_acap, hfi, array_length(hfi));
211 proto_register_subtree_array(ett, array_length(ett));
213 acap_handle = create_dissector_handle(dissect_acap, proto_acap);
217 proto_reg_handoff_acap(void)
219 dissector_add_uint_with_preference("tcp.port", TCP_PORT_ACAP, acap_handle);
223 * Editor modelines - http://www.wireshark.org/tools/modelines.html
228 * indent-tabs-mode: nil
231 * vi: set shiftwidth=4 tabstop=8 expandtab:
232 * :indentSize=4:tabSize=8:noTabs=true: