2 * Routines for ICP (internet cache protocol) packet disassembly
5 * Copyright 1999 Peter Torvals
9 * Wireshark - Network traffic analyzer
10 * By Gerald Combs <gerald@wireshark.org>
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
35 #include <epan/packet.h>
36 #include <epan/addr_resolv.h>
38 static int proto_icp=-1;
39 static int hf_icp_length=-1;
40 static int hf_icp_opcode=-1;
41 static int hf_icp_version=-1;
42 static int hf_icp_request_nr=-1;
44 static gint ett_icp = -1;
45 static gint ett_icp_payload = -1;
47 #define UDP_PORT_ICP 3130
49 #define CODE_ICP_OP_QUERY 1
50 #define CODE_ICP_OP_INVALID 0
51 #define CODE_ICP_OP_HIT 2
52 #define CODE_ICP_OP_MISS 3
53 #define CODE_ICP_OP_ERR 4
54 #define CODE_ICP_OP_SEND 5
55 #define CODE_ICP_OP_SENDA 6
56 #define CODE_ICP_OP_DATABEG 7
57 #define CODE_ICP_OP_DATA 8
58 #define CODE_ICP_OP_DATAEND 9
59 #define CODE_ICP_OP_SECHO 10
60 #define CODE_ICP_OP_DECHO 11
61 #define CODE_ICP_OP_MISS_NOFETCH 21
62 #define CODE_ICP_OP_DENIED 22
63 #define CODE_ICP_OP_HIT_OBJ 23
65 static const value_string opcode_vals[] = {
66 { CODE_ICP_OP_INVALID , "ICP_INVALID" },
67 { CODE_ICP_OP_QUERY , "ICP_QUERY" },
68 { CODE_ICP_OP_HIT , "ICP_HIT" },
69 { CODE_ICP_OP_MISS , "ICP_MISS" },
70 { CODE_ICP_OP_ERR , "ICP_ERR" },
71 { CODE_ICP_OP_SEND, "ICP_SEND" },
72 { CODE_ICP_OP_SENDA, "ICP_SENDA"},
73 { CODE_ICP_OP_DATABEG, "ICP_DATABEG"},
74 { CODE_ICP_OP_DATA, "ICP_DATA"},
75 { CODE_ICP_OP_DATAEND, "ICP_DATA_END"},
76 { CODE_ICP_OP_SECHO , "ICP_SECHO"},
77 { CODE_ICP_OP_DECHO , "ICP_DECHO"},
78 { CODE_ICP_OP_MISS_NOFETCH , "ICP_MISS_NOFETCH"},
79 { CODE_ICP_OP_DENIED , "ICP_DENIED"},
80 { CODE_ICP_OP_HIT_OBJ , "ICP_HIT_OBJ"},
84 static void dissect_icp_payload(tvbuff_t *tvb, int offset,
85 proto_tree *pload_tree, guint8 opcode)
92 case CODE_ICP_OP_QUERY:
93 /* 4 byte requester host address */
94 proto_tree_add_text(pload_tree, tvb,offset,4,
95 "Requester Host Address %s",
96 tvb_ip_to_str(tvb, offset));
99 /* null terminated URL */
100 stringlength = tvb_strsize(tvb, offset);
101 proto_tree_add_text(pload_tree, tvb, offset, stringlength,
102 "URL: %s", tvb_get_ephemeral_string(tvb, offset, stringlength));
105 case CODE_ICP_OP_SECHO:
106 case CODE_ICP_OP_DECHO:
107 case CODE_ICP_OP_HIT:
108 case CODE_ICP_OP_MISS:
109 case CODE_ICP_OP_ERR:
110 case CODE_ICP_OP_MISS_NOFETCH:
111 case CODE_ICP_OP_DENIED:
112 stringlength = tvb_strsize(tvb, offset);
113 proto_tree_add_text(pload_tree, tvb, offset, stringlength,
114 "URL: %s", tvb_get_ephemeral_string(tvb, offset, stringlength));
117 case CODE_ICP_OP_HIT_OBJ:
118 /* null terminated URL */
119 stringlength = tvb_strsize(tvb, offset);
120 proto_tree_add_text(pload_tree, tvb, offset, stringlength,
121 "URL: %s", tvb_get_ephemeral_string(tvb, offset, stringlength));
122 offset += stringlength;
124 /* 2 byte object size */
125 /* object data not recommended by standard*/
126 objectlength=tvb_get_ntohs(tvb, offset);
127 proto_tree_add_text(pload_tree, tvb,offset,2,"Object length: %u", objectlength);
130 /* object data not recommended by standard*/
131 proto_tree_add_text(pload_tree, tvb,offset,objectlength,"Object data");
132 if (objectlength > tvb_reported_length_remaining(tvb, offset))
134 proto_tree_add_text(pload_tree, tvb,offset,0,
135 "Packet is fragmented, rest of object is in next udp packet");
143 static void dissect_icp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
145 proto_tree *icp_tree , *payload_tree;
146 proto_item *ti , *payloadtf;
148 guint16 message_length;
149 guint32 request_number;
153 col_set_str(pinfo->cinfo, COL_PROTOCOL, "ICP");
154 col_clear(pinfo->cinfo, COL_INFO);
156 opcode=tvb_get_guint8(tvb, 0);
157 message_length=tvb_get_ntohs(tvb, 2);
158 request_number=tvb_get_ntohl(tvb, 4);
160 if (check_col(pinfo->cinfo, COL_INFO))
162 col_add_fstr(pinfo->cinfo,COL_INFO,"Opcode: %s (%u), Req Nr: %u",
163 val_to_str(opcode, opcode_vals, "Unknown"), opcode,
170 ti = proto_tree_add_item(tree,proto_icp, tvb, 0, message_length, ENC_NA);
171 icp_tree = proto_item_add_subtree(ti, ett_icp);
173 proto_tree_add_uint(icp_tree,hf_icp_opcode, tvb, 0, 1, opcode);
175 proto_tree_add_item(icp_tree,hf_icp_version, tvb, 1, 1, ENC_BIG_ENDIAN);
177 proto_tree_add_uint(icp_tree,hf_icp_length, tvb, 2, 2, message_length);
179 proto_tree_add_uint(icp_tree,hf_icp_request_nr, tvb, 4, 4,
182 options=tvb_get_ntohl(tvb, 8);
183 if ( (opcode == CODE_ICP_OP_QUERY) && ((options & 0x80000000 ) != 0) )
185 proto_tree_add_text(icp_tree, tvb,8,4,
186 "option: ICP_FLAG_HIT_OBJ");
188 if ( (opcode == CODE_ICP_OP_QUERY)&& ((options & 0x40000000 ) != 0) )
190 proto_tree_add_text(icp_tree, tvb,8,4,
191 "option:ICP_FLAG_SRC_RTT");
193 if ((opcode != CODE_ICP_OP_QUERY)&& ((options & 0x40000000 ) != 0))
195 option_data=tvb_get_ntohl(tvb, 12);
196 proto_tree_add_text(icp_tree, tvb,8,8,
197 "option: ICP_FLAG_SCR_RTT RTT=%u",
198 option_data & 0x0000ffff);
201 proto_tree_add_text(icp_tree, tvb, 16, 4,
202 "Sender Host IP address %s",
203 tvb_ip_to_str(tvb, 16));
205 payloadtf = proto_tree_add_text(icp_tree, tvb,
206 20, message_length - 20,
208 payload_tree = proto_item_add_subtree(payloadtf, ett_icp_payload);
209 dissect_icp_payload(tvb, 20, payload_tree, opcode);
213 proto_register_icp(void)
215 static hf_register_info hf[] = {
217 { "Opcode", "icp.opcode", FT_UINT8, BASE_HEX, VALS(opcode_vals),
221 { "Version", "icp.version", FT_UINT8, BASE_DEC, NULL,
225 { "Length", "icp.length", FT_UINT16, BASE_DEC, NULL,
228 { &hf_icp_request_nr,
229 { "Request Number", "icp.nr", FT_UINT32, BASE_DEC, NULL,
232 static gint *ett[] = {
237 proto_icp = proto_register_protocol("Internet Cache Protocol",
239 proto_register_field_array(proto_icp, hf, array_length(hf));
240 proto_register_subtree_array(ett, array_length(ett));
244 proto_reg_handoff_icp(void)
246 dissector_handle_t icp_handle;
248 icp_handle = create_dissector_handle(dissect_icp, proto_icp);
249 dissector_add_uint("udp.port", UDP_PORT_ICP, icp_handle);