2 * Routines for ICAP packet disassembly
5 * Srishylam Simharajan simha@netapp.com
9 * Wireshark - Network traffic analyzer
10 * By Gerald Combs <gerald@wireshark.org>
11 * Copyright 1998 Gerald Combs
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
36 #include <epan/packet.h>
37 #include <epan/strutil.h>
39 typedef enum _icap_type {
47 static int proto_icap = -1;
48 static int hf_icap_response = -1;
49 static int hf_icap_reqmod = -1;
50 static int hf_icap_respmod = -1;
51 static int hf_icap_options = -1;
52 static int hf_icap_other = -1;
54 static gint ett_icap = -1;
56 static dissector_handle_t data_handle;
58 #define TCP_PORT_ICAP 1344
59 static int is_icap_message(const guchar *data, int linelen, icap_type_t *type);
61 dissect_icap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
63 proto_tree *icap_tree = NULL;
64 proto_item *ti = NULL;
68 const guchar *linep, *lineend;
71 icap_type_t icap_type;
74 if (check_col(pinfo->cinfo, COL_PROTOCOL))
75 col_set_str(pinfo->cinfo, COL_PROTOCOL, "ICAP");
77 if (check_col(pinfo->cinfo, COL_INFO)) {
79 * Put the first line from the buffer into the summary
80 * if it's an ICAP header (but leave out the
82 * Otherwise, just call it a continuation.
84 * Note that "tvb_find_line_end()" will return a value that
85 * is not longer than what's in the buffer, so the
86 * "tvb_get_ptr()" call won't throw an exception.
88 linelen = tvb_find_line_end(tvb, offset, -1, &next_offset,
90 line = tvb_get_ptr(tvb, offset, linelen);
91 icap_type = ICAP_OTHER; /* type not known yet */
92 if (is_icap_message(line, linelen, &icap_type))
93 col_add_str(pinfo->cinfo, COL_INFO,
94 format_text(line, linelen));
96 col_set_str(pinfo->cinfo, COL_INFO, "Continuation");
100 ti = proto_tree_add_item(tree, proto_icap, tvb, offset, -1,
102 icap_tree = proto_item_add_subtree(ti, ett_icap);
106 * Process the packet data, a line at a time.
108 icap_type = ICAP_OTHER; /* type not known yet */
109 while (tvb_offset_exists(tvb, offset)) {
110 gboolean is_icap = FALSE;
111 gboolean loop_done = FALSE;
113 * Find the end of the line.
115 linelen = tvb_find_line_end(tvb, offset, -1, &next_offset,
119 * Get a buffer that refers to the line.
121 line = tvb_get_ptr(tvb, offset, linelen);
122 lineend = line + linelen;
127 if (is_icap_message(line, linelen, &icap_type)) {
133 * if it looks like a blank line, end of header perhaps?
141 * No. Does it look like a header?
145 while (linep < lineend && (!loop_done)) {
149 * This must be a CHAR to be part of a token; that
150 * means it must be ASCII.
154 break; /* not ASCII, thus not a CHAR */
158 * This mustn't be a CTL to be part of a token.
160 * XXX - what about leading LWS on continuation
165 break; /* CTL, not part of a header */
187 * It's a separator, so it's not part of a
188 * token, so it's not a field name for the
189 * beginning of a header.
191 * (We don't have to check for HT; that's
192 * already been ruled out by "iscntrl()".)
194 * XXX - what about ' '? HTTP's checks
203 * This ends the token; we consider this
213 * We don't consider this part of an ICAP message,
214 * so we don't display it.
215 * (Yeah, that means we don't display, say, a text/icap
216 * page, but you can get that from the data pane.)
222 proto_tree_add_text(icap_tree, tvb, offset,
223 next_offset - offset, "%s",
224 tvb_format_text(tvb, offset,
225 next_offset - offset)
228 offset = next_offset;
235 proto_tree_add_boolean_hidden(icap_tree,
236 hf_icap_options, tvb, 0, 0, 1);
240 proto_tree_add_boolean_hidden(icap_tree,
241 hf_icap_reqmod, tvb, 0, 0, 1);
245 proto_tree_add_boolean_hidden(icap_tree,
246 hf_icap_respmod, tvb, 0, 0, 1);
250 proto_tree_add_boolean_hidden(icap_tree,
251 hf_icap_response, tvb, 0, 0, 1);
260 datalen = tvb_length_remaining(tvb, offset);
262 call_dissector(data_handle,
263 tvb_new_subset(tvb, offset, -1, -1), pinfo, icap_tree);
269 is_icap_message(const guchar *data, int linelen, icap_type_t *type)
271 #define ICAP_COMPARE(string, length, msgtype) { \
272 if (strncmp(data, string, length) == 0) { \
273 if (*type == ICAP_OTHER) \
279 * From draft-elson-opes-icap-01(72).txt
282 ICAP_COMPARE("ICAP/", 5, ICAP_RESPONSE); /* response */
285 ICAP_COMPARE("REQMOD ", 7, ICAP_REQMOD); /* request mod */
288 ICAP_COMPARE("OPTIONS ", 8, ICAP_OPTIONS); /* options */
289 ICAP_COMPARE("RESPMOD ", 8, ICAP_RESPMOD); /* response mod */
296 proto_register_icap(void)
298 static hf_register_info hf[] = {
300 { "Response", "icap.response",
301 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
302 "TRUE if ICAP response", HFILL }},
304 { "Reqmod", "icap.reqmod",
305 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
306 "TRUE if ICAP reqmod", HFILL }},
308 { "Respmod", "icap.respmod",
309 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
310 "TRUE if ICAP respmod", HFILL }},
312 { "Options", "icap.options",
313 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
314 "TRUE if ICAP options", HFILL }},
316 { "Other", "icap.other",
317 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
318 "TRUE if ICAP other", HFILL }},
320 static gint *ett[] = {
324 proto_icap = proto_register_protocol(
325 "Internet Content Adaptation Protocol",
327 proto_register_field_array(proto_icap, hf, array_length(hf));
328 proto_register_subtree_array(ett, array_length(ett));
333 proto_reg_handoff_icap(void)
335 dissector_handle_t icap_handle;
337 data_handle = find_dissector("data");
338 icap_handle = create_dissector_handle(dissect_icap, proto_icap);
339 dissector_add("tcp.port", TCP_PORT_ICAP, icap_handle);