1 /* $NetBSD: rpcb_prot.c,v 1.3 2000/07/14 08:40:42 fvdl Exp $ */
4 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
5 * unrestricted use provided that this legend is included on all tape
6 * media and as a part of the software program in whole or part. Users
7 * may copy or modify Sun RPC without charge, but are not authorized
8 * to license or distribute it to anyone else except as part of a product or
9 * program developed by the user.
11 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
12 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
13 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
15 * Sun RPC is provided with no support and without any obligation on the
16 * part of Sun Microsystems, Inc. to assist in its use, correction,
17 * modification or enhancement.
19 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
20 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
21 * OR ANY PART THEREOF.
23 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
24 * or profits or other special, indirect and consequential damages, even if
25 * Sun has been advised of the possibility of such damages.
27 * Sun Microsystems, Inc.
29 * Mountain View, California 94043
32 * Copyright (c) 1986-1991 by Sun Microsystems Inc.
35 /* #ident "@(#)rpcb_prot.c 1.13 94/04/24 SMI" */
37 #if defined(LIBC_SCCS) && !defined(lint)
38 static char sccsid[] = "@(#)rpcb_prot.c 1.9 89/04/21 Copyr 1984 Sun Micro";
40 #include <sys/cdefs.h>
41 __FBSDID("$FreeBSD$");
45 * XDR routines for the rpcbinder version 3.
47 * Copyright (C) 1984, 1988, Sun Microsystems, Inc.
50 #include <sys/param.h>
51 #include <sys/systm.h>
52 #include <sys/kernel.h>
53 #include <sys/malloc.h>
56 #include <rpc/rpcb_prot.h>
59 xdr_portmap(XDR *xdrs, struct portmap *regs)
62 if (xdr_u_long(xdrs, ®s->pm_prog) &&
63 xdr_u_long(xdrs, ®s->pm_vers) &&
64 xdr_u_long(xdrs, ®s->pm_prot))
65 return (xdr_u_long(xdrs, ®s->pm_port));
70 xdr_rpcb(XDR *xdrs, RPCB *objp)
72 if (!xdr_uint32_t(xdrs, &objp->r_prog)) {
75 if (!xdr_uint32_t(xdrs, &objp->r_vers)) {
78 if (!xdr_string(xdrs, &objp->r_netid, (u_int)~0)) {
81 if (!xdr_string(xdrs, &objp->r_addr, (u_int)~0)) {
84 if (!xdr_string(xdrs, &objp->r_owner, (u_int)~0)) {
91 * rpcblist_ptr implements a linked list. The RPCL definition from
96 * struct rpcblist *rpcb_next;
98 * typedef rpcblist *rpcblist_ptr;
100 * Recall that "pointers" in XDR are encoded as a boolean, indicating whether
101 * there's any data behind the pointer, followed by the data (if any exists).
102 * The boolean can be interpreted as ``more data follows me''; if FALSE then
103 * nothing follows the boolean; if TRUE then the boolean is followed by an
104 * actual struct rpcb, and another rpcblist_ptr (declared in RPCL as "struct
107 * This could be implemented via the xdr_pointer type, though this would
108 * result in one recursive call per element in the list. Rather than do that
109 * we can ``unwind'' the recursion into a while loop and use xdr_reference to
110 * serialize the rpcb elements.
114 xdr_rpcblist_ptr(XDR *xdrs, rpcblist_ptr *rp)
117 * more_elements is pre-computed in case the direction is
118 * XDR_ENCODE or XDR_FREE. more_elements is overwritten by
119 * xdr_bool when the direction is XDR_DECODE.
121 bool_t more_elements;
122 int freeing = (xdrs->x_op == XDR_FREE);
124 rpcblist_ptr next_copy;
128 more_elements = (bool_t)(*rp != NULL);
129 if (! xdr_bool(xdrs, &more_elements)) {
132 if (! more_elements) {
133 return (TRUE); /* we are done */
136 * the unfortunate side effect of non-recursion is that in
137 * the case of freeing we must remember the next object
138 * before we free the current object ...
141 next = (*rp)->rpcb_next;
142 if (! xdr_reference(xdrs, (caddr_t *)rp,
143 (u_int)sizeof (RPCBLIST), (xdrproc_t)xdr_rpcb)) {
150 * Note that in the subsequent iteration, next_copy
151 * gets nulled out by the xdr_reference
152 * but next itself survives.
155 rp = &((*rp)->rpcb_next);
163 * xdr_rpcblist() is specified to take a RPCBLIST **, but is identical in
164 * functionality to xdr_rpcblist_ptr().
167 xdr_rpcblist(XDR *xdrs, RPCBLIST **rp)
171 dummy = xdr_rpcblist_ptr(xdrs, (rpcblist_ptr *)rp);
177 xdr_rpcb_entry(XDR *xdrs, rpcb_entry *objp)
179 if (!xdr_string(xdrs, &objp->r_maddr, (u_int)~0)) {
182 if (!xdr_string(xdrs, &objp->r_nc_netid, (u_int)~0)) {
185 if (!xdr_uint32_t(xdrs, &objp->r_nc_semantics)) {
188 if (!xdr_string(xdrs, &objp->r_nc_protofmly, (u_int)~0)) {
191 if (!xdr_string(xdrs, &objp->r_nc_proto, (u_int)~0)) {
198 xdr_rpcb_entry_list_ptr(XDR *xdrs, rpcb_entry_list_ptr *rp)
201 * more_elements is pre-computed in case the direction is
202 * XDR_ENCODE or XDR_FREE. more_elements is overwritten by
203 * xdr_bool when the direction is XDR_DECODE.
205 bool_t more_elements;
206 int freeing = (xdrs->x_op == XDR_FREE);
207 rpcb_entry_list_ptr next;
208 rpcb_entry_list_ptr next_copy;
212 more_elements = (bool_t)(*rp != NULL);
213 if (! xdr_bool(xdrs, &more_elements)) {
216 if (! more_elements) {
217 return (TRUE); /* we are done */
220 * the unfortunate side effect of non-recursion is that in
221 * the case of freeing we must remember the next object
222 * before we free the current object ...
225 next = (*rp)->rpcb_entry_next;
226 if (! xdr_reference(xdrs, (caddr_t *)rp,
227 (u_int)sizeof (rpcb_entry_list),
228 (xdrproc_t)xdr_rpcb_entry)) {
231 if (freeing && *rp) {
235 * Note that in the subsequent iteration, next_copy
236 * gets nulled out by the xdr_reference
237 * but next itself survives.
240 rp = &((*rp)->rpcb_entry_next);