2 * Routines for ICP (internet cache protocol) packet disassembly
5 * Copyright 1999 Peter Torvals
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 #include <epan/packet.h>
29 #include <epan/expert.h>
31 void proto_register_icp(void);
32 void proto_reg_handoff_icp(void);
34 static int proto_icp = -1;
35 static int hf_icp_length = -1;
36 static int hf_icp_opcode = -1;
37 static int hf_icp_version = -1;
38 static int hf_icp_request_nr = -1;
40 /* Generated from convert_proto_tree_add_text.pl */
41 static int hf_icp_url = -1;
42 static int hf_icp_rtt = -1;
43 static int hf_icp_object_data = -1;
44 static int hf_icp_requester_host_address = -1;
45 static int hf_icp_sender_host_ip_address = -1;
46 static int hf_icp_option_src_rtt = -1;
47 static int hf_icp_object_length = -1;
48 static int hf_icp_option_hit_obj = -1;
50 static gint ett_icp = -1;
51 static gint ett_icp_payload = -1;
53 /* Generated from convert_proto_tree_add_text.pl */
54 static expert_field ei_icp_fragmented_packet = EI_INIT;
56 #define UDP_PORT_ICP 3130
58 #define CODE_ICP_OP_QUERY 1
59 #define CODE_ICP_OP_INVALID 0
60 #define CODE_ICP_OP_HIT 2
61 #define CODE_ICP_OP_MISS 3
62 #define CODE_ICP_OP_ERR 4
63 #define CODE_ICP_OP_SEND 5
64 #define CODE_ICP_OP_SENDA 6
65 #define CODE_ICP_OP_DATABEG 7
66 #define CODE_ICP_OP_DATA 8
67 #define CODE_ICP_OP_DATAEND 9
68 #define CODE_ICP_OP_SECHO 10
69 #define CODE_ICP_OP_DECHO 11
70 #define CODE_ICP_OP_MISS_NOFETCH 21
71 #define CODE_ICP_OP_DENIED 22
72 #define CODE_ICP_OP_HIT_OBJ 23
74 static const value_string opcode_vals[] = {
75 { CODE_ICP_OP_INVALID , "ICP_INVALID" },
76 { CODE_ICP_OP_QUERY , "ICP_QUERY" },
77 { CODE_ICP_OP_HIT , "ICP_HIT" },
78 { CODE_ICP_OP_MISS , "ICP_MISS" },
79 { CODE_ICP_OP_ERR , "ICP_ERR" },
80 { CODE_ICP_OP_SEND, "ICP_SEND" },
81 { CODE_ICP_OP_SENDA, "ICP_SENDA"},
82 { CODE_ICP_OP_DATABEG, "ICP_DATABEG"},
83 { CODE_ICP_OP_DATA, "ICP_DATA"},
84 { CODE_ICP_OP_DATAEND, "ICP_DATA_END"},
85 { CODE_ICP_OP_SECHO , "ICP_SECHO"},
86 { CODE_ICP_OP_DECHO , "ICP_DECHO"},
87 { CODE_ICP_OP_MISS_NOFETCH , "ICP_MISS_NOFETCH"},
88 { CODE_ICP_OP_DENIED , "ICP_DENIED"},
89 { CODE_ICP_OP_HIT_OBJ , "ICP_HIT_OBJ"},
93 static void dissect_icp_payload(tvbuff_t *tvb, packet_info *pinfo, int offset,
94 proto_tree *pload_tree, guint8 opcode)
98 proto_item* object_item;
102 case CODE_ICP_OP_QUERY:
103 /* 4 byte requester host address */
104 proto_tree_add_item(pload_tree, hf_icp_requester_host_address, tvb, offset, 4, ENC_BIG_ENDIAN);
107 /* null terminated URL */
108 stringlength = tvb_strsize(tvb, offset);
109 proto_tree_add_item(pload_tree, hf_icp_url, tvb, offset, stringlength, ENC_ASCII|ENC_NA);
112 case CODE_ICP_OP_SECHO:
113 case CODE_ICP_OP_DECHO:
114 case CODE_ICP_OP_HIT:
115 case CODE_ICP_OP_MISS:
116 case CODE_ICP_OP_ERR:
117 case CODE_ICP_OP_MISS_NOFETCH:
118 case CODE_ICP_OP_DENIED:
119 stringlength = tvb_strsize(tvb, offset);
120 proto_tree_add_item(pload_tree, hf_icp_url, tvb, offset, stringlength, ENC_ASCII|ENC_NA);
123 case CODE_ICP_OP_HIT_OBJ:
124 /* null terminated URL */
125 stringlength = tvb_strsize(tvb, offset);
126 proto_tree_add_item(pload_tree, hf_icp_url, tvb, offset, stringlength, ENC_ASCII|ENC_NA);
127 offset += stringlength;
129 /* 2 byte object size */
130 /* object data not recommended by standard*/
131 objectlength=tvb_get_ntohs(tvb, offset);
132 proto_tree_add_item(pload_tree, hf_icp_object_length, tvb, offset, 2, ENC_BIG_ENDIAN);
135 /* object data not recommended by standard*/
136 object_item = proto_tree_add_item(pload_tree, hf_icp_object_data, tvb, offset, objectlength, ENC_NA);
137 if (objectlength > tvb_reported_length_remaining(tvb, offset))
139 expert_add_info(pinfo, object_item, &ei_icp_fragmented_packet);
147 static int dissect_icp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
149 proto_tree *icp_tree , *payload_tree;
152 guint16 message_length;
153 guint32 request_number;
156 col_set_str(pinfo->cinfo, COL_PROTOCOL, "ICP");
157 col_clear(pinfo->cinfo, COL_INFO);
159 opcode=tvb_get_guint8(tvb, 0);
160 message_length=tvb_get_ntohs(tvb, 2);
161 request_number=tvb_get_ntohl(tvb, 4);
163 col_add_fstr(pinfo->cinfo,COL_INFO,"Opcode: %s (%u), Req Nr: %u",
164 val_to_str_const(opcode, opcode_vals, "Unknown"), opcode,
167 ti = proto_tree_add_item(tree,proto_icp, tvb, 0, message_length, ENC_NA);
168 icp_tree = proto_item_add_subtree(ti, ett_icp);
172 proto_tree_add_uint(icp_tree,hf_icp_opcode, tvb, 0, 1, opcode);
174 proto_tree_add_item(icp_tree,hf_icp_version, tvb, 1, 1, ENC_BIG_ENDIAN);
176 proto_tree_add_uint(icp_tree,hf_icp_length, tvb, 2, 2, message_length);
178 proto_tree_add_uint(icp_tree,hf_icp_request_nr, tvb, 4, 4,
181 options=tvb_get_ntohl(tvb, 8);
182 if ( (opcode == CODE_ICP_OP_QUERY) && ((options & 0x80000000 ) != 0) )
184 proto_tree_add_item(icp_tree, hf_icp_option_hit_obj, tvb, 8, 4, ENC_NA);
186 if ( (opcode == CODE_ICP_OP_QUERY)&& ((options & 0x40000000 ) != 0) )
188 proto_tree_add_item(icp_tree, hf_icp_option_src_rtt, tvb, 8, 4, ENC_NA);
190 if ((opcode != CODE_ICP_OP_QUERY)&& ((options & 0x40000000 ) != 0))
192 proto_tree_add_item(icp_tree, hf_icp_option_src_rtt, tvb, 8, 4, ENC_NA);
193 proto_tree_add_item(icp_tree, hf_icp_rtt, tvb, 12, 4, ENC_BIG_ENDIAN);
196 proto_tree_add_item(icp_tree, hf_icp_sender_host_ip_address, tvb, 16, 4, ENC_BIG_ENDIAN);
199 payload_tree = proto_tree_add_subtree(icp_tree, tvb,
200 20, message_length - 20,
201 ett_icp_payload, NULL, "Payload");
202 dissect_icp_payload(tvb, pinfo, 20, payload_tree, opcode);
204 return tvb_captured_length(tvb);
208 proto_register_icp(void)
210 static hf_register_info hf[] = {
212 { "Opcode", "icp.opcode", FT_UINT8, BASE_HEX, VALS(opcode_vals),
216 { "Version", "icp.version", FT_UINT8, BASE_DEC, NULL,
220 { "Length", "icp.length", FT_UINT16, BASE_DEC, NULL,
223 { &hf_icp_request_nr,
224 { "Request Number", "icp.nr", FT_UINT32, BASE_DEC, NULL,
227 { &hf_icp_requester_host_address, { "Requester Host Address", "icp.requester_host_address", FT_IPv4, BASE_NONE, NULL, 0x0, NULL, HFILL }},
228 { &hf_icp_url, { "URL", "icp.url", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
229 { &hf_icp_object_length, { "Object length", "icp.object_length", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
230 { &hf_icp_object_data, { "Object data", "icp.object_data", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
231 { &hf_icp_option_hit_obj, { "Option: ICP_FLAG_HIT_OBJ", "icp.option.hit_obj", FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }},
232 { &hf_icp_option_src_rtt, { "Option: ICP_FLAG_SRC_RTT", "icp.option.src_rtt", FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }},
233 { &hf_icp_rtt, { "RTT", "icp.rtt", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }},
234 { &hf_icp_sender_host_ip_address, { "Sender Host IP address", "icp.sender_host_ip_address", FT_IPv4, BASE_NONE, NULL, 0x0, NULL, HFILL }},
236 static gint *ett[] = {
241 static ei_register_info ei[] = {
242 { &ei_icp_fragmented_packet, { "icp.fragmented_packet", PI_PROTOCOL, PI_WARN, "Packet is fragmented", EXPFILL }},
245 expert_module_t* expert_icp;
247 proto_icp = proto_register_protocol("Internet Cache Protocol", "ICP", "icp");
249 proto_register_field_array(proto_icp, hf, array_length(hf));
250 proto_register_subtree_array(ett, array_length(ett));
251 expert_icp = expert_register_protocol(proto_icp);
252 expert_register_field_array(expert_icp, ei, array_length(ei));
256 proto_reg_handoff_icp(void)
258 dissector_handle_t icp_handle;
260 icp_handle = new_create_dissector_handle(dissect_icp, proto_icp);
261 dissector_add_uint("udp.port", UDP_PORT_ICP, icp_handle);
265 * Editor modelines - http://www.wireshark.org/tools/modelines.html
270 * indent-tabs-mode: t
273 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
274 * :indentSize=8:tabSize=8:noTabs=false: