1 /* $NetBSD: rpcb_prot.c,v 1.9 2006/05/11 17:11:57 mrg 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 #include <sys/cdefs.h>
38 #if defined(LIBC_SCCS) && !defined(lint)
40 static char sccsid
[] = "@(#)rpcb_prot.c 1.9 89/04/21 Copyr 1984 Sun Micro";
42 __RCSID("$NetBSD: rpcb_prot.c,v 1.9 2006/05/11 17:11:57 mrg Exp $");
48 * XDR routines for the rpcbinder version 3.
50 * Copyright (C) 1984, 1988, Sun Microsystems, Inc.
53 #include "namespace.h"
56 #include <rpc/types.h>
58 #include <rpc/rpcb_prot.h>
63 __weak_alias(xdr_rpcb
,_xdr_rpcb
)
64 __weak_alias(xdr_rpcblist_ptr
,_xdr_rpcblist_ptr
)
65 __weak_alias(xdr_rpcblist
,_xdr_rpcblist
)
66 __weak_alias(xdr_rpcb_entry
,_xdr_rpcb_entry
)
67 __weak_alias(xdr_rpcb_entry_list_ptr
,_xdr_rpcb_entry_list_ptr
)
68 __weak_alias(xdr_rpcb_rmtcallargs
,_xdr_rpcb_rmtcallargs
)
69 __weak_alias(xdr_rpcb_rmtcallres
,_xdr_rpcb_rmtcallres
)
70 __weak_alias(xdr_netbuf
,_xdr_netbuf
)
80 _DIAGASSERT(objp
!= NULL
);
82 if (!xdr_u_int32_t(xdrs
, &objp
->r_prog
)) {
85 if (!xdr_u_int32_t(xdrs
, &objp
->r_vers
)) {
88 if (!xdr_string(xdrs
, &objp
->r_netid
, (u_int
)~0)) {
91 if (!xdr_string(xdrs
, &objp
->r_addr
, (u_int
)~0)) {
94 if (!xdr_string(xdrs
, &objp
->r_owner
, (u_int
)~0)) {
101 * rpcblist_ptr implements a linked list. The RPCL definition from
106 * struct rpcblist *rpcb_next;
108 * typedef rpcblist *rpcblist_ptr;
110 * Recall that "pointers" in XDR are encoded as a boolean, indicating whether
111 * there's any data behind the pointer, followed by the data (if any exists).
112 * The boolean can be interpreted as ``more data follows me''; if FALSE then
113 * nothing follows the boolean; if TRUE then the boolean is followed by an
114 * actual struct rpcb, and another rpcblist_ptr (declared in RPCL as "struct
117 * This could be implemented via the xdr_pointer type, though this would
118 * result in one recursive call per element in the list. Rather than do that
119 * we can ``unwind'' the recursion into a while loop and use xdr_reference to
120 * serialize the rpcb elements.
124 xdr_rpcblist_ptr(xdrs
, rp
)
129 * more_elements is pre-computed in case the direction is
130 * XDR_ENCODE or XDR_FREE. more_elements is overwritten by
131 * xdr_bool when the direction is XDR_DECODE.
133 bool_t more_elements
;
136 rpcblist_ptr next_copy
;
138 _DIAGASSERT(xdrs
!= NULL
);
139 /* XXX: rp may be NULL ??? */
141 freeing
= (xdrs
->x_op
== XDR_FREE
);
145 more_elements
= (bool_t
)(*rp
!= NULL
);
146 if (! xdr_bool(xdrs
, &more_elements
)) {
149 if (! more_elements
) {
150 return (TRUE
); /* we are done */
153 * the unfortunate side effect of non-recursion is that in
154 * the case of freeing we must remember the next object
155 * before we free the current object ...
158 next
= (*rp
)->rpcb_next
;
159 if (! xdr_reference(xdrs
, (caddr_t
*)rp
,
160 (u_int
)sizeof (rpcblist
), (xdrproc_t
)xdr_rpcb
)) {
167 * Note that in the subsequent iteration, next_copy
168 * gets nulled out by the xdr_reference
169 * but next itself survives.
172 rp
= &((*rp
)->rpcb_next
);
179 * xdr_rpcblist() is specified to take a RPCBLIST **, but is identical in
180 * functionality to xdr_rpcblist_ptr().
183 xdr_rpcblist(xdrs
, rp
)
189 dummy
= xdr_rpcblist_ptr(xdrs
, (rpcblist_ptr
*)rp
);
195 xdr_rpcb_entry(xdrs
, objp
)
200 _DIAGASSERT(objp
!= NULL
);
202 if (!xdr_string(xdrs
, &objp
->r_maddr
, (u_int
)~0)) {
205 if (!xdr_string(xdrs
, &objp
->r_nc_netid
, (u_int
)~0)) {
208 if (!xdr_u_int32_t(xdrs
, &objp
->r_nc_semantics
)) {
211 if (!xdr_string(xdrs
, &objp
->r_nc_protofmly
, (u_int
)~0)) {
214 if (!xdr_string(xdrs
, &objp
->r_nc_proto
, (u_int
)~0)) {
221 xdr_rpcb_entry_list_ptr(xdrs
, rp
)
223 rpcb_entry_list_ptr
*rp
;
226 * more_elements is pre-computed in case the direction is
227 * XDR_ENCODE or XDR_FREE. more_elements is overwritten by
228 * xdr_bool when the direction is XDR_DECODE.
230 bool_t more_elements
;
232 rpcb_entry_list_ptr next
;
233 rpcb_entry_list_ptr next_copy
;
235 _DIAGASSERT(xdrs
!= NULL
);
236 /* XXX: rp is allowed to be NULL ??? */
238 freeing
= (xdrs
->x_op
== XDR_FREE
);
242 more_elements
= (bool_t
)(*rp
!= NULL
);
243 if (! xdr_bool(xdrs
, &more_elements
)) {
246 if (! more_elements
) {
247 return (TRUE
); /* we are done */
250 * the unfortunate side effect of non-recursion is that in
251 * the case of freeing we must remember the next object
252 * before we free the current object ...
255 next
= (*rp
)->rpcb_entry_next
;
256 if (! xdr_reference(xdrs
, (caddr_t
*)rp
,
257 (u_int
)sizeof (rpcb_entry_list
),
258 (xdrproc_t
)xdr_rpcb_entry
)) {
265 * Note that in the subsequent iteration, next_copy
266 * gets nulled out by the xdr_reference
267 * but next itself survives.
270 rp
= &((*rp
)->rpcb_entry_next
);
277 * XDR remote call arguments
278 * written for XDR_ENCODE direction only
281 xdr_rpcb_rmtcallargs(xdrs
, p
)
283 struct rpcb_rmtcallargs
*p
;
285 struct r_rpcb_rmtcallargs
*objp
=
286 (struct r_rpcb_rmtcallargs
*)(void *)p
;
287 u_int lenposition
, argposition
, position
;
290 _DIAGASSERT(p
!= NULL
);
292 buf
= XDR_INLINE(xdrs
, 3 * BYTES_PER_XDR_UNIT
);
294 if (!xdr_u_int32_t(xdrs
, &objp
->prog
)) {
297 if (!xdr_u_int32_t(xdrs
, &objp
->vers
)) {
300 if (!xdr_u_int32_t(xdrs
, &objp
->proc
)) {
304 IXDR_PUT_U_INT32(buf
, objp
->prog
);
305 IXDR_PUT_U_INT32(buf
, objp
->vers
);
306 IXDR_PUT_U_INT32(buf
, objp
->proc
);
310 * All the jugglery for just getting the size of the arguments
312 lenposition
= XDR_GETPOS(xdrs
);
313 if (! xdr_u_int(xdrs
, &(objp
->args
.args_len
))) {
316 argposition
= XDR_GETPOS(xdrs
);
317 if (! (*objp
->xdr_args
)(xdrs
, objp
->args
.args_val
)) {
320 position
= XDR_GETPOS(xdrs
);
321 objp
->args
.args_len
= (u_int
)((u_long
)position
- (u_long
)argposition
);
322 XDR_SETPOS(xdrs
, lenposition
);
323 if (! xdr_u_int(xdrs
, &(objp
->args
.args_len
))) {
326 XDR_SETPOS(xdrs
, position
);
331 * XDR remote call results
332 * written for XDR_DECODE direction only
335 xdr_rpcb_rmtcallres(xdrs
, p
)
337 struct rpcb_rmtcallres
*p
;
340 struct r_rpcb_rmtcallres
*objp
= (struct r_rpcb_rmtcallres
*)(void *)p
;
342 _DIAGASSERT(p
!= NULL
);
344 if (!xdr_string(xdrs
, &objp
->addr
, (u_int
)~0)) {
347 if (!xdr_u_int(xdrs
, &objp
->results
.results_len
)) {
350 dummy
= (*(objp
->xdr_res
))(xdrs
, objp
->results
.results_val
);
355 xdr_netbuf(xdrs
, objp
)
361 _DIAGASSERT(objp
!= NULL
);
363 if (!xdr_u_int32_t(xdrs
, (u_int32_t
*) &objp
->maxlen
)) {
366 dummy
= xdr_bytes(xdrs
, (char **)(void *)&(objp
->buf
),
367 (u_int
*)&(objp
->len
), objp
->maxlen
);