2 * Routines for ICAP packet disassembly
4 * Srishylam Simharajan simha@netapp.com
6 * $Id: packet-icap.c,v 1.12 2002/08/28 21:00:17 jmayer Exp $
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.
35 #include <epan/packet.h>
36 #include <epan/strutil.h>
38 typedef enum _icap_type {
46 static int proto_icap = -1;
47 static int hf_icap_response = -1;
48 static int hf_icap_reqmod = -1;
49 static int hf_icap_respmod = -1;
50 static int hf_icap_options = -1;
51 static int hf_icap_other = -1;
53 static gint ett_icap = -1;
55 static dissector_handle_t data_handle;
57 #define TCP_PORT_ICAP 1344
58 static int is_icap_message(const guchar *data, int linelen, icap_type_t *type);
60 dissect_icap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
62 proto_tree *icap_tree = NULL;
63 proto_item *ti = NULL;
67 const guchar *linep, *lineend;
70 icap_type_t icap_type;
73 if (check_col(pinfo->cinfo, COL_PROTOCOL))
74 col_set_str(pinfo->cinfo, COL_PROTOCOL, "ICAP");
76 if (check_col(pinfo->cinfo, COL_INFO)) {
78 * Put the first line from the buffer into the summary
79 * if it's an ICAP header (but leave out the
81 * Otherwise, just call it a continuation.
83 * Note that "tvb_find_line_end()" will return a value that
84 * is not longer than what's in the buffer, so the
85 * "tvb_get_ptr()" call won't throw an exception.
87 linelen = tvb_find_line_end(tvb, offset, -1, &next_offset,
89 line = tvb_get_ptr(tvb, offset, linelen);
90 icap_type = ICAP_OTHER; /* type not known yet */
91 if (is_icap_message(line, linelen, &icap_type))
92 col_add_str(pinfo->cinfo, COL_INFO,
93 format_text(line, linelen));
95 col_set_str(pinfo->cinfo, COL_INFO, "Continuation");
99 ti = proto_tree_add_item(tree, proto_icap, tvb, offset, -1,
101 icap_tree = proto_item_add_subtree(ti, ett_icap);
105 * Process the packet data, a line at a time.
107 icap_type = ICAP_OTHER; /* type not known yet */
108 while (tvb_offset_exists(tvb, offset)) {
109 gboolean is_icap = FALSE;
110 gboolean loop_done = FALSE;
112 * Find the end of the line.
114 linelen = tvb_find_line_end(tvb, offset, -1, &next_offset,
118 * Get a buffer that refers to the line.
120 line = tvb_get_ptr(tvb, offset, linelen);
121 lineend = line + linelen;
126 if (is_icap_message(line, linelen, &icap_type)) {
132 * if it looks like a blank line, end of header perhaps?
140 * No. Does it look like a MIME header?
144 while (linep < lineend && (!loop_done)) {
148 break; /* not printable, not a MIME header */
178 * We don't consider this part of an ICAP message,
179 * so we don't display it.
180 * (Yeah, that means we don't display, say, a text/icap
181 * page, but you can get that from the data pane.)
187 proto_tree_add_text(icap_tree, tvb, offset,
188 next_offset - offset, "%s",
189 tvb_format_text(tvb, offset,
190 next_offset - offset)
193 offset = next_offset;
200 proto_tree_add_boolean_hidden(icap_tree,
201 hf_icap_options, tvb, 0, 0, 1);
205 proto_tree_add_boolean_hidden(icap_tree,
206 hf_icap_reqmod, tvb, 0, 0, 1);
210 proto_tree_add_boolean_hidden(icap_tree,
211 hf_icap_respmod, tvb, 0, 0, 1);
215 proto_tree_add_boolean_hidden(icap_tree,
216 hf_icap_response, tvb, 0, 0, 1);
225 datalen = tvb_length_remaining(tvb, offset);
227 call_dissector(data_handle,
228 tvb_new_subset(tvb, offset, -1, -1), pinfo, icap_tree);
234 is_icap_message(const guchar *data, int linelen, icap_type_t *type)
236 #define ICAP_COMPARE(string, length, msgtype) { \
237 if (strncmp(data, string, length) == 0) { \
238 if (*type == ICAP_OTHER) \
244 * From draft-elson-opes-icap-01(72).txt
247 ICAP_COMPARE("ICAP/", 5, ICAP_RESPONSE); /* response */
250 ICAP_COMPARE("REQMOD ", 7, ICAP_REQMOD); /* request mod */
253 ICAP_COMPARE("OPTIONS ", 8, ICAP_OPTIONS); /* options */
254 ICAP_COMPARE("RESPMOD ", 8, ICAP_RESPMOD); /* response mod */
261 proto_register_icap(void)
263 static hf_register_info hf[] = {
265 { "Response", "icap.response",
266 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
267 "TRUE if ICAP response", HFILL }},
269 { "Reqmod", "icap.reqmod",
270 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
271 "TRUE if ICAP reqmod", HFILL }},
273 { "Respmod", "icap.respmod",
274 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
275 "TRUE if ICAP respmod", HFILL }},
277 { "Options", "icap.options",
278 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
279 "TRUE if ICAP options", HFILL }},
281 { "Other", "icap.other",
282 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
283 "TRUE if ICAP other", HFILL }},
285 static gint *ett[] = {
289 proto_icap = proto_register_protocol(
290 "Internet Content Adaptation Protocol",
292 proto_register_field_array(proto_icap, hf, array_length(hf));
293 proto_register_subtree_array(ett, array_length(ett));
298 proto_reg_handoff_icap(void)
300 dissector_handle_t icap_handle;
302 data_handle = find_dissector("data");
303 icap_handle = create_dissector_handle(dissect_icap, proto_icap);
304 dissector_add("tcp.port", TCP_PORT_ICAP, icap_handle);