2 * Routines for ICP (internet cache protocol) packet disassembly
5 * Copyright 1999 Peter Torvals
7 * $Id: packet-icp.c,v 1.21 2002/01/21 07:36:35 guy 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
33 #ifdef HAVE_SYS_TYPES_H
34 # include <sys/types.h>
37 #ifdef HAVE_NETINET_IN_H
38 #include <netinet/in.h>
45 #include <epan/packet.h>
46 #include <epan/resolv.h>
48 static int proto_icp=-1;
49 static int hf_icp_length=-1;
50 static int hf_icp_opcode=-1;
51 static int hf_icp_version=-1;
52 static int hf_icp_request_nr=-1;
54 static gint ett_icp = -1;
55 static gint ett_icp_payload = -1;
57 #define UDP_PORT_ICP 3130
59 #define CODE_ICP_OP_QUERY 1
60 #define CODE_ICP_OP_INVALID 0
61 #define CODE_ICP_OP_HIT 2
62 #define CODE_ICP_OP_MISS 3
63 #define CODE_ICP_OP_ERR 4
64 #define CODE_ICP_OP_SEND 5
65 #define CODE_ICP_OP_SENDA 6
66 #define CODE_ICP_OP_DATABEG 7
67 #define CODE_ICP_OP_DATA 8
68 #define CODE_ICP_OP_DATAEND 9
69 #define CODE_ICP_OP_SECHO 10
70 #define CODE_ICP_OP_DECHO 11
71 #define CODE_ICP_OP_MISS_NOFETCH 21
72 #define CODE_ICP_OP_DENIED 22
73 #define CODE_ICP_OP_HIT_OBJ 23
75 static value_string opcode_vals[] = {
76 { CODE_ICP_OP_INVALID , "ICP_INVALID" },
77 { CODE_ICP_OP_QUERY , "ICP_QUERY" },
78 { CODE_ICP_OP_HIT , "ICP_HIT" },
79 { CODE_ICP_OP_MISS , "ICP_MISS" },
80 { CODE_ICP_OP_ERR , "ICP_ERR" },
81 { CODE_ICP_OP_SEND, "ICP_SEND" },
82 { CODE_ICP_OP_SENDA, "ICP_SENDA"},
83 { CODE_ICP_OP_DATABEG, "ICP_DATABEG"},
84 { CODE_ICP_OP_DATA, "ICP_DATA"},
85 { CODE_ICP_OP_DATAEND, "ICP_DATA_END"},
86 { CODE_ICP_OP_SECHO , "ICP_SECHO"},
87 { CODE_ICP_OP_DECHO , "ICP_DECHO"},
88 { CODE_ICP_OP_MISS_NOFETCH , "ICP_MISS_NOFETCH"},
89 { CODE_ICP_OP_DENIED , "ICP_DENIED"},
90 { CODE_ICP_OP_HIT_OBJ , "ICP_HIT_OBJ"},
94 static void dissect_icp_payload(tvbuff_t *tvb, int offset,
95 proto_tree *pload_tree, guint8 opcode)
102 case CODE_ICP_OP_QUERY:
103 /* 4 byte requester host address */
104 proto_tree_add_text(pload_tree, tvb,offset,4,
105 "Requester Host Address %s",
106 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
109 /* null terminated URL */
110 stringlength = tvb_strsize(tvb, offset);
111 proto_tree_add_text(pload_tree, tvb, offset, stringlength,
112 "URL: %s", tvb_get_ptr(tvb, offset, stringlength));
115 case CODE_ICP_OP_SECHO:
116 case CODE_ICP_OP_DECHO:
117 case CODE_ICP_OP_HIT:
118 case CODE_ICP_OP_MISS:
119 case CODE_ICP_OP_ERR:
120 case CODE_ICP_OP_MISS_NOFETCH:
121 case CODE_ICP_OP_DENIED:
122 stringlength = tvb_strsize(tvb, offset);
123 proto_tree_add_text(pload_tree, tvb, offset, stringlength,
124 "URL: %s", tvb_get_ptr(tvb, offset, stringlength));
127 case CODE_ICP_OP_HIT_OBJ:
128 /* null terminated URL */
129 stringlength = tvb_strsize(tvb, offset);
130 proto_tree_add_text(pload_tree, tvb, offset, stringlength,
131 "URL: %s", tvb_get_ptr(tvb, offset, stringlength));
132 offset += stringlength;
134 /* 2 byte object size */
135 /* object data not recommended by standard*/
136 objectlength=tvb_get_ntohs(tvb, offset);
137 proto_tree_add_text(pload_tree, tvb,offset,2,"Object length: %u", objectlength);
140 /* object data not recommended by standard*/
141 proto_tree_add_text(pload_tree, tvb,offset,objectlength,"Object data");
142 if (objectlength > tvb_reported_length_remaining(tvb, offset))
144 proto_tree_add_text(pload_tree, tvb,offset,0,
145 "Packet is fragmented, rest of object is in next udp packet");
153 static void dissect_icp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
155 proto_tree *icp_tree , *payload_tree;
156 proto_item *ti , *payloadtf;
158 guint16 message_length;
159 guint32 request_number;
163 if (check_col(pinfo->cinfo, COL_PROTOCOL))
164 col_set_str(pinfo->cinfo, COL_PROTOCOL, "ICP");
165 if (check_col(pinfo->cinfo, COL_INFO))
166 col_clear(pinfo->cinfo, COL_INFO);
168 opcode=tvb_get_guint8(tvb, 0);
169 message_length=tvb_get_ntohs(tvb, 2);
170 request_number=tvb_get_ntohl(tvb, 4);
172 if (check_col(pinfo->cinfo, COL_INFO))
174 col_add_fstr(pinfo->cinfo,COL_INFO,"Opcode: %s (%u), Req Nr: %u",
175 val_to_str(opcode, opcode_vals, "Unknown"), opcode,
182 ti = proto_tree_add_item(tree,proto_icp, tvb, 0, message_length, FALSE);
183 icp_tree = proto_item_add_subtree(ti, ett_icp);
185 proto_tree_add_uint(icp_tree,hf_icp_opcode, tvb, 0, 1, opcode);
187 proto_tree_add_item(icp_tree,hf_icp_version, tvb, 1, 1, FALSE);
189 proto_tree_add_uint(icp_tree,hf_icp_length, tvb, 2, 2, message_length);
191 proto_tree_add_uint(icp_tree,hf_icp_request_nr, tvb, 4, 4,
194 options=tvb_get_ntohl(tvb, 8);
195 if ( (opcode == CODE_ICP_OP_QUERY) && ((options & 0x80000000 ) != 0) )
197 proto_tree_add_text(icp_tree, tvb,8,4,
198 "option: ICP_FLAG_HIT_OBJ");
200 if ( (opcode == CODE_ICP_OP_QUERY)&& ((options & 0x40000000 ) != 0) )
202 proto_tree_add_text(icp_tree, tvb,8,4,
203 "option:ICP_FLAG_SRC_RTT");
205 if ((opcode != CODE_ICP_OP_QUERY)&& ((options & 0x40000000 ) != 0))
207 option_data=tvb_get_ntohl(tvb, 12);
208 proto_tree_add_text(icp_tree, tvb,8,8,
209 "option: ICP_FLAG_SCR_RTT RTT=%u",
210 option_data & 0x0000ffff);
213 proto_tree_add_text(icp_tree, tvb, 16, 4,
214 "Sender Host IP address %s",
215 ip_to_str(tvb_get_ptr(tvb, 16, 4)));
217 payloadtf = proto_tree_add_text(icp_tree, tvb,
218 20, message_length - 20,
220 payload_tree = proto_item_add_subtree(payloadtf, ett_icp_payload);
221 dissect_icp_payload(tvb, 20, payload_tree, opcode);
225 proto_register_icp(void)
227 static hf_register_info hf[] = {
229 { "Opcode", "icp.opcode", FT_UINT8, BASE_HEX, VALS(opcode_vals),
233 { "Version", "icp.version", FT_UINT8, BASE_DEC, NULL,
237 { "Length", "icp.length", FT_UINT16, BASE_DEC, NULL,
240 { &hf_icp_request_nr,
241 { "Request Number", "icp.nr", FT_UINT32, BASE_DEC, NULL,
244 static gint *ett[] = {
249 proto_icp = proto_register_protocol("Internet Cache Protocol",
251 proto_register_field_array(proto_icp, hf, array_length(hf));
252 proto_register_subtree_array(ett, array_length(ett));
256 proto_reg_handoff_icp(void)
258 dissector_handle_t icp_handle;
260 icp_handle = create_dissector_handle(dissect_icp, proto_icp);
261 dissector_add("udp.port", UDP_PORT_ICP, icp_handle);