2 * Routines for ICP (internet cache protocol) packet disassembly
5 * Copyright 1999 Peter Torvals
7 * $Id: packet-icp.c,v 1.23 2002/08/28 21:00:17 jmayer Exp $
9 * Ethereal - Network traffic analyzer
10 * By Gerald Combs <gerald@ethereal.com>
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.
28 #define MAX_TEXTBUF_LENGTH 600
37 #include <epan/packet.h>
38 #include <epan/resolv.h>
40 static int proto_icp=-1;
41 static int hf_icp_length=-1;
42 static int hf_icp_opcode=-1;
43 static int hf_icp_version=-1;
44 static int hf_icp_request_nr=-1;
46 static gint ett_icp = -1;
47 static gint ett_icp_payload = -1;
49 #define UDP_PORT_ICP 3130
51 #define CODE_ICP_OP_QUERY 1
52 #define CODE_ICP_OP_INVALID 0
53 #define CODE_ICP_OP_HIT 2
54 #define CODE_ICP_OP_MISS 3
55 #define CODE_ICP_OP_ERR 4
56 #define CODE_ICP_OP_SEND 5
57 #define CODE_ICP_OP_SENDA 6
58 #define CODE_ICP_OP_DATABEG 7
59 #define CODE_ICP_OP_DATA 8
60 #define CODE_ICP_OP_DATAEND 9
61 #define CODE_ICP_OP_SECHO 10
62 #define CODE_ICP_OP_DECHO 11
63 #define CODE_ICP_OP_MISS_NOFETCH 21
64 #define CODE_ICP_OP_DENIED 22
65 #define CODE_ICP_OP_HIT_OBJ 23
67 static value_string opcode_vals[] = {
68 { CODE_ICP_OP_INVALID , "ICP_INVALID" },
69 { CODE_ICP_OP_QUERY , "ICP_QUERY" },
70 { CODE_ICP_OP_HIT , "ICP_HIT" },
71 { CODE_ICP_OP_MISS , "ICP_MISS" },
72 { CODE_ICP_OP_ERR , "ICP_ERR" },
73 { CODE_ICP_OP_SEND, "ICP_SEND" },
74 { CODE_ICP_OP_SENDA, "ICP_SENDA"},
75 { CODE_ICP_OP_DATABEG, "ICP_DATABEG"},
76 { CODE_ICP_OP_DATA, "ICP_DATA"},
77 { CODE_ICP_OP_DATAEND, "ICP_DATA_END"},
78 { CODE_ICP_OP_SECHO , "ICP_SECHO"},
79 { CODE_ICP_OP_DECHO , "ICP_DECHO"},
80 { CODE_ICP_OP_MISS_NOFETCH , "ICP_MISS_NOFETCH"},
81 { CODE_ICP_OP_DENIED , "ICP_DENIED"},
82 { CODE_ICP_OP_HIT_OBJ , "ICP_HIT_OBJ"},
86 static void dissect_icp_payload(tvbuff_t *tvb, int offset,
87 proto_tree *pload_tree, guint8 opcode)
94 case CODE_ICP_OP_QUERY:
95 /* 4 byte requester host address */
96 proto_tree_add_text(pload_tree, tvb,offset,4,
97 "Requester Host Address %s",
98 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
101 /* null terminated URL */
102 stringlength = tvb_strsize(tvb, offset);
103 proto_tree_add_text(pload_tree, tvb, offset, stringlength,
104 "URL: %s", tvb_get_ptr(tvb, offset, stringlength));
107 case CODE_ICP_OP_SECHO:
108 case CODE_ICP_OP_DECHO:
109 case CODE_ICP_OP_HIT:
110 case CODE_ICP_OP_MISS:
111 case CODE_ICP_OP_ERR:
112 case CODE_ICP_OP_MISS_NOFETCH:
113 case CODE_ICP_OP_DENIED:
114 stringlength = tvb_strsize(tvb, offset);
115 proto_tree_add_text(pload_tree, tvb, offset, stringlength,
116 "URL: %s", tvb_get_ptr(tvb, offset, stringlength));
119 case CODE_ICP_OP_HIT_OBJ:
120 /* null terminated URL */
121 stringlength = tvb_strsize(tvb, offset);
122 proto_tree_add_text(pload_tree, tvb, offset, stringlength,
123 "URL: %s", tvb_get_ptr(tvb, offset, stringlength));
124 offset += stringlength;
126 /* 2 byte object size */
127 /* object data not recommended by standard*/
128 objectlength=tvb_get_ntohs(tvb, offset);
129 proto_tree_add_text(pload_tree, tvb,offset,2,"Object length: %u", objectlength);
132 /* object data not recommended by standard*/
133 proto_tree_add_text(pload_tree, tvb,offset,objectlength,"Object data");
134 if (objectlength > tvb_reported_length_remaining(tvb, offset))
136 proto_tree_add_text(pload_tree, tvb,offset,0,
137 "Packet is fragmented, rest of object is in next udp packet");
145 static void dissect_icp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
147 proto_tree *icp_tree , *payload_tree;
148 proto_item *ti , *payloadtf;
150 guint16 message_length;
151 guint32 request_number;
155 if (check_col(pinfo->cinfo, COL_PROTOCOL))
156 col_set_str(pinfo->cinfo, COL_PROTOCOL, "ICP");
157 if (check_col(pinfo->cinfo, COL_INFO))
158 col_clear(pinfo->cinfo, COL_INFO);
160 opcode=tvb_get_guint8(tvb, 0);
161 message_length=tvb_get_ntohs(tvb, 2);
162 request_number=tvb_get_ntohl(tvb, 4);
164 if (check_col(pinfo->cinfo, COL_INFO))
166 col_add_fstr(pinfo->cinfo,COL_INFO,"Opcode: %s (%u), Req Nr: %u",
167 val_to_str(opcode, opcode_vals, "Unknown"), opcode,
174 ti = proto_tree_add_item(tree,proto_icp, tvb, 0, message_length, FALSE);
175 icp_tree = proto_item_add_subtree(ti, ett_icp);
177 proto_tree_add_uint(icp_tree,hf_icp_opcode, tvb, 0, 1, opcode);
179 proto_tree_add_item(icp_tree,hf_icp_version, tvb, 1, 1, FALSE);
181 proto_tree_add_uint(icp_tree,hf_icp_length, tvb, 2, 2, message_length);
183 proto_tree_add_uint(icp_tree,hf_icp_request_nr, tvb, 4, 4,
186 options=tvb_get_ntohl(tvb, 8);
187 if ( (opcode == CODE_ICP_OP_QUERY) && ((options & 0x80000000 ) != 0) )
189 proto_tree_add_text(icp_tree, tvb,8,4,
190 "option: ICP_FLAG_HIT_OBJ");
192 if ( (opcode == CODE_ICP_OP_QUERY)&& ((options & 0x40000000 ) != 0) )
194 proto_tree_add_text(icp_tree, tvb,8,4,
195 "option:ICP_FLAG_SRC_RTT");
197 if ((opcode != CODE_ICP_OP_QUERY)&& ((options & 0x40000000 ) != 0))
199 option_data=tvb_get_ntohl(tvb, 12);
200 proto_tree_add_text(icp_tree, tvb,8,8,
201 "option: ICP_FLAG_SCR_RTT RTT=%u",
202 option_data & 0x0000ffff);
205 proto_tree_add_text(icp_tree, tvb, 16, 4,
206 "Sender Host IP address %s",
207 ip_to_str(tvb_get_ptr(tvb, 16, 4)));
209 payloadtf = proto_tree_add_text(icp_tree, tvb,
210 20, message_length - 20,
212 payload_tree = proto_item_add_subtree(payloadtf, ett_icp_payload);
213 dissect_icp_payload(tvb, 20, payload_tree, opcode);
217 proto_register_icp(void)
219 static hf_register_info hf[] = {
221 { "Opcode", "icp.opcode", FT_UINT8, BASE_HEX, VALS(opcode_vals),
225 { "Version", "icp.version", FT_UINT8, BASE_DEC, NULL,
229 { "Length", "icp.length", FT_UINT16, BASE_DEC, NULL,
232 { &hf_icp_request_nr,
233 { "Request Number", "icp.nr", FT_UINT32, BASE_DEC, NULL,
236 static gint *ett[] = {
241 proto_icp = proto_register_protocol("Internet Cache Protocol",
243 proto_register_field_array(proto_icp, hf, array_length(hf));
244 proto_register_subtree_array(ett, array_length(ett));
248 proto_reg_handoff_icp(void)
250 dissector_handle_t icp_handle;
252 icp_handle = create_dissector_handle(dissect_icp, proto_icp);
253 dissector_add("udp.port", UDP_PORT_ICP, icp_handle);