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
17 #include <epan/packet.h>
18 #include <epan/strutil.h>
20 /* Forward declarations */
21 void proto_register_acap(void);
22 void proto_reg_handoff_acap(void);
24 static dissector_handle_t acap_handle
;
26 static int proto_acap
;
28 static int hf_acap_request
;
29 static int hf_acap_request_data
;
30 static int hf_acap_request_tag
;
31 static int hf_acap_response
;
32 static int hf_acap_response_data
;
33 static int hf_acap_response_tag
;
36 static int ett_acap_reqresp
;
38 #define TCP_PORT_ACAP 674
41 dissect_acap(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data _U_
)
44 proto_tree
*acap_tree
, *reqresp_tree
;
45 proto_item
*ti
, *hidden_item
;
47 const unsigned char *line
;
51 const unsigned char *next_token
;
55 * If this should be a request or response, do this quick check to see if
56 * it begins with a string...
57 * Otherwise, looking for the end of line in a binary file can take a long time
58 * and this probably isn't ACAP
60 if (!g_ascii_isprint(tvb_get_uint8(tvb
, offset
))) {
64 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "ACAP");
67 * Find the end of the first line.
69 * Note that "tvb_find_line_end()" will return a value that is
70 * not longer than what's in the buffer, so the "tvb_get_ptr()"
71 * call won't throw an exception.
73 linelen
= tvb_find_line_end(tvb
, offset
, -1, &next_offset
, false);
74 line
= tvb_get_ptr(tvb
, offset
, linelen
);
76 if (pinfo
->match_uint
== pinfo
->destport
)
82 * Put the first line from the buffer into the summary
83 * (but leave out the line terminator).
85 col_add_fstr(pinfo
->cinfo
, COL_INFO
, "%s: %s",
86 is_request
? "Request" : "Response",
87 format_text(pinfo
->pool
, line
, linelen
));
90 ti
= proto_tree_add_item(tree
, proto_acap
, tvb
, offset
, -1,
92 acap_tree
= proto_item_add_subtree(ti
, ett_acap
);
95 hidden_item
= proto_tree_add_boolean(acap_tree
,
96 hf_acap_request
, tvb
, 0, 0, true);
97 proto_item_set_hidden(hidden_item
);
99 hidden_item
= proto_tree_add_boolean(acap_tree
,
100 hf_acap_response
, tvb
, 0, 0, true);
101 proto_item_set_hidden(hidden_item
);
105 * Put the line into the protocol tree.
107 ti
= proto_tree_add_format_text(acap_tree
, tvb
, offset
, next_offset
- offset
);
108 reqresp_tree
= proto_item_add_subtree(ti
, ett_acap_reqresp
);
111 * Show the first line as tags + requests or replies.
115 * Extract the first token, and, if there is a first
116 * token, add it as the request or reply tag.
118 tokenlen
= get_token_len(line
, line
+ linelen
, &next_token
);
121 proto_tree_add_string(reqresp_tree
, hf_acap_request_tag
, tvb
, offset
,
122 tokenlen
, format_text(pinfo
->pool
, line
, tokenlen
));
124 proto_tree_add_string(reqresp_tree
, hf_acap_response_tag
, tvb
, offset
,
125 tokenlen
, format_text(pinfo
->pool
, line
, tokenlen
));
127 offset
+= (int)(next_token
- line
);
128 linelen
-= (int)(next_token
- line
);
133 * Add the rest of the line as request or reply data.
137 proto_tree_add_string(reqresp_tree
, hf_acap_request_data
, tvb
, offset
,
138 linelen
, format_text(pinfo
->pool
, line
, linelen
));
140 proto_tree_add_string(reqresp_tree
, hf_acap_response_data
, tvb
, offset
,
141 linelen
, format_text(pinfo
->pool
, line
, linelen
));
146 * XXX - show the rest of the frame; this requires that
147 * we handle literals, quoted strings, continuation
150 * This involves a state machine, and attaching
151 * state information to the packets.
154 return tvb_captured_length(tvb
);
158 proto_register_acap(void)
160 static hf_register_info hf
[] = {
162 { "Response", "acap.response",
163 FT_BOOLEAN
, BASE_NONE
, NULL
, 0x0,
164 "true if ACAP response", HFILL
}
167 { "Request", "acap.request",
168 FT_BOOLEAN
, BASE_NONE
, NULL
, 0x0,
169 "true if ACAP request", HFILL
}
171 { &hf_acap_request_tag
,
172 { "Request Tag", "acap.request_tag",
173 FT_STRING
, BASE_NONE
, NULL
, 0x0,
176 { &hf_acap_response_tag
,
177 { "Response Tag", "acap.response_tag",
178 FT_STRING
, BASE_NONE
, NULL
, 0x0,
181 { &hf_acap_request_data
,
182 { "Request", "acap.request_data",
183 FT_STRING
, BASE_NONE
, NULL
, 0x0,
186 { &hf_acap_response_data
,
187 { "Response", "acap.response_data",
188 FT_STRING
, BASE_NONE
, NULL
, 0x0,
193 static int *ett
[] = {
198 proto_acap
= proto_register_protocol("Application Configuration Access Protocol",
200 proto_register_field_array(proto_acap
, hf
, array_length(hf
));
201 proto_register_subtree_array(ett
, array_length(ett
));
203 acap_handle
= register_dissector("acap", dissect_acap
, proto_acap
);
207 proto_reg_handoff_acap(void)
209 dissector_add_uint_with_preference("tcp.port", TCP_PORT_ACAP
, acap_handle
);
213 * Editor modelines - https://www.wireshark.org/tools/modelines.html
218 * indent-tabs-mode: nil
221 * vi: set shiftwidth=4 tabstop=8 expandtab:
222 * :indentSize=4:tabSize=8:noTabs=true: