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.9 2000/05/31 05:07:48 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 static int proto_srvloc = -1;
63 static int hf_srvloc_version = -1;
64 static int hf_srvloc_function = -1;
65 static int hf_srvloc_flags = -1;
66 static int hf_srvloc_error = -1;
68 static gint ett_srvloc = -1;
69 static gint ett_srvloc_flags = -1;
71 #define TCP_PORT_SRVLOC 427
72 #define UDP_PORT_SRVLOC 427
74 /* Define function types */
85 #define SRVTYPERPLY 10
87 /* Create protocol header structure */
100 /* List to resolve function numbers to names */
102 static const value_string srvloc_functions[] = {
103 { SRVREQ, "Service Request" },
104 { SRVRPLY, "Service Reply" },
105 { SRVREG, "Service Registration" },
106 { SRVDEREG, "Service Deregister" },
107 { SRVACK, "Service Acknowledge" },
108 { ATTRRQST, "Attribute Request" },
109 { ATTRRPLY, "Attribute Reply" },
110 { DAADVERT, "DA Advertisement" },
111 { SRVTYPERQST, "Service Type Request" },
112 { SRVTYPERPLY, "Service Type Reply" },
115 /* List to resolve flag values to names */
118 /* Define flag masks */
126 /* Define Error Codes */
129 #define LANG_NOT_SPTD 1
130 #define PROT_PARSE_ERR 2
132 #define SCOPE_NOT_SPTD 4
133 #define CHRSET_NOT_UND 5
134 #define AUTH_ABSENT 6
135 #define AUTH_FAILED 7
137 /* List to resolve error codes to names */
139 static const value_string srvloc_errs[] = {
140 { SUCCESS, "No Error" },
141 { LANG_NOT_SPTD, "Language not supported" },
142 { PROT_PARSE_ERR, "Protocol parse error" },
143 { INVLD_REG, "Invalid registration" },
144 { SCOPE_NOT_SPTD, "Scope not supported" },
145 { CHRSET_NOT_UND, "Character set not understood" },
146 { AUTH_ABSENT, "Authentication absent" },
147 { AUTH_FAILED, "Authentication failed" },
151 dissect_authblk(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
158 seconds = pntohl(&pd[offset]) - 2208988800ul;
159 stamp = gmtime(&seconds);
160 floatsec = stamp->tm_sec + pntohl(&pd[offset + 4]) / 4294967296.0;
161 proto_tree_add_text(tree, NullTVB, offset, 8,
162 "Timestamp: %04d-%02d-%02d %02d:%02d:%07.4f UTC",
163 stamp->tm_year + 1900, stamp->tm_mon + 1,
164 stamp->tm_mday, stamp->tm_hour, stamp->tm_min,
166 proto_tree_add_text(tree, NullTVB, offset + 8, 2, "Block Structure Desciptor: %u",
167 pntohs(&pd[offset + 8]));
168 length = pntohs(&pd[offset + 10]);
169 proto_tree_add_text(tree, NullTVB, offset + 10, 2, "Authenticator length: %u",
172 proto_tree_add_text(tree, NullTVB, offset, length, "Authentication block: %s",
173 format_text(&pd[offset], length));
177 /* Packet dissection routine called by tcp & udp when port 427 detected */
180 dissect_srvloc(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
183 proto_tree *srvloc_tree, *srvloc_flags;
184 struct srvloc_hdr srvloc_hdr;
188 if (check_col(fd, COL_PROTOCOL))
189 col_add_str(fd, COL_PROTOCOL, "SRVLOC");
191 if (check_col(fd, COL_INFO))
192 col_add_str(fd, COL_INFO, val_to_str(pd[offset + 1], srvloc_functions, "Unknown Function (%d)"));
195 ti = proto_tree_add_item(tree, proto_srvloc, NullTVB, offset, END_OF_FRAME, FALSE);
196 srvloc_tree = proto_item_add_subtree(ti, ett_srvloc);
198 if ( END_OF_FRAME > sizeof(srvloc_hdr) ) {
199 memcpy( &srvloc_hdr, &pd[offset], sizeof(srvloc_hdr) );
200 srvloc_hdr.length = pntohs(&srvloc_hdr.length);
201 srvloc_hdr.encoding = pntohs(&srvloc_hdr.encoding);
202 srvloc_hdr.xid = pntohs(&srvloc_hdr.xid);
203 proto_tree_add_uint(srvloc_tree, hf_srvloc_version, NullTVB, offset, 1, srvloc_hdr.version);
204 proto_tree_add_uint(srvloc_tree, hf_srvloc_function, NullTVB, offset + 1, 1, srvloc_hdr.function);
205 proto_tree_add_text(srvloc_tree, NullTVB, offset + 2, 2, "Length: %d",srvloc_hdr.length);
206 tf = proto_tree_add_uint(srvloc_tree, hf_srvloc_flags, NullTVB, offset + 4, 1, srvloc_hdr.flags);
207 srvloc_flags = proto_item_add_subtree(tf, ett_srvloc_flags);
208 proto_tree_add_text(srvloc_flags, NullTVB, offset + 4, 0, "Overflow %d... .xxx", (srvloc_hdr.flags & FLAG_O) >> 7 );
209 proto_tree_add_text(srvloc_flags, NullTVB, offset + 4, 0, "Monolingual .%d.. .xxx", (srvloc_hdr.flags & FLAG_M) >> 6 );
210 proto_tree_add_text(srvloc_flags, NullTVB, offset + 4, 0, "URL Authentication Present ..%d. .xxx", (srvloc_hdr.flags & FLAG_U) >> 5 );
211 proto_tree_add_text(srvloc_flags, NullTVB, offset + 4, 0, "Attribute Authentication Present ...%d .xxx", (srvloc_hdr.flags & FLAG_A) >> 4 );
212 proto_tree_add_text(srvloc_flags, NullTVB, offset + 4, 0, "Fresh Service Entry .... %dxxx", (srvloc_hdr.flags & FLAG_F) >> 3 );
213 proto_tree_add_text(srvloc_tree, NullTVB, offset + 5, 1, "Dialect: %d",srvloc_hdr.dialect);
214 proto_tree_add_text(srvloc_tree, NullTVB, offset + 6, 2, "Language: %s", format_text(srvloc_hdr.language,2));
215 proto_tree_add_text(srvloc_tree, NullTVB, offset + 8, 2, "Encoding: %d", srvloc_hdr.encoding);
216 proto_tree_add_text(srvloc_tree, NullTVB, offset + 10, 2, "Transaction ID: %d", srvloc_hdr.xid);
219 proto_tree_add_text(srvloc_tree, NullTVB, offset, END_OF_FRAME, "Invalid Packet: Length less than header.");
222 if (( srvloc_hdr.length - 12 ) == END_OF_FRAME ) {
223 switch (srvloc_hdr.function) {
225 proto_tree_add_text(srvloc_tree, NullTVB, offset, 0, "Service Request");
226 length = pntohs(&pd[offset]);
227 proto_tree_add_text(srvloc_tree, NullTVB, offset, 2, "Previous Response List Length: %d", length);
229 proto_tree_add_text(srvloc_tree, NullTVB, offset, length, "Previous Response List: %s", format_text(&pd[offset], length));
231 length = pntohs(&pd[offset]);
232 proto_tree_add_text(srvloc_tree, NullTVB, offset, 2, "Predicate length: %d", length);
234 proto_tree_add_text(srvloc_tree, NullTVB, offset, length, "Predicate: %s", format_text(&pd[offset], length));
239 proto_tree_add_text(srvloc_tree, NullTVB, offset, 0, "Service Reply");
240 proto_tree_add_uint(srvloc_tree, hf_srvloc_error, NullTVB, offset, 2, pd[offset]);;
242 proto_tree_add_text(srvloc_tree, NullTVB, offset, 2, "URL Count: %d", pntohs(&pd[offset]));
244 for (count = pntohs(&pd[offset]) + 1; count > 0; count--, offset++) {
245 proto_tree_add_text(srvloc_tree, NullTVB, offset, 2, "URL lifetime: %d", pntohs(&pd[offset]));
247 length = pntohs(&pd[offset]);
248 proto_tree_add_text(srvloc_tree, NullTVB, offset, 2, "URL length: %d", length);
250 proto_tree_add_text(srvloc_tree, NullTVB, offset, length, "Service URL: %s", format_text(&pd[offset], length));
252 if ( (srvloc_hdr.flags & FLAG_U) == FLAG_U )
253 dissect_authblk(pd, offset, fd, srvloc_tree);
258 proto_tree_add_text(srvloc_tree, NullTVB, offset, 0, "Service Registration");
259 proto_tree_add_text(srvloc_tree, NullTVB, offset, 2, "URL lifetime: %d", pntohs(&pd[offset]));
261 length = pntohs(&pd[offset]);
262 proto_tree_add_text(srvloc_tree, NullTVB, offset, 2, "URL length: %d", length);
264 proto_tree_add_text(srvloc_tree, NullTVB, offset, length, "Service URL: %s", format_text(&pd[offset], length));
266 if ( (srvloc_hdr.flags & FLAG_U) == FLAG_U )
267 dissect_authblk(pd, offset, fd, srvloc_tree);
268 length = pntohs(&pd[offset]);
269 proto_tree_add_text(srvloc_tree, NullTVB, offset, 2, "Attribute List length: %d", length);
271 proto_tree_add_text(srvloc_tree, NullTVB, offset, length, "Attribute List: %s", format_text(&pd[offset], length));
273 if ( (srvloc_hdr.flags & FLAG_A) == FLAG_A )
274 dissect_authblk(pd, offset, fd, srvloc_tree);
278 proto_tree_add_text(srvloc_tree, NullTVB, offset, 0, "Service Deregister");
279 length = pntohs(&pd[offset]);
280 proto_tree_add_text(srvloc_tree, NullTVB, offset, 2, "URL length: %d", length);
282 proto_tree_add_text(srvloc_tree, NullTVB, offset, length, "Service URL: %s", format_text(&pd[offset], length));
284 if ( (srvloc_hdr.flags & FLAG_U) == FLAG_U )
285 dissect_authblk(pd, offset, fd, srvloc_tree);
286 length = pntohs(&pd[offset]);
287 proto_tree_add_text(srvloc_tree, NullTVB, offset, 2, "Attribute List length: %d", length);
289 proto_tree_add_text(srvloc_tree, NullTVB, offset, length, "Attribute List: %s", format_text(&pd[offset], length));
291 if ( (srvloc_hdr.flags & FLAG_A) == FLAG_A )
292 dissect_authblk(pd, offset, fd, srvloc_tree);
296 proto_tree_add_text(srvloc_tree, NullTVB, offset, 0, "Service Acknowledge");
297 proto_tree_add_uint(srvloc_tree, hf_srvloc_error, NullTVB, offset, 2, pd[offset]);;
302 proto_tree_add_text(srvloc_tree, NullTVB, offset, 0, "Attribute Request");
303 length = pntohs(&pd[offset]);
304 proto_tree_add_text(srvloc_tree, NullTVB, offset, 2, "Previous Response List Length: %d", length);
306 proto_tree_add_text(srvloc_tree, NullTVB, offset, length, "Previous Response List: %s", format_text(&pd[offset], length));
308 length = pntohs(&pd[offset]);
309 proto_tree_add_text(srvloc_tree, NullTVB, offset, 2, "URL length: %d", length);
311 proto_tree_add_text(srvloc_tree, NullTVB, offset, length, "Service URL: %s", format_text(&pd[offset], length));
313 length = pntohs(&pd[offset]);
314 proto_tree_add_text(srvloc_tree, NullTVB, offset, 2, "Scope List Length: %d", length);
316 proto_tree_add_text(srvloc_tree, NullTVB, offset, length, "Scope Response List: %s", format_text(&pd[offset], length));
318 length = pntohs(&pd[offset]);
319 proto_tree_add_text(srvloc_tree, NullTVB, offset, 2, "Attribute List length: %d", length);
321 proto_tree_add_text(srvloc_tree, NullTVB, offset, length, "Attribute List: %s", format_text(&pd[offset], length));
326 proto_tree_add_text(srvloc_tree, NullTVB, offset, 0, "Attribute Reply");
327 proto_tree_add_uint(srvloc_tree, hf_srvloc_error, NullTVB, offset, 2, pd[offset]);;
329 length = pntohs(&pd[offset]);
330 proto_tree_add_text(srvloc_tree, NullTVB, offset, 2, "Attribute List length: %d", length);
332 proto_tree_add_text(srvloc_tree, NullTVB, offset, length, "Attribute List: %s", format_text(&pd[offset], length));
334 if ( (srvloc_hdr.flags & FLAG_A) == FLAG_A )
335 dissect_authblk(pd, offset, fd, srvloc_tree);
339 proto_tree_add_text(srvloc_tree, NullTVB, offset, 0, "DA Advertisement");
340 proto_tree_add_uint(srvloc_tree, hf_srvloc_error, NullTVB, offset, 2, pd[offset]);;
342 length = pntohs(&pd[offset]);
343 proto_tree_add_text(srvloc_tree, NullTVB, offset, 2, "URL length: %d", length);
345 proto_tree_add_text(srvloc_tree, NullTVB, offset, length, "Service URL: %s", format_text(&pd[offset], length));
347 length = pntohs(&pd[offset]);
348 proto_tree_add_text(srvloc_tree, NullTVB, offset, 2, "Scope List Length: %d", length);
350 proto_tree_add_text(srvloc_tree, NullTVB, offset, length, "Scope Response List: %s", format_text(&pd[offset], length));
355 proto_tree_add_text(srvloc_tree, NullTVB, offset, 0, "Service Type Request");
356 length = pntohs(&pd[offset]);
357 proto_tree_add_text(srvloc_tree, NullTVB, offset, 2, "Previous Response List Length: %d", length);
359 proto_tree_add_text(srvloc_tree, NullTVB, offset, length, "Previous Response List: %s", format_text(&pd[offset], length));
361 length = pntohs(&pd[offset]);
362 proto_tree_add_text(srvloc_tree, NullTVB, offset, 2, "Naming Authority List length: %d", length);
364 proto_tree_add_text(srvloc_tree, NullTVB, offset, length, "Naming Authority List: %s", format_text(&pd[offset], length));
366 length = pntohs(&pd[offset]);
367 proto_tree_add_text(srvloc_tree, NullTVB, offset, 2, "Scope List Length: %d", length);
369 proto_tree_add_text(srvloc_tree, NullTVB, offset, length, "Scope Response List: %s", format_text(&pd[offset], length));
374 proto_tree_add_text(srvloc_tree, NullTVB, offset, 0, "Service Type Reply");
375 proto_tree_add_uint(srvloc_tree, hf_srvloc_error, NullTVB, offset, 2, pd[offset]);;
377 proto_tree_add_text(srvloc_tree, NullTVB, offset, 2, "Service Type Count: %d", pntohs(&pd[offset]));
379 for (count = pntohs(&pd[offset]) + 1; count > 0; count--, offset++) {
380 length = pntohs(&pd[offset]);
381 proto_tree_add_text(srvloc_tree, NullTVB, offset, 2, "Service Type List length: %d", length);
383 proto_tree_add_text(srvloc_tree, NullTVB, offset, length, "Service Type List: %s", format_text(&pd[offset], length));
389 proto_tree_add_text(srvloc_tree, NullTVB, offset, END_OF_FRAME, "Unknown Function Type");
391 } else { proto_tree_add_text(srvloc_tree, NullTVB, offset, END_OF_FRAME,"Invalid packet: Bad length value");
396 /* Register protocol with Ethereal. */
399 proto_register_srvloc(void)
401 static hf_register_info hf[] = {
402 { &hf_srvloc_version,
403 { "Version", "srvloc.version",
404 FT_UINT8, BASE_DEC, NULL, 0x0,
408 {&hf_srvloc_function,
409 {"Function", "srvloc.function",
410 FT_UINT8, BASE_DEC, VALS(srvloc_functions), 0x0,
415 {"Flags", "srvloc.flags",
416 FT_UINT8, BASE_HEX, NULL, 0x0,
421 {"Error Code", "srvloc.err",
422 FT_UINT8, BASE_DEC, VALS(srvloc_errs), 0x0,
427 static gint *ett[] = {
432 proto_srvloc = proto_register_protocol("Service Location Protocol", "srvloc");
433 proto_register_field_array(proto_srvloc, hf, array_length(hf));
434 proto_register_subtree_array(ett, array_length(ett));
438 proto_reg_handoff_srvloc(void)
440 dissector_add("tcp.port", TCP_PORT_SRVLOC, dissect_srvloc);
441 dissector_add("udp.port", UDP_PORT_SRVLOC, dissect_srvloc);