2 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
3 * unrestricted use provided that this legend is included on all tape
4 * media and as a part of the software program in whole or part. Users
5 * may copy or modify Sun RPC without charge, but are not authorized
6 * to license or distribute it to anyone else except as part of a product or
7 * program developed by the user.
9 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
10 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
11 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
13 * Sun RPC is provided with no support and without any obligation on the
14 * part of Sun Microsystems, Inc. to assist in its use, correction,
15 * modification or enhancement.
17 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
18 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
19 * OR ANY PART THEREOF.
21 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
22 * or profits or other special, indirect and consequential damages, even if
23 * Sun has been advised of the possibility of such damages.
25 * Sun Microsystems, Inc.
27 * Mountain View, California 94043
29 * @(#)rpcb_prot.c 1.13 94/04/24 SMI; 1.9 89/04/21 Copyr 1984 Sun Micro
30 * $NetBSD: rpcb_prot.c,v 1.3 2000/07/14 08:40:42 fvdl Exp $
31 * $FreeBSD: src/lib/libc/rpc/rpcb_prot.c,v 1.7 2007/11/20 01:51:20 jb Exp $
34 * Copyright (c) 1986-1991 by Sun Microsystems Inc.
39 * XDR routines for the rpcbinder version 3.
41 * Copyright (C) 1984, 1988, Sun Microsystems, Inc.
44 #include "namespace.h"
46 #include <rpc/types.h>
48 #include <rpc/rpcb_prot.h>
49 #include "un-namespace.h"
52 xdr_rpcb(XDR
*xdrs
, RPCB
*objp
)
54 if (!xdr_u_int32_t(xdrs
, &objp
->r_prog
)) {
57 if (!xdr_u_int32_t(xdrs
, &objp
->r_vers
)) {
60 if (!xdr_string(xdrs
, &objp
->r_netid
, (u_int
)~0)) {
63 if (!xdr_string(xdrs
, &objp
->r_addr
, (u_int
)~0)) {
66 if (!xdr_string(xdrs
, &objp
->r_owner
, (u_int
)~0)) {
73 * rpcblist_ptr implements a linked list. The RPCL definition from
78 * struct rpcblist *rpcb_next;
80 * typedef rpcblist *rpcblist_ptr;
82 * Recall that "pointers" in XDR are encoded as a boolean, indicating whether
83 * there's any data behind the pointer, followed by the data (if any exists).
84 * The boolean can be interpreted as ``more data follows me''; if FALSE then
85 * nothing follows the boolean; if TRUE then the boolean is followed by an
86 * actual struct rpcb, and another rpcblist_ptr (declared in RPCL as "struct
89 * This could be implemented via the xdr_pointer type, though this would
90 * result in one recursive call per element in the list. Rather than do that
91 * we can ``unwind'' the recursion into a while loop and use xdr_reference to
92 * serialize the rpcb elements.
96 xdr_rpcblist_ptr(XDR
*xdrs
, rpcblist_ptr
*rp
)
99 * more_elements is pre-computed in case the direction is
100 * XDR_ENCODE or XDR_FREE. more_elements is overwritten by
101 * xdr_bool when the direction is XDR_DECODE.
103 bool_t more_elements
;
104 int freeing
= (xdrs
->x_op
== XDR_FREE
);
106 rpcblist_ptr next_copy
;
110 more_elements
= (bool_t
)(*rp
!= NULL
);
111 if (! xdr_bool(xdrs
, &more_elements
)) {
114 if (! more_elements
) {
115 return (TRUE
); /* we are done */
118 * the unfortunate side effect of non-recursion is that in
119 * the case of freeing we must remember the next object
120 * before we free the current object ...
123 next
= (*rp
)->rpcb_next
;
124 if (! xdr_reference(xdrs
, (caddr_t
*)rp
,
125 (u_int
)sizeof (rpcblist
), (xdrproc_t
)xdr_rpcb
)) {
132 * Note that in the subsequent iteration, next_copy
133 * gets nulled out by the xdr_reference
134 * but next itself survives.
137 rp
= &((*rp
)->rpcb_next
);
144 * xdr_rpcblist() is specified to take a RPCBLIST **, but is identical in
145 * functionality to xdr_rpcblist_ptr().
148 xdr_rpcblist(XDR
*xdrs
, RPCBLIST
**rp
)
152 dummy
= xdr_rpcblist_ptr(xdrs
, (rpcblist_ptr
*)rp
);
158 xdr_rpcb_entry(XDR
*xdrs
, rpcb_entry
*objp
)
160 if (!xdr_string(xdrs
, &objp
->r_maddr
, (u_int
)~0)) {
163 if (!xdr_string(xdrs
, &objp
->r_nc_netid
, (u_int
)~0)) {
166 if (!xdr_u_int32_t(xdrs
, &objp
->r_nc_semantics
)) {
169 if (!xdr_string(xdrs
, &objp
->r_nc_protofmly
, (u_int
)~0)) {
172 if (!xdr_string(xdrs
, &objp
->r_nc_proto
, (u_int
)~0)) {
179 xdr_rpcb_entry_list_ptr(XDR
*xdrs
, rpcb_entry_list_ptr
*rp
)
182 * more_elements is pre-computed in case the direction is
183 * XDR_ENCODE or XDR_FREE. more_elements is overwritten by
184 * xdr_bool when the direction is XDR_DECODE.
186 bool_t more_elements
;
187 int freeing
= (xdrs
->x_op
== XDR_FREE
);
188 rpcb_entry_list_ptr next
;
189 rpcb_entry_list_ptr next_copy
;
193 more_elements
= (bool_t
)(*rp
!= NULL
);
194 if (! xdr_bool(xdrs
, &more_elements
)) {
197 if (! more_elements
) {
198 return (TRUE
); /* we are done */
201 * the unfortunate side effect of non-recursion is that in
202 * the case of freeing we must remember the next object
203 * before we free the current object ...
206 next
= (*rp
)->rpcb_entry_next
;
207 if (! xdr_reference(xdrs
, (caddr_t
*)rp
,
208 (u_int
)sizeof (rpcb_entry_list
),
209 (xdrproc_t
)xdr_rpcb_entry
)) {
212 if (freeing
&& *rp
) {
216 * Note that in the subsequent iteration, next_copy
217 * gets nulled out by the xdr_reference
218 * but next itself survives.
221 rp
= &((*rp
)->rpcb_entry_next
);
228 * XDR remote call arguments
229 * written for XDR_ENCODE direction only
232 xdr_rpcb_rmtcallargs(XDR
*xdrs
, struct rpcb_rmtcallargs
*p
)
234 struct r_rpcb_rmtcallargs
*objp
=
235 (struct r_rpcb_rmtcallargs
*)(void *)p
;
236 u_int lenposition
, argposition
, position
;
239 buf
= XDR_INLINE(xdrs
, 3 * BYTES_PER_XDR_UNIT
);
241 if (!xdr_u_int32_t(xdrs
, &objp
->prog
)) {
244 if (!xdr_u_int32_t(xdrs
, &objp
->vers
)) {
247 if (!xdr_u_int32_t(xdrs
, &objp
->proc
)) {
251 IXDR_PUT_U_INT32(buf
, objp
->prog
);
252 IXDR_PUT_U_INT32(buf
, objp
->vers
);
253 IXDR_PUT_U_INT32(buf
, objp
->proc
);
257 * All the jugglery for just getting the size of the arguments
259 lenposition
= XDR_GETPOS(xdrs
);
260 if (! xdr_u_int(xdrs
, &(objp
->args
.args_len
))) {
263 argposition
= XDR_GETPOS(xdrs
);
264 if (! (*objp
->xdr_args
)(xdrs
, objp
->args
.args_val
)) {
267 position
= XDR_GETPOS(xdrs
);
268 objp
->args
.args_len
= (u_int
)((u_long
)position
- (u_long
)argposition
);
269 XDR_SETPOS(xdrs
, lenposition
);
270 if (! xdr_u_int(xdrs
, &(objp
->args
.args_len
))) {
273 XDR_SETPOS(xdrs
, position
);
278 * XDR remote call results
279 * written for XDR_DECODE direction only
282 xdr_rpcb_rmtcallres(XDR
*xdrs
, struct rpcb_rmtcallres
*p
)
285 struct r_rpcb_rmtcallres
*objp
= (struct r_rpcb_rmtcallres
*)(void *)p
;
287 if (!xdr_string(xdrs
, &objp
->addr
, (u_int
)~0)) {
290 if (!xdr_u_int(xdrs
, &objp
->results
.results_len
)) {
293 dummy
= (*(objp
->xdr_res
))(xdrs
, objp
->results
.results_val
);
298 xdr_netbuf(XDR
*xdrs
, struct netbuf
*objp
)
303 if (!xdr_u_int32_t(xdrs
, (u_int32_t
*) &objp
->maxlen
)) {
307 dummy
= xdr_bytes(xdrs
, (char **) pp
,
308 (u_int
*)&(objp
->len
), objp
->maxlen
);