2 * Routines for ICP (internet cache protocol) packet disassembly
5 * $Id: packet-icp.c,v 1.18 2001/06/18 02:17:46 guy Exp $
7 * Ethereal - Network traffic analyzer
9 * Copyright 1999 Peter Torvals
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 #define MAX_TEXTBUF_LENGTH 600
31 #ifdef HAVE_SYS_TYPES_H
32 # include <sys/types.h>
35 #ifdef HAVE_NETINET_IN_H
36 #include <netinet/in.h>
46 static int proto_icp=-1;
47 static int hf_icp_length=-1;
48 static int hf_icp_opcode=-1;
49 static int hf_icp_version=-1;
50 static int hf_icp_request_nr=-1;
52 static gint ett_icp = -1;
53 static gint ett_icp_payload = -1;
55 #define UDP_PORT_ICP 3130
57 #define CODE_ICP_OP_QUERY 1
58 #define CODE_ICP_OP_INVALID 0
59 #define CODE_ICP_OP_HIT 2
60 #define CODE_ICP_OP_MISS 3
61 #define CODE_ICP_OP_ERR 4
62 #define CODE_ICP_OP_SEND 5
63 #define CODE_ICP_OP_SENDA 6
64 #define CODE_ICP_OP_DATABEG 7
65 #define CODE_ICP_OP_DATA 8
66 #define CODE_ICP_OP_DATAEND 9
67 #define CODE_ICP_OP_SECHO 10
68 #define CODE_ICP_OP_DECHO 11
69 #define CODE_ICP_OP_MISS_NOFETCH 21
70 #define CODE_ICP_OP_DENIED 22
71 #define CODE_ICP_OP_HIT_OBJ 23
73 static value_string opcode_vals[] = {
74 { CODE_ICP_OP_INVALID , "ICP_INVALID" },
75 { CODE_ICP_OP_QUERY , "ICP_QUERY" },
76 { CODE_ICP_OP_HIT , "ICP_HIT" },
77 { CODE_ICP_OP_MISS , "ICP_MISS" },
78 { CODE_ICP_OP_ERR , "ICP_ERR" },
79 { CODE_ICP_OP_SEND, "ICP_SEND" },
80 { CODE_ICP_OP_SENDA, "ICP_SENDA"},
81 { CODE_ICP_OP_DATABEG, "ICP_DATABEG"},
82 { CODE_ICP_OP_DATA, "ICP_DATA"},
83 { CODE_ICP_OP_DATAEND, "ICP_DATA_END"},
84 { CODE_ICP_OP_SECHO , "ICP_SECHO"},
85 { CODE_ICP_OP_DECHO , "ICP_DECHO"},
86 { CODE_ICP_OP_MISS_NOFETCH , "ICP_MISS_NOFETCH"},
87 { CODE_ICP_OP_DENIED , "ICP_DENIED"},
88 { CODE_ICP_OP_HIT_OBJ , "ICP_HIT_OBJ"},
92 static void dissect_icp_payload(tvbuff_t *tvb, int offset,
93 proto_tree *pload_tree, guint8 opcode)
100 case CODE_ICP_OP_QUERY:
101 /* 4 byte requester host address */
102 proto_tree_add_text(pload_tree, tvb,offset,4,
103 "Requester Host Address %s",
104 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
107 /* null terminated URL */
108 stringlength = tvb_strsize(tvb, offset);
109 proto_tree_add_text(pload_tree, tvb, offset, stringlength,
110 "URL: %s", tvb_get_ptr(tvb, offset, stringlength));
113 case CODE_ICP_OP_SECHO:
114 case CODE_ICP_OP_DECHO:
115 case CODE_ICP_OP_HIT:
116 case CODE_ICP_OP_MISS:
117 case CODE_ICP_OP_ERR:
118 case CODE_ICP_OP_MISS_NOFETCH:
119 case CODE_ICP_OP_DENIED:
120 stringlength = tvb_strsize(tvb, offset);
121 proto_tree_add_text(pload_tree, tvb, offset, stringlength,
122 "URL: %s", tvb_get_ptr(tvb, offset, stringlength));
125 case CODE_ICP_OP_HIT_OBJ:
126 /* null terminated URL */
127 stringlength = tvb_strsize(tvb, offset);
128 proto_tree_add_text(pload_tree, tvb, offset, stringlength,
129 "URL: %s", tvb_get_ptr(tvb, offset, stringlength));
130 offset += stringlength;
132 /* 2 byte object size */
133 /* object data not recommended by standard*/
134 objectlength=tvb_get_ntohs(tvb, offset);
135 proto_tree_add_text(pload_tree, tvb,offset,2,"Object length: %u", objectlength);
138 /* object data not recommended by standard*/
139 proto_tree_add_text(pload_tree, tvb,offset,objectlength,"Object data");
140 if (objectlength > tvb_reported_length_remaining(tvb, offset))
142 proto_tree_add_text(pload_tree, tvb,offset,0,
143 "Packet is fragmented, rest of object is in next udp packet");
151 static void dissect_icp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
153 proto_tree *icp_tree , *payload_tree;
154 proto_item *ti , *payloadtf;
156 guint16 message_length;
157 guint32 request_number;
161 if (check_col(pinfo->fd, COL_PROTOCOL))
162 col_set_str(pinfo->fd, COL_PROTOCOL, "ICP");
163 if (check_col(pinfo->fd, COL_INFO))
164 col_clear(pinfo->fd, COL_INFO);
166 opcode=tvb_get_guint8(tvb, 0);
167 message_length=tvb_get_ntohs(tvb, 2);
168 request_number=tvb_get_ntohl(tvb, 4);
170 if (check_col(pinfo->fd, COL_INFO))
172 col_add_fstr(pinfo->fd,COL_INFO,"Opcode: %s (%u), Req Nr: %u",
173 val_to_str(opcode, opcode_vals, "Unknown"), opcode,
180 ti = proto_tree_add_item(tree,proto_icp, tvb, 0, message_length, FALSE);
181 icp_tree = proto_item_add_subtree(ti, ett_icp);
183 proto_tree_add_uint(icp_tree,hf_icp_opcode, tvb, 0, 1, opcode);
185 proto_tree_add_item(icp_tree,hf_icp_version, tvb, 1, 1, FALSE);
187 proto_tree_add_uint(icp_tree,hf_icp_length, tvb, 2, 2, message_length);
189 proto_tree_add_uint(icp_tree,hf_icp_request_nr, tvb, 4, 4,
192 options=tvb_get_ntohl(tvb, 8);
193 if ( (opcode == CODE_ICP_OP_QUERY) && ((options & 0x80000000 ) != 0) )
195 proto_tree_add_text(icp_tree, tvb,8,4,
196 "option: ICP_FLAG_HIT_OBJ");
198 if ( (opcode == CODE_ICP_OP_QUERY)&& ((options & 0x40000000 ) != 0) )
200 proto_tree_add_text(icp_tree, tvb,8,4,
201 "option:ICP_FLAG_SRC_RTT");
203 if ((opcode != CODE_ICP_OP_QUERY)&& ((options & 0x40000000 ) != 0))
205 option_data=tvb_get_ntohl(tvb, 12);
206 proto_tree_add_text(icp_tree, tvb,8,8,
207 "option: ICP_FLAG_SCR_RTT RTT=%u",
208 option_data & 0x0000ffff);
211 proto_tree_add_text(icp_tree, tvb, 16, 4,
212 "Sender Host IP address %s",
213 ip_to_str(tvb_get_ptr(tvb, 16, 4)));
215 payloadtf = proto_tree_add_text(icp_tree, tvb,
216 20, message_length - 20,
218 payload_tree = proto_item_add_subtree(payloadtf, ett_icp_payload);
219 dissect_icp_payload(tvb, 20, payload_tree, opcode);
223 proto_register_icp(void)
225 static hf_register_info hf[] = {
227 { "Opcode", "icp.opcode", FT_UINT8, BASE_HEX, VALS(opcode_vals),
231 { "Version", "icp.version", FT_UINT8, BASE_DEC, NULL,
235 { "Length", "icp.length", FT_UINT16, BASE_DEC, NULL,
238 { &hf_icp_request_nr,
239 { "Request Number", "icp.nr", FT_UINT32, BASE_DEC, NULL,
242 static gint *ett[] = {
247 proto_icp = proto_register_protocol("Internet Cache Protocol",
249 proto_register_field_array(proto_icp, hf, array_length(hf));
250 proto_register_subtree_array(ett, array_length(ett));
254 proto_reg_handoff_icp(void)
256 dissector_add("udp.port", UDP_PORT_ICP, dissect_icp, proto_icp);