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 $
35 * Copyright (c) 1986-1991 by Sun Microsystems Inc.
40 * XDR routines for the rpcbinder version 3.
42 * Copyright (C) 1984, 1988, Sun Microsystems, Inc.
45 #include "namespace.h"
47 #include <rpc/types.h>
49 #include <rpc/rpcb_prot.h>
50 #include "un-namespace.h"
53 xdr_rpcb(XDR
*xdrs
, RPCB
*objp
)
55 if (!xdr_u_int32_t(xdrs
, &objp
->r_prog
)) {
58 if (!xdr_u_int32_t(xdrs
, &objp
->r_vers
)) {
61 if (!xdr_string(xdrs
, &objp
->r_netid
, (u_int
)~0)) {
64 if (!xdr_string(xdrs
, &objp
->r_addr
, (u_int
)~0)) {
67 if (!xdr_string(xdrs
, &objp
->r_owner
, (u_int
)~0)) {
74 * rpcblist_ptr implements a linked list. The RPCL definition from
79 * struct rpcblist *rpcb_next;
81 * typedef rpcblist *rpcblist_ptr;
83 * Recall that "pointers" in XDR are encoded as a boolean, indicating whether
84 * there's any data behind the pointer, followed by the data (if any exists).
85 * The boolean can be interpreted as ``more data follows me''; if FALSE then
86 * nothing follows the boolean; if TRUE then the boolean is followed by an
87 * actual struct rpcb, and another rpcblist_ptr (declared in RPCL as "struct
90 * This could be implemented via the xdr_pointer type, though this would
91 * result in one recursive call per element in the list. Rather than do that
92 * we can ``unwind'' the recursion into a while loop and use xdr_reference to
93 * serialize the rpcb elements.
97 xdr_rpcblist_ptr(XDR
*xdrs
, rpcblist_ptr
*rp
)
100 * more_elements is pre-computed in case the direction is
101 * XDR_ENCODE or XDR_FREE. more_elements is overwritten by
102 * xdr_bool when the direction is XDR_DECODE.
104 bool_t more_elements
;
105 int freeing
= (xdrs
->x_op
== XDR_FREE
);
107 rpcblist_ptr next_copy
;
111 more_elements
= (bool_t
)(*rp
!= NULL
);
112 if (! xdr_bool(xdrs
, &more_elements
)) {
115 if (! more_elements
) {
116 return (TRUE
); /* we are done */
119 * the unfortunate side effect of non-recursion is that in
120 * the case of freeing we must remember the next object
121 * before we free the current object ...
124 next
= (*rp
)->rpcb_next
;
125 if (! xdr_reference(xdrs
, (caddr_t
*)rp
,
126 (u_int
)sizeof (rpcblist
), (xdrproc_t
)xdr_rpcb
)) {
133 * Note that in the subsequent iteration, next_copy
134 * gets nulled out by the xdr_reference
135 * but next itself survives.
138 rp
= &((*rp
)->rpcb_next
);
145 * xdr_rpcblist() is specified to take a RPCBLIST **, but is identical in
146 * functionality to xdr_rpcblist_ptr().
149 xdr_rpcblist(XDR
*xdrs
, RPCBLIST
**rp
)
153 dummy
= xdr_rpcblist_ptr(xdrs
, (rpcblist_ptr
*)rp
);
159 xdr_rpcb_entry(XDR
*xdrs
, rpcb_entry
*objp
)
161 if (!xdr_string(xdrs
, &objp
->r_maddr
, (u_int
)~0)) {
164 if (!xdr_string(xdrs
, &objp
->r_nc_netid
, (u_int
)~0)) {
167 if (!xdr_u_int32_t(xdrs
, &objp
->r_nc_semantics
)) {
170 if (!xdr_string(xdrs
, &objp
->r_nc_protofmly
, (u_int
)~0)) {
173 if (!xdr_string(xdrs
, &objp
->r_nc_proto
, (u_int
)~0)) {
180 xdr_rpcb_entry_list_ptr(XDR
*xdrs
, rpcb_entry_list_ptr
*rp
)
183 * more_elements is pre-computed in case the direction is
184 * XDR_ENCODE or XDR_FREE. more_elements is overwritten by
185 * xdr_bool when the direction is XDR_DECODE.
187 bool_t more_elements
;
188 int freeing
= (xdrs
->x_op
== XDR_FREE
);
189 rpcb_entry_list_ptr next
;
190 rpcb_entry_list_ptr next_copy
;
194 more_elements
= (bool_t
)(*rp
!= NULL
);
195 if (! xdr_bool(xdrs
, &more_elements
)) {
198 if (! more_elements
) {
199 return (TRUE
); /* we are done */
202 * the unfortunate side effect of non-recursion is that in
203 * the case of freeing we must remember the next object
204 * before we free the current object ...
207 next
= (*rp
)->rpcb_entry_next
;
208 if (! xdr_reference(xdrs
, (caddr_t
*)rp
,
209 (u_int
)sizeof (rpcb_entry_list
),
210 (xdrproc_t
)xdr_rpcb_entry
)) {
213 if (freeing
&& *rp
) {
217 * Note that in the subsequent iteration, next_copy
218 * gets nulled out by the xdr_reference
219 * but next itself survives.
222 rp
= &((*rp
)->rpcb_entry_next
);
229 * XDR remote call arguments
230 * written for XDR_ENCODE direction only
233 xdr_rpcb_rmtcallargs(XDR
*xdrs
, struct rpcb_rmtcallargs
*p
)
235 struct r_rpcb_rmtcallargs
*objp
=
236 (struct r_rpcb_rmtcallargs
*)(void *)p
;
237 u_int lenposition
, argposition
, position
;
240 buf
= XDR_INLINE(xdrs
, 3 * BYTES_PER_XDR_UNIT
);
242 if (!xdr_u_int32_t(xdrs
, &objp
->prog
)) {
245 if (!xdr_u_int32_t(xdrs
, &objp
->vers
)) {
248 if (!xdr_u_int32_t(xdrs
, &objp
->proc
)) {
252 IXDR_PUT_U_INT32(buf
, objp
->prog
);
253 IXDR_PUT_U_INT32(buf
, objp
->vers
);
254 IXDR_PUT_U_INT32(buf
, objp
->proc
);
258 * All the jugglery for just getting the size of the arguments
260 lenposition
= XDR_GETPOS(xdrs
);
261 if (! xdr_u_int(xdrs
, &(objp
->args
.args_len
))) {
264 argposition
= XDR_GETPOS(xdrs
);
265 if (! (*objp
->xdr_args
)(xdrs
, objp
->args
.args_val
)) {
268 position
= XDR_GETPOS(xdrs
);
269 objp
->args
.args_len
= (u_int
)((u_long
)position
- (u_long
)argposition
);
270 XDR_SETPOS(xdrs
, lenposition
);
271 if (! xdr_u_int(xdrs
, &(objp
->args
.args_len
))) {
274 XDR_SETPOS(xdrs
, position
);
279 * XDR remote call results
280 * written for XDR_DECODE direction only
283 xdr_rpcb_rmtcallres(XDR
*xdrs
, struct rpcb_rmtcallres
*p
)
286 struct r_rpcb_rmtcallres
*objp
= (struct r_rpcb_rmtcallres
*)(void *)p
;
288 if (!xdr_string(xdrs
, &objp
->addr
, (u_int
)~0)) {
291 if (!xdr_u_int(xdrs
, &objp
->results
.results_len
)) {
294 dummy
= (*(objp
->xdr_res
))(xdrs
, objp
->results
.results_val
);
299 xdr_netbuf(XDR
*xdrs
, struct netbuf
*objp
)
304 if (!xdr_u_int32_t(xdrs
, (u_int32_t
*) &objp
->maxlen
)) {
308 dummy
= xdr_bytes(xdrs
, (char **) pp
,
309 (u_int
*)&(objp
->len
), objp
->maxlen
);