xref: /titanic_41/usr/src/uts/common/rpc/rpcb_prot.c (revision 69bb4bb45c98da60d21839c4dc3c01ea1be60585)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 1997 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 /*
31  * Portions of this source code were derived from Berkeley 4.3 BSD
32  * under license from the Regents of the University of California.
33  */
34 
35 /*
36  * rpcb_prot.c
37  * XDR routines for the rpcbinder version 3.
38  */
39 
40 #pragma ident	"%Z%%M%	%I%	%E% SMI"
41 
42 #if !defined(lint) && defined(SCCSIDS)
43 static char sccsid[] = "@(#)rpcb_prot.c 1.9 89/04/21 Copyr 1984 Sun Micro";
44 #endif
45 
46 
47 #include <rpc/rpc.h>
48 #include <rpc/types.h>
49 #include <rpc/xdr.h>
50 #include <rpc/rpcb_prot.h>
51 
52 
53 bool_t
54 xdr_rpcb(XDR *xdrs, RPCB *objp)
55 {
56 	if (!xdr_rpcprog(xdrs, &objp->r_prog))
57 		return (FALSE);
58 	if (!xdr_rpcvers(xdrs, &objp->r_vers))
59 		return (FALSE);
60 	if (!xdr_string(xdrs, &objp->r_netid, ~0))
61 		return (FALSE);
62 	if (!xdr_string(xdrs, &objp->r_addr, ~0))
63 		return (FALSE);
64 	if (!xdr_string(xdrs, &objp->r_owner, ~0))
65 		return (FALSE);
66 	return (TRUE);
67 }
68 
69 /*
70  * XDR remote call arguments
71  * written for XDR_ENCODE direction only
72  */
73 bool_t
74 xdr_rpcb_rmtcallargs(XDR *xdrs, struct rpcb_rmtcallargs *objp)
75 {
76 	u_int lenposition, argposition, position;
77 
78 	if (!xdr_rpcprog(xdrs, &objp->prog))
79 		return (FALSE);
80 	if (!xdr_rpcvers(xdrs, &objp->vers))
81 		return (FALSE);
82 	if (!xdr_rpcproc(xdrs, &objp->proc))
83 		return (FALSE);
84 	/*
85 	 * All the jugglery for just getting the size of the arguments
86 	 */
87 	lenposition = XDR_GETPOS(xdrs);
88 	if (!xdr_u_int(xdrs, &(objp->arglen)))
89 	    return (FALSE);
90 	argposition = XDR_GETPOS(xdrs);
91 	if (!(*(objp->xdr_args))(xdrs, objp->args_ptr))
92 	    return (FALSE);
93 	position = XDR_GETPOS(xdrs);
94 	objp->arglen = (u_int)position - (u_int)argposition;
95 	XDR_SETPOS(xdrs, lenposition);
96 	if (!xdr_u_int(xdrs, &(objp->arglen)))
97 	    return (FALSE);
98 	XDR_SETPOS(xdrs, position);
99 	return (TRUE);
100 }
101 
102 /*
103  * XDR remote call results
104  * written for XDR_DECODE direction only
105  */
106 bool_t
107 xdr_rpcb_rmtcallres(XDR *xdrs, struct rpcb_rmtcallres *objp)
108 {
109 	if (!xdr_string(xdrs, &objp->addr_ptr, ~0))
110 		return (FALSE);
111 	if (!xdr_u_int(xdrs, &objp->resultslen))
112 		return (FALSE);
113 	return ((*(objp->xdr_results))(xdrs, objp->results_ptr));
114 }
115 
116 bool_t
117 xdr_netbuf(XDR *xdrs, struct netbuf *objp)
118 {
119 	/*
120 	 * If we're decoding and the caller has already allocated a buffer,
121 	 * throw away maxlen, since it doesn't apply to the caller's
122 	 * buffer.  xdr_bytes will return an error if the buffer isn't big
123 	 * enough.
124 	 */
125 	if (xdrs->x_op == XDR_DECODE && objp->buf != NULL) {
126 		u_int maxlen;
127 
128 		if (!xdr_u_int(xdrs, &maxlen))
129 			return (FALSE);
130 	} else {
131 		if (!xdr_u_int(xdrs, (u_int *)&objp->maxlen))
132 			return (FALSE);
133 	}
134 	return (xdr_bytes(xdrs, (char **)&(objp->buf),
135 	    (u_int *)&(objp->len), objp->maxlen));
136 }
137