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.3 1999/12/15 01:48:58 guy Exp $
11 * Ethereal - Network traffic analyzer
12 * By Gerald Combs <gerald@unicom.net>
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"
59 #include "packet-ipv6.h"
61 int proto_srvloc = -1;
62 int hf_srvloc_version = -1;
63 int hf_srvloc_function = -1;
64 int hf_srvloc_flags = -1;
65 int hf_srvloc_error = -1;
67 static gint ett_srvloc = -1;
68 gint ett_srvloc_flags = -1;
70 /* Define function types */
81 #define SRVTYPERPLY 10
83 /* Create protocol header structure */
96 /* List to resolve function numbers to names */
98 static const value_string srvloc_functions[] = {
99 { SRVREQ, "Service Request" },
100 { SRVRPLY, "Service Reply" },
101 { SRVREG, "Service Registration" },
102 { SRVDEREG, "Service Deregister" },
103 { SRVACK, "Service Acknowledge" },
104 { ATTRRQST, "Attribute Request" },
105 { ATTRRPLY, "Attribute Reply" },
106 { DAADVERT, "DA Advertisement" },
107 { SRVTYPERQST, "Service Type Request" },
108 { SRVTYPERPLY, "Service Type Reply" },
111 /* List to resolve flag values to names */
114 /* Define flag masks */
122 /* Define Error Codes */
125 #define LANG_NOT_SPTD 1
126 #define PROT_PARSE_ERR 2
128 #define SCOPE_NOT_SPTD 4
129 #define CHRSET_NOT_UND 5
130 #define AUTH_ABSENT 6
131 #define AUTH_FAILED 7
133 /* List to resolve error codes to names */
135 static const value_string srvloc_errs[] = {
136 { SUCCESS, "No Error" },
137 { LANG_NOT_SPTD, "Language not supported" },
138 { PROT_PARSE_ERR, "Protocol parse error" },
139 { INVLD_REG, "Invalid registration" },
140 { SCOPE_NOT_SPTD, "Scope not supported" },
141 { CHRSET_NOT_UND, "Character set not understood" },
142 { AUTH_ABSENT, "Authentication absent" },
143 { AUTH_FAILED, "Authentication failed" },
147 dissect_authblk(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
154 seconds = pntohl(&pd[offset]) - 2208988800ul;
155 stamp = gmtime(&seconds);
156 floatsec = stamp->tm_sec + pntohl(&pd[offset + 4]) / 4294967296.0;
157 proto_tree_add_text(tree, offset, 8,
158 "Timestamp: %04d-%02d-%02d %02d:%02d:%07.4f UTC",
159 stamp->tm_year + 1900, stamp->tm_mon, stamp->tm_mday,
160 stamp->tm_hour, stamp->tm_min, floatsec);
161 proto_tree_add_text(tree, offset + 8, 2, "Block Structure Desciptor: %u",
162 pntohs(&pd[offset + 8]));
163 length = pntohs(&pd[offset + 10]);
164 proto_tree_add_text(tree, offset + 10, 2, "Authenticator length: %u",
167 proto_tree_add_text(tree, offset, length, "Authentication block: %s",
168 format_text(&pd[offset], length));
172 /* Packet dissection routine called by tcp & udp when port 427 detected */
175 dissect_srvloc(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
178 proto_tree *srvloc_tree, *srvloc_flags;
179 struct srvloc_hdr srvloc_hdr;
183 if (check_col(fd, COL_PROTOCOL))
184 col_add_str(fd, COL_PROTOCOL, "SRVLOC");
186 if (check_col(fd, COL_INFO))
187 col_add_str(fd, COL_INFO, val_to_str(pd[offset + 1], srvloc_functions, "Unknown Function (%d)"));
190 ti = proto_tree_add_item(tree, proto_srvloc, offset, END_OF_FRAME, NULL);
191 srvloc_tree = proto_item_add_subtree(ti, ett_srvloc);
193 if ( END_OF_FRAME > sizeof(srvloc_hdr) ) {
194 memcpy( &srvloc_hdr, &pd[offset], sizeof(srvloc_hdr) );
195 srvloc_hdr.length = pntohs(&srvloc_hdr.length);
196 srvloc_hdr.encoding = pntohs(&srvloc_hdr.encoding);
197 srvloc_hdr.xid = pntohs(&srvloc_hdr.xid);
198 proto_tree_add_item(srvloc_tree, hf_srvloc_version, offset, 1, srvloc_hdr.version);
199 proto_tree_add_item(srvloc_tree, hf_srvloc_function, offset + 1, 1, srvloc_hdr.function);
200 proto_tree_add_text(srvloc_tree, offset + 2, 2, "Length: %d",srvloc_hdr.length);
201 tf = proto_tree_add_item(srvloc_tree, hf_srvloc_flags, offset + 4, 1, srvloc_hdr.flags);
202 srvloc_flags = proto_item_add_subtree(tf, ett_srvloc_flags);
203 proto_tree_add_text(srvloc_flags, offset + 4, 0, "Overflow %d... .xxx", (srvloc_hdr.flags & FLAG_O) >> 7 );
204 proto_tree_add_text(srvloc_flags, offset + 4, 0, "Monolingual .%d.. .xxx", (srvloc_hdr.flags & FLAG_M) >> 6 );
205 proto_tree_add_text(srvloc_flags, offset + 4, 0, "URL Authentication Present ..%d. .xxx", (srvloc_hdr.flags & FLAG_U) >> 5 );
206 proto_tree_add_text(srvloc_flags, offset + 4, 0, "Attribute Authentication Present ...%d .xxx", (srvloc_hdr.flags & FLAG_A) >> 4 );
207 proto_tree_add_text(srvloc_flags, offset + 4, 0, "Fresh Service Entry .... %dxxx", (srvloc_hdr.flags & FLAG_F) >> 3 );
208 proto_tree_add_text(srvloc_tree, offset + 5, 1, "Dialect: %d",srvloc_hdr.dialect);
209 proto_tree_add_text(srvloc_tree, offset + 6, 2, "Language: %s", format_text(srvloc_hdr.language,2));
210 proto_tree_add_text(srvloc_tree, offset + 8, 2, "Encoding: %d", srvloc_hdr.encoding);
211 proto_tree_add_text(srvloc_tree, offset + 10, 2, "Transaction ID: %d", srvloc_hdr.xid);
214 proto_tree_add_text(srvloc_tree, offset, END_OF_FRAME, "Invalid Packet: Length less than header.");
217 if (( srvloc_hdr.length - 12 ) == END_OF_FRAME ) {
218 switch (srvloc_hdr.function) {
220 proto_tree_add_text(srvloc_tree, offset, 0, "Service Request");
221 length = pntohs(&pd[offset]);
222 proto_tree_add_text(srvloc_tree, offset, 2, "Previous Response List Length: %d", length);
224 proto_tree_add_text(srvloc_tree, offset, length, "Previous Response List: %s", format_text(&pd[offset], length));
226 length = pntohs(&pd[offset]);
227 proto_tree_add_text(srvloc_tree, offset, 2, "Predicate length: %d", length);
229 proto_tree_add_text(srvloc_tree, offset, length, "Predicate: %s", format_text(&pd[offset], length));
234 proto_tree_add_text(srvloc_tree, offset, 0, "Service Reply");
235 proto_tree_add_item(srvloc_tree, hf_srvloc_error, offset, 2, pd[offset]);;
237 proto_tree_add_text(srvloc_tree, offset, 2, "URL Count: %d", pntohs(&pd[offset]));
239 for (count = pntohs(&pd[offset]) + 1; count > 0; count--, offset++) {
240 proto_tree_add_text(srvloc_tree, offset, 2, "URL lifetime: %d", pntohs(&pd[offset]));
242 length = pntohs(&pd[offset]);
243 proto_tree_add_text(srvloc_tree, offset, 2, "URL length: %d", length);
245 proto_tree_add_text(srvloc_tree, offset, length, "Service URL: %s", format_text(&pd[offset], length));
247 if ( (srvloc_hdr.flags & FLAG_U) == FLAG_U )
248 dissect_authblk(pd, offset, fd, srvloc_tree);
253 proto_tree_add_text(srvloc_tree, offset, 0, "Service Registration");
254 proto_tree_add_text(srvloc_tree, offset, 2, "URL lifetime: %d", pntohs(&pd[offset]));
256 length = pntohs(&pd[offset]);
257 proto_tree_add_text(srvloc_tree, offset, 2, "URL length: %d", length);
259 proto_tree_add_text(srvloc_tree, offset, length, "Service URL: %s", format_text(&pd[offset], length));
261 if ( (srvloc_hdr.flags & FLAG_U) == FLAG_U )
262 dissect_authblk(pd, offset, fd, srvloc_tree);
263 length = pntohs(&pd[offset]);
264 proto_tree_add_text(srvloc_tree, offset, 2, "Attribute List length: %d", length);
266 proto_tree_add_text(srvloc_tree, offset, length, "Attribute List: %s", format_text(&pd[offset], length));
268 if ( (srvloc_hdr.flags & FLAG_A) == FLAG_A )
269 dissect_authblk(pd, offset, fd, srvloc_tree);
273 proto_tree_add_text(srvloc_tree, offset, 0, "Service Deregister");
274 length = pntohs(&pd[offset]);
275 proto_tree_add_text(srvloc_tree, offset, 2, "URL length: %d", length);
277 proto_tree_add_text(srvloc_tree, offset, length, "Service URL: %s", format_text(&pd[offset], length));
279 if ( (srvloc_hdr.flags & FLAG_U) == FLAG_U )
280 dissect_authblk(pd, offset, fd, srvloc_tree);
281 length = pntohs(&pd[offset]);
282 proto_tree_add_text(srvloc_tree, offset, 2, "Attribute List length: %d", length);
284 proto_tree_add_text(srvloc_tree, offset, length, "Attribute List: %s", format_text(&pd[offset], length));
286 if ( (srvloc_hdr.flags & FLAG_A) == FLAG_A )
287 dissect_authblk(pd, offset, fd, srvloc_tree);
291 proto_tree_add_text(srvloc_tree, offset, 0, "Service Acknowledge");
292 proto_tree_add_item(srvloc_tree, hf_srvloc_error, offset, 2, pd[offset]);;
297 proto_tree_add_text(srvloc_tree, offset, 0, "Attribute Request");
298 length = pntohs(&pd[offset]);
299 proto_tree_add_text(srvloc_tree, offset, 2, "Previous Response List Length: %d", length);
301 proto_tree_add_text(srvloc_tree, offset, length, "Previous Response List: %s", format_text(&pd[offset], length));
303 length = pntohs(&pd[offset]);
304 proto_tree_add_text(srvloc_tree, offset, 2, "URL length: %d", length);
306 proto_tree_add_text(srvloc_tree, offset, length, "Service URL: %s", format_text(&pd[offset], length));
308 length = pntohs(&pd[offset]);
309 proto_tree_add_text(srvloc_tree, offset, 2, "Scope List Length: %d", length);
311 proto_tree_add_text(srvloc_tree, offset, length, "Scope Response List: %s", format_text(&pd[offset], length));
313 length = pntohs(&pd[offset]);
314 proto_tree_add_text(srvloc_tree, offset, 2, "Attribute List length: %d", length);
316 proto_tree_add_text(srvloc_tree, offset, length, "Attribute List: %s", format_text(&pd[offset], length));
321 proto_tree_add_text(srvloc_tree, offset, 0, "Attribute Reply");
322 proto_tree_add_item(srvloc_tree, hf_srvloc_error, offset, 2, pd[offset]);;
324 length = pntohs(&pd[offset]);
325 proto_tree_add_text(srvloc_tree, offset, 2, "Attribute List length: %d", length);
327 proto_tree_add_text(srvloc_tree, offset, length, "Attribute List: %s", format_text(&pd[offset], length));
329 if ( (srvloc_hdr.flags & FLAG_A) == FLAG_A )
330 dissect_authblk(pd, offset, fd, srvloc_tree);
334 proto_tree_add_text(srvloc_tree, offset, 0, "DA Advertisement");
335 proto_tree_add_item(srvloc_tree, hf_srvloc_error, offset, 2, pd[offset]);;
337 length = pntohs(&pd[offset]);
338 proto_tree_add_text(srvloc_tree, offset, 2, "URL length: %d", length);
340 proto_tree_add_text(srvloc_tree, offset, length, "Service URL: %s", format_text(&pd[offset], length));
342 length = pntohs(&pd[offset]);
343 proto_tree_add_text(srvloc_tree, offset, 2, "Scope List Length: %d", length);
345 proto_tree_add_text(srvloc_tree, offset, length, "Scope Response List: %s", format_text(&pd[offset], length));
350 proto_tree_add_text(srvloc_tree, offset, 0, "Service Type Request");
351 length = pntohs(&pd[offset]);
352 proto_tree_add_text(srvloc_tree, offset, 2, "Previous Response List Length: %d", length);
354 proto_tree_add_text(srvloc_tree, offset, length, "Previous Response List: %s", format_text(&pd[offset], length));
356 length = pntohs(&pd[offset]);
357 proto_tree_add_text(srvloc_tree, offset, 2, "Naming Authority List length: %d", length);
359 proto_tree_add_text(srvloc_tree, offset, length, "Naming Authority List: %s", format_text(&pd[offset], length));
361 length = pntohs(&pd[offset]);
362 proto_tree_add_text(srvloc_tree, offset, 2, "Scope List Length: %d", length);
364 proto_tree_add_text(srvloc_tree, offset, length, "Scope Response List: %s", format_text(&pd[offset], length));
369 proto_tree_add_text(srvloc_tree, offset, 0, "Service Type Reply");
370 proto_tree_add_item(srvloc_tree, hf_srvloc_error, offset, 2, pd[offset]);;
372 proto_tree_add_text(srvloc_tree, offset, 2, "Service Type Count: %d", pntohs(&pd[offset]));
374 for (count = pntohs(&pd[offset]) + 1; count > 0; count--, offset++) {
375 length = pntohs(&pd[offset]);
376 proto_tree_add_text(srvloc_tree, offset, 2, "Service Type List length: %d", length);
378 proto_tree_add_text(srvloc_tree, offset, length, "Service Type List: %s", format_text(&pd[offset], length));
384 proto_tree_add_text(srvloc_tree, offset, END_OF_FRAME, "Unknown Function Type");
386 } else { proto_tree_add_text(srvloc_tree, offset, END_OF_FRAME,"Invalid packet: Bad length value");
391 /* Register protocol with Ethereal. */
394 proto_register_srvloc(void)
396 static hf_register_info hf[] = {
397 { &hf_srvloc_version,
398 { "Version", "srvloc.version",
399 FT_UINT8, BASE_DEC, NULL, 0x0,
403 {&hf_srvloc_function,
404 {"Function", "srvloc.function",
405 FT_UINT8, BASE_DEC, VALS(srvloc_functions), 0x0,
410 {"Flags", "srvloc.flags",
411 FT_UINT8, BASE_HEX, NULL, 0x0,
416 {"Error Code", "srvloc.err",
417 FT_UINT8, BASE_DEC, VALS(srvloc_errs), 0x0,
422 static gint *ett[] = {
427 proto_srvloc = proto_register_protocol("Service Location Protocol", "srvloc");
428 proto_register_field_array(proto_srvloc, hf, array_length(hf));
429 proto_register_subtree_array(ett, array_length(ett));