2 * Routines for ypserv dissection
4 * $Id: packet-ypserv.c,v 1.23 2002/08/02 23:36:05 jmayer 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.
36 #include "packet-rpc.h"
37 #include "packet-ypserv.h"
39 static int proto_ypserv = -1;
40 static int hf_ypserv_domain = -1;
41 static int hf_ypserv_servesdomain = -1;
42 static int hf_ypserv_map = -1;
43 static int hf_ypserv_key = -1;
44 static int hf_ypserv_peer = -1;
45 static int hf_ypserv_more = -1;
46 static int hf_ypserv_ordernum = -1;
47 static int hf_ypserv_transid = -1;
48 static int hf_ypserv_prog = -1;
49 static int hf_ypserv_port = -1;
50 static int hf_ypserv_value = -1;
51 static int hf_ypserv_status = -1;
52 static int hf_ypserv_map_parms = -1;
53 static int hf_ypserv_xfrstat = -1;
55 static gint ett_ypserv = -1;
56 static gint ett_ypserv_map_parms = -1;
58 static const value_string ypstat[] =
74 static const value_string xfrstat[] =
78 { -1, "YPXFR_NOMAP" },
79 { -2, "YPXFR_NODOM" },
82 { -5, "YPXFR_MADDR" },
83 { -6, "YPXFR_YPERR" },
84 { -7, "YPXFR_BADARGS" },
87 { -10, "YPXFR_SKEW" },
88 { -11, "YPXFR_CLEAR" },
89 { -12, "YPXFR_FORCE" },
90 { -13, "YPXFR_XFRERR" },
91 { -14, "YPXFR_REFUSED" },
96 dissect_domain_call(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
100 offset = dissect_rpc_string(tvb,tree,hf_ypserv_domain,offset,NULL);
107 dissect_domain_reply(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
111 proto_tree_add_boolean(tree, hf_ypserv_servesdomain, tvb,
112 offset, 4, tvb_get_ntohl(tvb,offset));
120 dissect_match_call(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
124 offset = dissect_rpc_string(tvb, tree, hf_ypserv_domain, offset, NULL);
125 offset = dissect_rpc_string(tvb, tree, hf_ypserv_map, offset, NULL);
126 offset = dissect_rpc_string(tvb, tree, hf_ypserv_key, offset, NULL);
133 dissect_match_reply(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
137 offset = dissect_rpc_uint32(tvb, tree, hf_ypserv_status, offset);
139 offset = dissect_rpc_string(tvb, tree, hf_ypserv_value,offset, NULL);
147 dissect_first_call(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
150 * XXX - does Sun's "yp.x" lie, and claim that the argument to a
151 * FIRST call is a "ypreq_key" rather than a "ypreq_nokey"?
152 * You presumably need the key for NEXT, as "next" is "next
153 * after some entry", and the key tells you which entry, but
154 * you don't need a key for FIRST, as there's only one entry that
155 * is the first entry.
157 * The NIS server originally used DBM, which has a "firstkey()"
158 * call, with no argument, and a "nextkey()" argument, with
159 * a key argument. (Heck, it might *still* use DBM.)
161 * Given that, and given that at least one FIRST call from a Sun
162 * running Solaris 8 (the Sun on which I'm typing this, in fact)
163 * had a "ypreq_nokey" as the argument, I'm assuming that "yp.x"
169 offset = dissect_rpc_string(tvb, tree, hf_ypserv_domain, offset, NULL);
170 offset = dissect_rpc_string(tvb, tree, hf_ypserv_map, offset, NULL);
178 dissect_firstnext_reply(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
182 offset = dissect_rpc_uint32(tvb, tree, hf_ypserv_status, offset);
184 offset = dissect_rpc_string(tvb, tree, hf_ypserv_value, offset, NULL);
185 offset = dissect_rpc_string(tvb, tree, hf_ypserv_key, offset, NULL);
193 dissect_next_call(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
197 offset = dissect_rpc_string(tvb, tree, hf_ypserv_domain, offset, NULL);
198 offset = dissect_rpc_string(tvb, tree, hf_ypserv_map, offset, NULL);
199 offset = dissect_rpc_string(tvb, tree, hf_ypserv_key, offset, NULL);
206 dissect_xfr_call(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
208 proto_item *sub_item=NULL;
209 proto_tree *sub_tree=NULL;
210 int start_offset = offset;
213 sub_item = proto_tree_add_item(tree, hf_ypserv_map_parms, tvb,
216 sub_tree = proto_item_add_subtree(sub_item, ett_ypserv_map_parms);
219 offset = dissect_rpc_string(tvb, sub_tree, hf_ypserv_domain, offset, NULL);
221 offset = dissect_rpc_string(tvb, sub_tree, hf_ypserv_map, offset, NULL);
223 offset = dissect_rpc_uint32(tvb, sub_tree, hf_ypserv_ordernum, offset);
225 offset = dissect_rpc_string(tvb, sub_tree, hf_ypserv_peer, offset, NULL);
227 proto_tree_add_item(tree, hf_ypserv_transid, tvb, offset, 4, FALSE);
230 offset = dissect_rpc_uint32(tvb, tree, hf_ypserv_prog, offset);
231 offset = dissect_rpc_uint32(tvb, tree, hf_ypserv_port, offset);
234 proto_item_set_len(sub_item, offset - start_offset);
240 dissect_xfr_reply(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
242 proto_tree_add_item(tree, hf_ypserv_transid, tvb, offset, 4, FALSE);
245 offset = dissect_rpc_uint32(tvb, tree, hf_ypserv_xfrstat, offset);
251 dissect_ypreq_nokey(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
254 offset = dissect_rpc_string(tvb, tree, hf_ypserv_domain, offset, NULL);
256 offset = dissect_rpc_string(tvb, tree, hf_ypserv_map, offset, NULL);
262 dissect_ypresp_all(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
267 more = tvb_get_ntohl(tvb, offset);
269 offset = dissect_rpc_uint32(tvb, tree, hf_ypserv_more, offset);
272 offset = dissect_rpc_uint32(tvb, tree, hf_ypserv_status, offset);
273 offset = dissect_rpc_string(tvb, tree, hf_ypserv_value, offset, NULL);
274 offset = dissect_rpc_string(tvb, tree, hf_ypserv_key, offset, NULL);
281 dissect_ypresp_master(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
284 offset = dissect_rpc_uint32(tvb, tree, hf_ypserv_status, offset);
286 offset = dissect_rpc_string(tvb, tree, hf_ypserv_peer, offset, NULL);
293 dissect_ypresp_order(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
296 offset = dissect_rpc_uint32(tvb, tree, hf_ypserv_status, offset);
298 offset = dissect_rpc_uint32(tvb, tree, hf_ypserv_ordernum, offset);
305 dissect_ypresp_maplist(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
307 offset = dissect_rpc_uint32(tvb, tree, hf_ypserv_status, offset);
308 while(tvb_get_ntohl(tvb,offset)){
309 offset = dissect_rpc_uint32(tvb, tree, hf_ypserv_more, offset);
310 offset = dissect_rpc_string(tvb, tree, hf_ypserv_map, offset, NULL);
313 offset = dissect_rpc_uint32(tvb, tree, hf_ypserv_more, offset);
318 /* proc number, "proc name", dissect_request, dissect_reply */
319 /* NULL as function pointer means: type of arguments is "void". */
321 /* someone please get me a version 1 trace */
322 static const vsff ypserv1_proc[] = {
323 { 0, "NULL", NULL, NULL },
324 { YPPROC_DOMAIN, "DOMAIN",
326 { YPPROC_DOMAIN_NONACK, "DOMAIN_NONACK",
328 { YPPROC_MATCH, "MATCH",
330 { YPPROC_FIRST, "FIRST",
332 { YPPROC_NEXT, "NEXT",
336 { YPPROC_CLEAR, "CLEAR",
340 { YPPROC_MASTER, "MASTER",
342 { YPPROC_ORDER, "ORDER",
344 { YPPROC_MAPLIST, "MAPLIST",
346 { 0, NULL, NULL, NULL }
348 /* end of YPServ version 2 */
350 static const vsff ypserv2_proc[] = {
351 { 0, "NULL", NULL, NULL },
352 { YPPROC_DOMAIN, "DOMAIN",
353 dissect_domain_call, dissect_domain_reply },
354 { YPPROC_DOMAIN_NONACK, "DOMAIN_NONACK",
355 dissect_domain_call, dissect_domain_reply },
356 { YPPROC_MATCH, "MATCH",
357 dissect_match_call, dissect_match_reply },
358 { YPPROC_FIRST, "FIRST",
359 dissect_first_call, dissect_firstnext_reply },
360 { YPPROC_NEXT, "NEXT",
361 dissect_next_call, dissect_firstnext_reply },
363 dissect_xfr_call, dissect_xfr_reply },
364 { YPPROC_CLEAR, "CLEAR",
367 dissect_ypreq_nokey, dissect_ypresp_all },
368 { YPPROC_MASTER, "MASTER",
369 dissect_ypreq_nokey, dissect_ypresp_master },
370 { YPPROC_ORDER, "ORDER",
371 dissect_ypreq_nokey, dissect_ypresp_order },
372 { YPPROC_MAPLIST, "MAPLIST",
373 dissect_domain_call, dissect_ypresp_maplist },
374 { 0, NULL, NULL, NULL }
376 /* end of YPServ version 2 */
380 proto_register_ypserv(void)
382 /*static struct true_false_string okfailed = { "Ok", "Failed" };*/
383 static struct true_false_string yesno = { "Yes", "No" };
385 static hf_register_info hf[] = {
386 { &hf_ypserv_domain, {
387 "Domain", "ypserv.domain", FT_STRING, BASE_DEC,
388 NULL, 0, "Domain", HFILL }},
389 { &hf_ypserv_servesdomain, {
390 "Serves Domain", "ypserv.servesdomain", FT_BOOLEAN, BASE_DEC,
391 &yesno, 0, "Serves Domain", HFILL }},
393 "Map Name", "ypserv.map", FT_STRING, BASE_DEC,
394 NULL, 0, "Map Name", HFILL }},
396 "Peer Name", "ypserv.peer", FT_STRING, BASE_DEC,
397 NULL, 0, "Peer Name", HFILL }},
399 "More", "ypserv.more", FT_BOOLEAN, BASE_NONE,
400 &yesno, 0, "More", HFILL }},
401 { &hf_ypserv_ordernum, {
402 "Order Number", "ypserv.ordernum", FT_UINT32, BASE_DEC,
403 NULL, 0, "Order Number for XFR", HFILL }},
404 { &hf_ypserv_transid, {
405 "Host Transport ID", "ypserv.transid", FT_IPv4, BASE_DEC,
406 NULL, 0, "Host Transport ID to use for XFR Callback", HFILL }},
408 "Program Number", "ypserv.prog", FT_UINT32, BASE_DEC,
409 NULL, 0, "Program Number to use for XFR Callback", HFILL }},
411 "Port", "ypserv.port", FT_UINT32, BASE_DEC,
412 NULL, 0, "Port to use for XFR Callback", HFILL }},
414 "Key", "ypserv.key", FT_STRING, BASE_DEC,
415 NULL, 0, "Key", HFILL }},
416 { &hf_ypserv_value, {
417 "Value", "ypserv.value", FT_STRING, BASE_DEC,
418 NULL, 0, "Value", HFILL }},
419 { &hf_ypserv_status, {
420 "Status", "ypserv.status", FT_INT32, BASE_DEC,
421 VALS(ypstat) , 0, "Status", HFILL }},
422 { &hf_ypserv_map_parms, {
423 "YP Map Parameters", "ypserv.map_parms", FT_NONE, BASE_DEC,
424 NULL, 0, "YP Map Parameters", HFILL }},
425 { &hf_ypserv_xfrstat, {
426 "Xfrstat", "ypserv.xfrstat", FT_INT32, BASE_DEC,
427 VALS(xfrstat), 0, "Xfrstat", HFILL }},
429 static gint *ett[] = {
431 &ett_ypserv_map_parms,
434 proto_ypserv = proto_register_protocol("Yellow Pages Service",
436 proto_register_field_array(proto_ypserv, hf, array_length(hf));
437 proto_register_subtree_array(ett, array_length(ett));
441 proto_reg_handoff_ypserv(void)
443 /* Register the protocol as RPC */
444 rpc_init_prog(proto_ypserv, YPSERV_PROGRAM, ett_ypserv);
445 /* Register the procedure tables */
446 rpc_init_proc_table(YPSERV_PROGRAM, 1, ypserv1_proc);
447 rpc_init_proc_table(YPSERV_PROGRAM, 2, ypserv2_proc);