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 "namespace.h"
52 #include <rpc/types.h>
54 #include <rpc/rpcb_prot.h>
55 #include "un-namespace.h"
62 if (!xdr_u_int32_t(xdrs, &objp->r_prog)) {
65 if (!xdr_u_int32_t(xdrs, &objp->r_vers)) {
68 if (!xdr_string(xdrs, &objp->r_netid, (u_int)~0)) {
71 if (!xdr_string(xdrs, &objp->r_addr, (u_int)~0)) {
74 if (!xdr_string(xdrs, &objp->r_owner, (u_int)~0)) {
81 * rpcblist_ptr implements a linked list. The RPCL definition from
86 * struct rpcblist *rpcb_next;
88 * typedef rpcblist *rpcblist_ptr;
90 * Recall that "pointers" in XDR are encoded as a boolean, indicating whether
91 * there's any data behind the pointer, followed by the data (if any exists).
92 * The boolean can be interpreted as ``more data follows me''; if FALSE then
93 * nothing follows the boolean; if TRUE then the boolean is followed by an
94 * actual struct rpcb, and another rpcblist_ptr (declared in RPCL as "struct
97 * This could be implemented via the xdr_pointer type, though this would
98 * result in one recursive call per element in the list. Rather than do that
99 * we can ``unwind'' the recursion into a while loop and use xdr_reference to
100 * serialize the rpcb elements.
104 xdr_rpcblist_ptr(xdrs, rp)
109 * more_elements is pre-computed in case the direction is
110 * XDR_ENCODE or XDR_FREE. more_elements is overwritten by
111 * xdr_bool when the direction is XDR_DECODE.
113 bool_t more_elements;
114 int freeing = (xdrs->x_op == XDR_FREE);
116 rpcblist_ptr next_copy;
120 more_elements = (bool_t)(*rp != NULL);
121 if (! xdr_bool(xdrs, &more_elements)) {
124 if (! more_elements) {
125 return (TRUE); /* we are done */
128 * the unfortunate side effect of non-recursion is that in
129 * the case of freeing we must remember the next object
130 * before we free the current object ...
133 next = (*rp)->rpcb_next;
134 if (! xdr_reference(xdrs, (caddr_t *)rp,
135 (u_int)sizeof (rpcblist), (xdrproc_t)xdr_rpcb)) {
142 * Note that in the subsequent iteration, next_copy
143 * gets nulled out by the xdr_reference
144 * but next itself survives.
147 rp = &((*rp)->rpcb_next);
154 * xdr_rpcblist() is specified to take a RPCBLIST **, but is identical in
155 * functionality to xdr_rpcblist_ptr().
158 xdr_rpcblist(xdrs, rp)
164 dummy = xdr_rpcblist_ptr(xdrs, (rpcblist_ptr *)rp);
170 xdr_rpcb_entry(xdrs, objp)
174 if (!xdr_string(xdrs, &objp->r_maddr, (u_int)~0)) {
177 if (!xdr_string(xdrs, &objp->r_nc_netid, (u_int)~0)) {
180 if (!xdr_u_int32_t(xdrs, &objp->r_nc_semantics)) {
183 if (!xdr_string(xdrs, &objp->r_nc_protofmly, (u_int)~0)) {
186 if (!xdr_string(xdrs, &objp->r_nc_proto, (u_int)~0)) {
193 xdr_rpcb_entry_list_ptr(xdrs, rp)
195 rpcb_entry_list_ptr *rp;
198 * more_elements is pre-computed in case the direction is
199 * XDR_ENCODE or XDR_FREE. more_elements is overwritten by
200 * xdr_bool when the direction is XDR_DECODE.
202 bool_t more_elements;
203 int freeing = (xdrs->x_op == XDR_FREE);
204 rpcb_entry_list_ptr next;
205 rpcb_entry_list_ptr next_copy;
209 more_elements = (bool_t)(*rp != NULL);
210 if (! xdr_bool(xdrs, &more_elements)) {
213 if (! more_elements) {
214 return (TRUE); /* we are done */
217 * the unfortunate side effect of non-recursion is that in
218 * the case of freeing we must remember the next object
219 * before we free the current object ...
222 next = (*rp)->rpcb_entry_next;
223 if (! xdr_reference(xdrs, (caddr_t *)rp,
224 (u_int)sizeof (rpcb_entry_list),
225 (xdrproc_t)xdr_rpcb_entry)) {
228 if (freeing && *rp) {
232 * Note that in the subsequent iteration, next_copy
233 * gets nulled out by the xdr_reference
234 * but next itself survives.
237 rp = &((*rp)->rpcb_entry_next);
244 * XDR remote call arguments
245 * written for XDR_ENCODE direction only
248 xdr_rpcb_rmtcallargs(xdrs, p)
250 struct rpcb_rmtcallargs *p;
252 struct r_rpcb_rmtcallargs *objp =
253 (struct r_rpcb_rmtcallargs *)(void *)p;
254 u_int lenposition, argposition, position;
257 buf = XDR_INLINE(xdrs, 3 * BYTES_PER_XDR_UNIT);
259 if (!xdr_u_int32_t(xdrs, &objp->prog)) {
262 if (!xdr_u_int32_t(xdrs, &objp->vers)) {
265 if (!xdr_u_int32_t(xdrs, &objp->proc)) {
269 IXDR_PUT_U_INT32(buf, objp->prog);
270 IXDR_PUT_U_INT32(buf, objp->vers);
271 IXDR_PUT_U_INT32(buf, objp->proc);
275 * All the jugglery for just getting the size of the arguments
277 lenposition = XDR_GETPOS(xdrs);
278 if (! xdr_u_int(xdrs, &(objp->args.args_len))) {
281 argposition = XDR_GETPOS(xdrs);
282 if (! (*objp->xdr_args)(xdrs, objp->args.args_val)) {
285 position = XDR_GETPOS(xdrs);
286 objp->args.args_len = (u_int)((u_long)position - (u_long)argposition);
287 XDR_SETPOS(xdrs, lenposition);
288 if (! xdr_u_int(xdrs, &(objp->args.args_len))) {
291 XDR_SETPOS(xdrs, position);
296 * XDR remote call results
297 * written for XDR_DECODE direction only
300 xdr_rpcb_rmtcallres(xdrs, p)
302 struct rpcb_rmtcallres *p;
305 struct r_rpcb_rmtcallres *objp = (struct r_rpcb_rmtcallres *)(void *)p;
307 if (!xdr_string(xdrs, &objp->addr, (u_int)~0)) {
310 if (!xdr_u_int(xdrs, &objp->results.results_len)) {
313 dummy = (*(objp->xdr_res))(xdrs, objp->results.results_val);
318 xdr_netbuf(xdrs, objp)
325 if (!xdr_u_int32_t(xdrs, (u_int32_t *) &objp->maxlen)) {
329 dummy = xdr_bytes(xdrs, (char **) pp,
330 (u_int *)&(objp->len), objp->maxlen);