2 * Routines for SRVLOC (Service Location Protocol) packet dissection
3 * Copyright 1999, James Coe <jammer@cin.net>
5 * NOTE: This is Alpha software not all features have been verified yet.
6 * In particular I have not had an opportunity to see how it
7 * responds to SRVLOC over TCP.
9 * $Id: packet-srvloc.c,v 1.6 2000/01/22 02:00:24 guy Exp $
11 * Ethereal - Network traffic analyzer
12 * By Gerald Combs <gerald@zing.org>
13 * Copyright 1998 Gerald Combs
15 * Service Location Protocol is RFC 2165
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License
19 * as published by the Free Software Foundation; either version 2
20 * of the License, or (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
39 #ifdef HAVE_SYS_TYPES_H
40 # include <sys/types.h>
43 #ifdef HAVE_NETINET_IN_H
44 # include <netinet/in.h>
47 #ifdef NEED_SNPRINTF_H
53 # include "snprintf.h"
60 #include "packet-ipv6.h"
62 int proto_srvloc = -1;
63 int hf_srvloc_version = -1;
64 int hf_srvloc_function = -1;
65 int hf_srvloc_flags = -1;
66 int hf_srvloc_error = -1;
68 static gint ett_srvloc = -1;
69 gint ett_srvloc_flags = -1;
71 /* Define function types */
82 #define SRVTYPERPLY 10
84 /* Create protocol header structure */
97 /* List to resolve function numbers to names */
99 static const value_string srvloc_functions[] = {
100 { SRVREQ, "Service Request" },
101 { SRVRPLY, "Service Reply" },
102 { SRVREG, "Service Registration" },
103 { SRVDEREG, "Service Deregister" },
104 { SRVACK, "Service Acknowledge" },
105 { ATTRRQST, "Attribute Request" },
106 { ATTRRPLY, "Attribute Reply" },
107 { DAADVERT, "DA Advertisement" },
108 { SRVTYPERQST, "Service Type Request" },
109 { SRVTYPERPLY, "Service Type Reply" },
112 /* List to resolve flag values to names */
115 /* Define flag masks */
123 /* Define Error Codes */
126 #define LANG_NOT_SPTD 1
127 #define PROT_PARSE_ERR 2
129 #define SCOPE_NOT_SPTD 4
130 #define CHRSET_NOT_UND 5
131 #define AUTH_ABSENT 6
132 #define AUTH_FAILED 7
134 /* List to resolve error codes to names */
136 static const value_string srvloc_errs[] = {
137 { SUCCESS, "No Error" },
138 { LANG_NOT_SPTD, "Language not supported" },
139 { PROT_PARSE_ERR, "Protocol parse error" },
140 { INVLD_REG, "Invalid registration" },
141 { SCOPE_NOT_SPTD, "Scope not supported" },
142 { CHRSET_NOT_UND, "Character set not understood" },
143 { AUTH_ABSENT, "Authentication absent" },
144 { AUTH_FAILED, "Authentication failed" },
148 dissect_authblk(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
155 seconds = pntohl(&pd[offset]) - 2208988800ul;
156 stamp = gmtime(&seconds);
157 floatsec = stamp->tm_sec + pntohl(&pd[offset + 4]) / 4294967296.0;
158 proto_tree_add_text(tree, offset, 8,
159 "Timestamp: %04d-%02d-%02d %02d:%02d:%07.4f UTC",
160 stamp->tm_year + 1900, stamp->tm_mon + 1,
161 stamp->tm_mday, stamp->tm_hour, stamp->tm_min,
163 proto_tree_add_text(tree, offset + 8, 2, "Block Structure Desciptor: %u",
164 pntohs(&pd[offset + 8]));
165 length = pntohs(&pd[offset + 10]);
166 proto_tree_add_text(tree, offset + 10, 2, "Authenticator length: %u",
169 proto_tree_add_text(tree, offset, length, "Authentication block: %s",
170 format_text(&pd[offset], length));
174 /* Packet dissection routine called by tcp & udp when port 427 detected */
177 dissect_srvloc(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
180 proto_tree *srvloc_tree, *srvloc_flags;
181 struct srvloc_hdr srvloc_hdr;
185 if (check_col(fd, COL_PROTOCOL))
186 col_add_str(fd, COL_PROTOCOL, "SRVLOC");
188 if (check_col(fd, COL_INFO))
189 col_add_str(fd, COL_INFO, val_to_str(pd[offset + 1], srvloc_functions, "Unknown Function (%d)"));
192 ti = proto_tree_add_item(tree, proto_srvloc, offset, END_OF_FRAME, NULL);
193 srvloc_tree = proto_item_add_subtree(ti, ett_srvloc);
195 if ( END_OF_FRAME > sizeof(srvloc_hdr) ) {
196 memcpy( &srvloc_hdr, &pd[offset], sizeof(srvloc_hdr) );
197 srvloc_hdr.length = pntohs(&srvloc_hdr.length);
198 srvloc_hdr.encoding = pntohs(&srvloc_hdr.encoding);
199 srvloc_hdr.xid = pntohs(&srvloc_hdr.xid);
200 proto_tree_add_item(srvloc_tree, hf_srvloc_version, offset, 1, srvloc_hdr.version);
201 proto_tree_add_item(srvloc_tree, hf_srvloc_function, offset + 1, 1, srvloc_hdr.function);
202 proto_tree_add_text(srvloc_tree, offset + 2, 2, "Length: %d",srvloc_hdr.length);
203 tf = proto_tree_add_item(srvloc_tree, hf_srvloc_flags, offset + 4, 1, srvloc_hdr.flags);
204 srvloc_flags = proto_item_add_subtree(tf, ett_srvloc_flags);
205 proto_tree_add_text(srvloc_flags, offset + 4, 0, "Overflow %d... .xxx", (srvloc_hdr.flags & FLAG_O) >> 7 );
206 proto_tree_add_text(srvloc_flags, offset + 4, 0, "Monolingual .%d.. .xxx", (srvloc_hdr.flags & FLAG_M) >> 6 );
207 proto_tree_add_text(srvloc_flags, offset + 4, 0, "URL Authentication Present ..%d. .xxx", (srvloc_hdr.flags & FLAG_U) >> 5 );
208 proto_tree_add_text(srvloc_flags, offset + 4, 0, "Attribute Authentication Present ...%d .xxx", (srvloc_hdr.flags & FLAG_A) >> 4 );
209 proto_tree_add_text(srvloc_flags, offset + 4, 0, "Fresh Service Entry .... %dxxx", (srvloc_hdr.flags & FLAG_F) >> 3 );
210 proto_tree_add_text(srvloc_tree, offset + 5, 1, "Dialect: %d",srvloc_hdr.dialect);
211 proto_tree_add_text(srvloc_tree, offset + 6, 2, "Language: %s", format_text(srvloc_hdr.language,2));
212 proto_tree_add_text(srvloc_tree, offset + 8, 2, "Encoding: %d", srvloc_hdr.encoding);
213 proto_tree_add_text(srvloc_tree, offset + 10, 2, "Transaction ID: %d", srvloc_hdr.xid);
216 proto_tree_add_text(srvloc_tree, offset, END_OF_FRAME, "Invalid Packet: Length less than header.");
219 if (( srvloc_hdr.length - 12 ) == END_OF_FRAME ) {
220 switch (srvloc_hdr.function) {
222 proto_tree_add_text(srvloc_tree, offset, 0, "Service Request");
223 length = pntohs(&pd[offset]);
224 proto_tree_add_text(srvloc_tree, offset, 2, "Previous Response List Length: %d", length);
226 proto_tree_add_text(srvloc_tree, offset, length, "Previous Response List: %s", format_text(&pd[offset], length));
228 length = pntohs(&pd[offset]);
229 proto_tree_add_text(srvloc_tree, offset, 2, "Predicate length: %d", length);
231 proto_tree_add_text(srvloc_tree, offset, length, "Predicate: %s", format_text(&pd[offset], length));
236 proto_tree_add_text(srvloc_tree, offset, 0, "Service Reply");
237 proto_tree_add_item(srvloc_tree, hf_srvloc_error, offset, 2, pd[offset]);;
239 proto_tree_add_text(srvloc_tree, offset, 2, "URL Count: %d", pntohs(&pd[offset]));
241 for (count = pntohs(&pd[offset]) + 1; count > 0; count--, offset++) {
242 proto_tree_add_text(srvloc_tree, offset, 2, "URL lifetime: %d", pntohs(&pd[offset]));
244 length = pntohs(&pd[offset]);
245 proto_tree_add_text(srvloc_tree, offset, 2, "URL length: %d", length);
247 proto_tree_add_text(srvloc_tree, offset, length, "Service URL: %s", format_text(&pd[offset], length));
249 if ( (srvloc_hdr.flags & FLAG_U) == FLAG_U )
250 dissect_authblk(pd, offset, fd, srvloc_tree);
255 proto_tree_add_text(srvloc_tree, offset, 0, "Service Registration");
256 proto_tree_add_text(srvloc_tree, offset, 2, "URL lifetime: %d", pntohs(&pd[offset]));
258 length = pntohs(&pd[offset]);
259 proto_tree_add_text(srvloc_tree, offset, 2, "URL length: %d", length);
261 proto_tree_add_text(srvloc_tree, offset, length, "Service URL: %s", format_text(&pd[offset], length));
263 if ( (srvloc_hdr.flags & FLAG_U) == FLAG_U )
264 dissect_authblk(pd, offset, fd, srvloc_tree);
265 length = pntohs(&pd[offset]);
266 proto_tree_add_text(srvloc_tree, offset, 2, "Attribute List length: %d", length);
268 proto_tree_add_text(srvloc_tree, offset, length, "Attribute List: %s", format_text(&pd[offset], length));
270 if ( (srvloc_hdr.flags & FLAG_A) == FLAG_A )
271 dissect_authblk(pd, offset, fd, srvloc_tree);
275 proto_tree_add_text(srvloc_tree, offset, 0, "Service Deregister");
276 length = pntohs(&pd[offset]);
277 proto_tree_add_text(srvloc_tree, offset, 2, "URL length: %d", length);
279 proto_tree_add_text(srvloc_tree, offset, length, "Service URL: %s", format_text(&pd[offset], length));
281 if ( (srvloc_hdr.flags & FLAG_U) == FLAG_U )
282 dissect_authblk(pd, offset, fd, srvloc_tree);
283 length = pntohs(&pd[offset]);
284 proto_tree_add_text(srvloc_tree, offset, 2, "Attribute List length: %d", length);
286 proto_tree_add_text(srvloc_tree, offset, length, "Attribute List: %s", format_text(&pd[offset], length));
288 if ( (srvloc_hdr.flags & FLAG_A) == FLAG_A )
289 dissect_authblk(pd, offset, fd, srvloc_tree);
293 proto_tree_add_text(srvloc_tree, offset, 0, "Service Acknowledge");
294 proto_tree_add_item(srvloc_tree, hf_srvloc_error, offset, 2, pd[offset]);;
299 proto_tree_add_text(srvloc_tree, offset, 0, "Attribute Request");
300 length = pntohs(&pd[offset]);
301 proto_tree_add_text(srvloc_tree, offset, 2, "Previous Response List Length: %d", length);
303 proto_tree_add_text(srvloc_tree, offset, length, "Previous Response List: %s", format_text(&pd[offset], length));
305 length = pntohs(&pd[offset]);
306 proto_tree_add_text(srvloc_tree, offset, 2, "URL length: %d", length);
308 proto_tree_add_text(srvloc_tree, offset, length, "Service URL: %s", format_text(&pd[offset], length));
310 length = pntohs(&pd[offset]);
311 proto_tree_add_text(srvloc_tree, offset, 2, "Scope List Length: %d", length);
313 proto_tree_add_text(srvloc_tree, offset, length, "Scope Response List: %s", format_text(&pd[offset], length));
315 length = pntohs(&pd[offset]);
316 proto_tree_add_text(srvloc_tree, offset, 2, "Attribute List length: %d", length);
318 proto_tree_add_text(srvloc_tree, offset, length, "Attribute List: %s", format_text(&pd[offset], length));
323 proto_tree_add_text(srvloc_tree, offset, 0, "Attribute Reply");
324 proto_tree_add_item(srvloc_tree, hf_srvloc_error, offset, 2, pd[offset]);;
326 length = pntohs(&pd[offset]);
327 proto_tree_add_text(srvloc_tree, offset, 2, "Attribute List length: %d", length);
329 proto_tree_add_text(srvloc_tree, offset, length, "Attribute List: %s", format_text(&pd[offset], length));
331 if ( (srvloc_hdr.flags & FLAG_A) == FLAG_A )
332 dissect_authblk(pd, offset, fd, srvloc_tree);
336 proto_tree_add_text(srvloc_tree, offset, 0, "DA Advertisement");
337 proto_tree_add_item(srvloc_tree, hf_srvloc_error, offset, 2, pd[offset]);;
339 length = pntohs(&pd[offset]);
340 proto_tree_add_text(srvloc_tree, offset, 2, "URL length: %d", length);
342 proto_tree_add_text(srvloc_tree, offset, length, "Service URL: %s", format_text(&pd[offset], length));
344 length = pntohs(&pd[offset]);
345 proto_tree_add_text(srvloc_tree, offset, 2, "Scope List Length: %d", length);
347 proto_tree_add_text(srvloc_tree, offset, length, "Scope Response List: %s", format_text(&pd[offset], length));
352 proto_tree_add_text(srvloc_tree, offset, 0, "Service Type Request");
353 length = pntohs(&pd[offset]);
354 proto_tree_add_text(srvloc_tree, offset, 2, "Previous Response List Length: %d", length);
356 proto_tree_add_text(srvloc_tree, offset, length, "Previous Response List: %s", format_text(&pd[offset], length));
358 length = pntohs(&pd[offset]);
359 proto_tree_add_text(srvloc_tree, offset, 2, "Naming Authority List length: %d", length);
361 proto_tree_add_text(srvloc_tree, offset, length, "Naming Authority List: %s", format_text(&pd[offset], length));
363 length = pntohs(&pd[offset]);
364 proto_tree_add_text(srvloc_tree, offset, 2, "Scope List Length: %d", length);
366 proto_tree_add_text(srvloc_tree, offset, length, "Scope Response List: %s", format_text(&pd[offset], length));
371 proto_tree_add_text(srvloc_tree, offset, 0, "Service Type Reply");
372 proto_tree_add_item(srvloc_tree, hf_srvloc_error, offset, 2, pd[offset]);;
374 proto_tree_add_text(srvloc_tree, offset, 2, "Service Type Count: %d", pntohs(&pd[offset]));
376 for (count = pntohs(&pd[offset]) + 1; count > 0; count--, offset++) {
377 length = pntohs(&pd[offset]);
378 proto_tree_add_text(srvloc_tree, offset, 2, "Service Type List length: %d", length);
380 proto_tree_add_text(srvloc_tree, offset, length, "Service Type List: %s", format_text(&pd[offset], length));
386 proto_tree_add_text(srvloc_tree, offset, END_OF_FRAME, "Unknown Function Type");
388 } else { proto_tree_add_text(srvloc_tree, offset, END_OF_FRAME,"Invalid packet: Bad length value");
393 /* Register protocol with Ethereal. */
396 proto_register_srvloc(void)
398 static hf_register_info hf[] = {
399 { &hf_srvloc_version,
400 { "Version", "srvloc.version",
401 FT_UINT8, BASE_DEC, NULL, 0x0,
405 {&hf_srvloc_function,
406 {"Function", "srvloc.function",
407 FT_UINT8, BASE_DEC, VALS(srvloc_functions), 0x0,
412 {"Flags", "srvloc.flags",
413 FT_UINT8, BASE_HEX, NULL, 0x0,
418 {"Error Code", "srvloc.err",
419 FT_UINT8, BASE_DEC, VALS(srvloc_errs), 0x0,
424 static gint *ett[] = {
429 proto_srvloc = proto_register_protocol("Service Location Protocol", "srvloc");
430 proto_register_field_array(proto_srvloc, hf, array_length(hf));
431 proto_register_subtree_array(ett, array_length(ett));