2 * Routines for ypserv dissection
4 * $Id: packet-ypserv.c,v 1.22 2002/04/03 13:24:13 girlich Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@ethereal.com>
8 * Copyright 1998 Gerald Combs
10 * Copied from packet-smb.c
12 * 2001 Ronnie Sahlberg <See AUTHORS for email>
13 * Added all remaining dissectors for this protocol
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
35 #ifdef HAVE_SYS_TYPES_H
36 #include <sys/types.h>
40 #include "packet-rpc.h"
41 #include "packet-ypserv.h"
43 static int proto_ypserv = -1;
44 static int hf_ypserv_domain = -1;
45 static int hf_ypserv_servesdomain = -1;
46 static int hf_ypserv_map = -1;
47 static int hf_ypserv_key = -1;
48 static int hf_ypserv_peer = -1;
49 static int hf_ypserv_more = -1;
50 static int hf_ypserv_ordernum = -1;
51 static int hf_ypserv_transid = -1;
52 static int hf_ypserv_prog = -1;
53 static int hf_ypserv_port = -1;
54 static int hf_ypserv_value = -1;
55 static int hf_ypserv_status = -1;
56 static int hf_ypserv_map_parms = -1;
57 static int hf_ypserv_xfrstat = -1;
59 static gint ett_ypserv = -1;
60 static gint ett_ypserv_map_parms = -1;
62 static const value_string ypstat[] =
78 static const value_string xfrstat[] =
82 { -1, "YPXFR_NOMAP" },
83 { -2, "YPXFR_NODOM" },
86 { -5, "YPXFR_MADDR" },
87 { -6, "YPXFR_YPERR" },
88 { -7, "YPXFR_BADARGS" },
91 { -10, "YPXFR_SKEW" },
92 { -11, "YPXFR_CLEAR" },
93 { -12, "YPXFR_FORCE" },
94 { -13, "YPXFR_XFRERR" },
95 { -14, "YPXFR_REFUSED" },
100 dissect_domain_call(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
104 offset = dissect_rpc_string(tvb,tree,hf_ypserv_domain,offset,NULL);
111 dissect_domain_reply(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
115 proto_tree_add_boolean(tree, hf_ypserv_servesdomain, tvb,
116 offset, 4, tvb_get_ntohl(tvb,offset));
124 dissect_match_call(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
128 offset = dissect_rpc_string(tvb, tree, hf_ypserv_domain, offset, NULL);
129 offset = dissect_rpc_string(tvb, tree, hf_ypserv_map, offset, NULL);
130 offset = dissect_rpc_string(tvb, tree, hf_ypserv_key, offset, NULL);
137 dissect_match_reply(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
141 offset = dissect_rpc_uint32(tvb, tree, hf_ypserv_status, offset);
143 offset = dissect_rpc_string(tvb, tree, hf_ypserv_value,offset, NULL);
151 dissect_first_call(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
154 * XXX - does Sun's "yp.x" lie, and claim that the argument to a
155 * FIRST call is a "ypreq_key" rather than a "ypreq_nokey"?
156 * You presumably need the key for NEXT, as "next" is "next
157 * after some entry", and the key tells you which entry, but
158 * you don't need a key for FIRST, as there's only one entry that
159 * is the first entry.
161 * The NIS server originally used DBM, which has a "firstkey()"
162 * call, with no argument, and a "nextkey()" argument, with
163 * a key argument. (Heck, it might *still* use DBM.)
165 * Given that, and given that at least one FIRST call from a Sun
166 * running Solaris 8 (the Sun on which I'm typing this, in fact)
167 * had a "ypreq_nokey" as the argument, I'm assuming that "yp.x"
173 offset = dissect_rpc_string(tvb, tree, hf_ypserv_domain, offset, NULL);
174 offset = dissect_rpc_string(tvb, tree, hf_ypserv_map, offset, NULL);
182 dissect_firstnext_reply(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
186 offset = dissect_rpc_uint32(tvb, tree, hf_ypserv_status, offset);
188 offset = dissect_rpc_string(tvb, tree, hf_ypserv_value, offset, NULL);
189 offset = dissect_rpc_string(tvb, tree, hf_ypserv_key, offset, NULL);
197 dissect_next_call(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
201 offset = dissect_rpc_string(tvb, tree, hf_ypserv_domain, offset, NULL);
202 offset = dissect_rpc_string(tvb, tree, hf_ypserv_map, offset, NULL);
203 offset = dissect_rpc_string(tvb, tree, hf_ypserv_key, offset, NULL);
210 dissect_xfr_call(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
212 proto_item *sub_item=NULL;
213 proto_tree *sub_tree=NULL;
214 int start_offset = offset;
217 sub_item = proto_tree_add_item(tree, hf_ypserv_map_parms, tvb,
220 sub_tree = proto_item_add_subtree(sub_item, ett_ypserv_map_parms);
223 offset = dissect_rpc_string(tvb, sub_tree, hf_ypserv_domain, offset, NULL);
225 offset = dissect_rpc_string(tvb, sub_tree, hf_ypserv_map, offset, NULL);
227 offset = dissect_rpc_uint32(tvb, sub_tree, hf_ypserv_ordernum, offset);
229 offset = dissect_rpc_string(tvb, sub_tree, hf_ypserv_peer, offset, NULL);
231 proto_tree_add_item(tree, hf_ypserv_transid, tvb, offset, 4, FALSE);
234 offset = dissect_rpc_uint32(tvb, tree, hf_ypserv_prog, offset);
235 offset = dissect_rpc_uint32(tvb, tree, hf_ypserv_port, offset);
238 proto_item_set_len(sub_item, offset - start_offset);
244 dissect_xfr_reply(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
246 proto_tree_add_item(tree, hf_ypserv_transid, tvb, offset, 4, FALSE);
249 offset = dissect_rpc_uint32(tvb, tree, hf_ypserv_xfrstat, offset);
255 dissect_ypreq_nokey(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
258 offset = dissect_rpc_string(tvb, tree, hf_ypserv_domain, offset, NULL);
260 offset = dissect_rpc_string(tvb, tree, hf_ypserv_map, offset, NULL);
266 dissect_ypresp_all(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
271 more = tvb_get_ntohl(tvb, offset);
273 offset = dissect_rpc_uint32(tvb, tree, hf_ypserv_more, offset);
276 offset = dissect_rpc_uint32(tvb, tree, hf_ypserv_status, offset);
277 offset = dissect_rpc_string(tvb, tree, hf_ypserv_value, offset, NULL);
278 offset = dissect_rpc_string(tvb, tree, hf_ypserv_key, offset, NULL);
285 dissect_ypresp_master(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
288 offset = dissect_rpc_uint32(tvb, tree, hf_ypserv_status, offset);
290 offset = dissect_rpc_string(tvb, tree, hf_ypserv_peer, offset, NULL);
297 dissect_ypresp_order(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
300 offset = dissect_rpc_uint32(tvb, tree, hf_ypserv_status, offset);
302 offset = dissect_rpc_uint32(tvb, tree, hf_ypserv_ordernum, offset);
309 dissect_ypresp_maplist(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
311 offset = dissect_rpc_uint32(tvb, tree, hf_ypserv_status, offset);
312 while(tvb_get_ntohl(tvb,offset)){
313 offset = dissect_rpc_uint32(tvb, tree, hf_ypserv_more, offset);
314 offset = dissect_rpc_string(tvb, tree, hf_ypserv_map, offset, NULL);
317 offset = dissect_rpc_uint32(tvb, tree, hf_ypserv_more, offset);
322 /* proc number, "proc name", dissect_request, dissect_reply */
323 /* NULL as function pointer means: type of arguments is "void". */
325 /* someone please get me a version 1 trace */
326 static const vsff ypserv1_proc[] = {
327 { 0, "NULL", NULL, NULL },
328 { YPPROC_DOMAIN, "DOMAIN",
330 { YPPROC_DOMAIN_NONACK, "DOMAIN_NONACK",
332 { YPPROC_MATCH, "MATCH",
334 { YPPROC_FIRST, "FIRST",
336 { YPPROC_NEXT, "NEXT",
340 { YPPROC_CLEAR, "CLEAR",
344 { YPPROC_MASTER, "MASTER",
346 { YPPROC_ORDER, "ORDER",
348 { YPPROC_MAPLIST, "MAPLIST",
350 { 0, NULL, NULL, NULL }
352 /* end of YPServ version 2 */
354 static const vsff ypserv2_proc[] = {
355 { 0, "NULL", NULL, NULL },
356 { YPPROC_DOMAIN, "DOMAIN",
357 dissect_domain_call, dissect_domain_reply },
358 { YPPROC_DOMAIN_NONACK, "DOMAIN_NONACK",
359 dissect_domain_call, dissect_domain_reply },
360 { YPPROC_MATCH, "MATCH",
361 dissect_match_call, dissect_match_reply },
362 { YPPROC_FIRST, "FIRST",
363 dissect_first_call, dissect_firstnext_reply },
364 { YPPROC_NEXT, "NEXT",
365 dissect_next_call, dissect_firstnext_reply },
367 dissect_xfr_call, dissect_xfr_reply },
368 { YPPROC_CLEAR, "CLEAR",
371 dissect_ypreq_nokey, dissect_ypresp_all },
372 { YPPROC_MASTER, "MASTER",
373 dissect_ypreq_nokey, dissect_ypresp_master },
374 { YPPROC_ORDER, "ORDER",
375 dissect_ypreq_nokey, dissect_ypresp_order },
376 { YPPROC_MAPLIST, "MAPLIST",
377 dissect_domain_call, dissect_ypresp_maplist },
378 { 0, NULL, NULL, NULL }
380 /* end of YPServ version 2 */
384 proto_register_ypserv(void)
386 /*static struct true_false_string okfailed = { "Ok", "Failed" };*/
387 static struct true_false_string yesno = { "Yes", "No" };
389 static hf_register_info hf[] = {
390 { &hf_ypserv_domain, {
391 "Domain", "ypserv.domain", FT_STRING, BASE_DEC,
392 NULL, 0, "Domain", HFILL }},
393 { &hf_ypserv_servesdomain, {
394 "Serves Domain", "ypserv.servesdomain", FT_BOOLEAN, BASE_DEC,
395 &yesno, 0, "Serves Domain", HFILL }},
397 "Map Name", "ypserv.map", FT_STRING, BASE_DEC,
398 NULL, 0, "Map Name", HFILL }},
400 "Peer Name", "ypserv.peer", FT_STRING, BASE_DEC,
401 NULL, 0, "Peer Name", HFILL }},
403 "More", "ypserv.more", FT_BOOLEAN, BASE_NONE,
404 &yesno, 0, "More", HFILL }},
405 { &hf_ypserv_ordernum, {
406 "Order Number", "ypserv.ordernum", FT_UINT32, BASE_DEC,
407 NULL, 0, "Order Number for XFR", HFILL }},
408 { &hf_ypserv_transid, {
409 "Host Transport ID", "ypserv.transid", FT_IPv4, BASE_DEC,
410 NULL, 0, "Host Transport ID to use for XFR Callback", HFILL }},
412 "Program Number", "ypserv.prog", FT_UINT32, BASE_DEC,
413 NULL, 0, "Program Number to use for XFR Callback", HFILL }},
415 "Port", "ypserv.port", FT_UINT32, BASE_DEC,
416 NULL, 0, "Port to use for XFR Callback", HFILL }},
418 "Key", "ypserv.key", FT_STRING, BASE_DEC,
419 NULL, 0, "Key", HFILL }},
420 { &hf_ypserv_value, {
421 "Value", "ypserv.value", FT_STRING, BASE_DEC,
422 NULL, 0, "Value", HFILL }},
423 { &hf_ypserv_status, {
424 "Status", "ypserv.status", FT_INT32, BASE_DEC,
425 VALS(ypstat) , 0, "Status", HFILL }},
426 { &hf_ypserv_map_parms, {
427 "YP Map Parameters", "ypserv.map_parms", FT_NONE, BASE_DEC,
428 NULL, 0, "YP Map Parameters", HFILL }},
429 { &hf_ypserv_xfrstat, {
430 "Xfrstat", "ypserv.xfrstat", FT_INT32, BASE_DEC,
431 VALS(xfrstat), 0, "Xfrstat", HFILL }},
433 static gint *ett[] = {
435 &ett_ypserv_map_parms,
438 proto_ypserv = proto_register_protocol("Yellow Pages Service",
440 proto_register_field_array(proto_ypserv, hf, array_length(hf));
441 proto_register_subtree_array(ett, array_length(ett));
445 proto_reg_handoff_ypserv(void)
447 /* Register the protocol as RPC */
448 rpc_init_prog(proto_ypserv, YPSERV_PROGRAM, ett_ypserv);
449 /* Register the procedure tables */
450 rpc_init_proc_table(YPSERV_PROGRAM, 1, ypserv1_proc);
451 rpc_init_proc_table(YPSERV_PROGRAM, 2, ypserv2_proc);