2 * Routines for ICAP packet disassembly
4 * Srishylam Simharajan simha@netapp.com
6 * packet-icap.c Mon Aug 13 17:50:19 PDT 2001 simha
8 * Ethereal - Network traffic analyzer
9 * By Gerald Combs <gerald@ethereal.com>
10 * Copyright 1998 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 #ifdef HAVE_SYS_TYPES_H
32 #include <sys/types.h>
39 #include <epan/packet.h>
40 #include <epan/strutil.h>
42 typedef enum _icap_type {
50 static int proto_icap = -1;
51 static int hf_icap_response = -1;
52 static int hf_icap_reqmod = -1;
53 static int hf_icap_respmod = -1;
54 static int hf_icap_options = -1;
55 static int hf_icap_other = -1;
57 static gint ett_icap = -1;
59 static dissector_handle_t data_handle;
61 #define TCP_PORT_ICAP 1344
62 static int is_icap_message(const u_char *data, int linelen, icap_type_t *type);
64 dissect_icap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
66 proto_tree *icap_tree = NULL;
67 proto_item *ti = NULL;
71 const u_char *linep, *lineend;
74 icap_type_t icap_type;
77 if (check_col(pinfo->cinfo, COL_PROTOCOL))
78 col_set_str(pinfo->cinfo, COL_PROTOCOL, "ICAP");
80 if (check_col(pinfo->cinfo, COL_INFO)) {
82 * Put the first line from the buffer into the summary
83 * if it's an ICAP header (but leave out the
85 * Otherwise, just call it a continuation.
87 * Note that "tvb_find_line_end()" will return a value that
88 * is not longer than what's in the buffer, so the
89 * "tvb_get_ptr()" call won't throw an exception.
91 linelen = tvb_find_line_end(tvb, offset, -1, &next_offset);
92 line = tvb_get_ptr(tvb, offset, linelen);
93 icap_type = ICAP_OTHER; /* type not known yet */
94 if (is_icap_message(line, linelen, &icap_type))
95 col_add_str(pinfo->cinfo, COL_INFO,
96 format_text(line, linelen));
98 col_set_str(pinfo->cinfo, COL_INFO, "Continuation");
102 ti = proto_tree_add_item(tree, proto_icap, tvb, offset, -1,
104 icap_tree = proto_item_add_subtree(ti, ett_icap);
108 * Process the packet data, a line at a time.
110 icap_type = ICAP_OTHER; /* type not known yet */
111 while (tvb_offset_exists(tvb, offset)) {
112 gboolean is_icap = FALSE;
113 gboolean loop_done = FALSE;
115 * Find the end of the line.
117 linelen = tvb_find_line_end(tvb, offset, -1, &next_offset);
120 * Get a buffer that refers to the line.
122 line = tvb_get_ptr(tvb, offset, linelen);
123 lineend = line + linelen;
128 if (is_icap_message(line, linelen, &icap_type)) {
134 * if it looks like a blank line, end of header perhaps?
142 * No. Does it look like a MIME header?
146 while (linep < lineend && (!loop_done)) {
150 break; /* not printable, not a MIME header */
180 * We don't consider this part of an ICAP message,
181 * so we don't display it.
182 * (Yeah, that means we don't display, say, a text/icap
183 * page, but you can get that from the data pane.)
189 proto_tree_add_text(icap_tree, tvb, offset,
190 next_offset - offset, "%s",
191 tvb_format_text(tvb, offset,
192 next_offset - offset)
195 offset = next_offset;
202 proto_tree_add_boolean_hidden(icap_tree,
203 hf_icap_options, tvb, 0, 0, 1);
207 proto_tree_add_boolean_hidden(icap_tree,
208 hf_icap_reqmod, tvb, 0, 0, 1);
212 proto_tree_add_boolean_hidden(icap_tree,
213 hf_icap_respmod, tvb, 0, 0, 1);
217 proto_tree_add_boolean_hidden(icap_tree,
218 hf_icap_response, tvb, 0, 0, 1);
227 datalen = tvb_length_remaining(tvb, offset);
229 call_dissector(data_handle,tvb_new_subset(tvb, offset, -1, tvb_reported_length_remaining(tvb,offset)), pinfo, icap_tree);
235 is_icap_message(const u_char *data, int linelen, icap_type_t *type)
237 #define ICAP_COMPARE(string, length, msgtype) { \
238 if (strncmp(data, string, length) == 0) { \
239 if (*type == ICAP_OTHER) \
245 * From draft-elson-opes-icap-01(72).txt
248 ICAP_COMPARE("ICAP/", 5, ICAP_RESPONSE); /* response */
251 ICAP_COMPARE("REQMOD ", 7, ICAP_REQMOD); /* request mod */
254 ICAP_COMPARE("OPTIONS ", 8, ICAP_OPTIONS); /* options */
255 ICAP_COMPARE("RESPMOD ", 8, ICAP_RESPMOD); /* response mod */
262 proto_register_icap(void)
264 static hf_register_info hf[] = {
266 { "Response", "icap.response",
267 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
268 "TRUE if ICAP response", HFILL }},
270 { "Reqmod", "icap.reqmod",
271 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
272 "TRUE if ICAP reqmod", HFILL }},
274 { "Respmod", "icap.respmod",
275 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
276 "TRUE if ICAP respmod", HFILL }},
278 { "Options", "icap.options",
279 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
280 "TRUE if ICAP options", HFILL }},
282 { "Other", "icap.other",
283 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
284 "TRUE if ICAP other", HFILL }},
286 static gint *ett[] = {
290 proto_icap = proto_register_protocol(
291 "Internet Content Adaptation Protocol",
293 proto_register_field_array(proto_icap, hf, array_length(hf));
294 proto_register_subtree_array(ett, array_length(ett));
299 proto_reg_handoff_icap(void)
301 dissector_handle_t icap_handle;
303 data_handle = find_dissector("data");
304 icap_handle = create_dissector_handle(dissect_icap, proto_icap);
305 dissector_add("tcp.port", TCP_PORT_ICAP, icap_handle);