2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
26 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
27 * unrestricted use provided that this legend is included on all tape
28 * media and as a part of the software program in whole or part. Users
29 * may copy or modify Sun RPC without charge, but are not authorized
30 * to license or distribute it to anyone else except as part of a product or
31 * program developed by the user.
33 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
34 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
35 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
37 * Sun RPC is provided with no support and without any obligation on the
38 * part of Sun Microsystems, Inc. to assist in its use, correction,
39 * modification or enhancement.
41 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
42 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
43 * OR ANY PART THEREOF.
45 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
46 * or profits or other special, indirect and consequential damages, even if
47 * Sun has been advised of the possibility of such damages.
49 * Sun Microsystems, Inc.
51 * Mountain View, California 94043
54 #if defined(LIBC_SCCS) && !defined(lint)
55 /*static char *sccsid = "from: @(#)clnt_raw.c 1.22 87/08/11 Copyr 1984 Sun Micro";*/
56 /*static char *sccsid = "from: @(#)clnt_raw.c 2.2 88/08/01 4.0 RPCSRC";*/
57 static char *rcsid
= "$Id: clnt_raw.c,v 1.3 2002/02/19 20:36:22 epeyton Exp $";
63 * Copyright (C) 1984, Sun Microsystems, Inc.
65 * Memory based rpc for simple testing and timing.
66 * Interface to create an rpc client and server in the same process.
67 * This lets us similate rpc and get round trip overhead, without
68 * any interference from the kernal.
75 extern bool_t
xdr_opaque_auth();
77 #define MCALL_MSG_SIZE 24
80 * This is the "network" we will be moving stuff over.
82 static struct clntraw_private
{
85 char _raw_buf
[UDPMSGSIZE
];
86 char mashl_callmsg
[MCALL_MSG_SIZE
];
90 static enum clnt_stat
clntraw_call();
91 static void clntraw_abort();
92 static void clntraw_geterr();
93 static bool_t
clntraw_freeres();
94 static bool_t
clntraw_control();
95 static void clntraw_destroy();
97 static struct clnt_ops client_ops
= {
109 * Create a client handle for memory based rpc.
112 clntraw_create(prog
, vers
)
116 register struct clntraw_private
*clp
= clntraw_private
;
117 struct rpc_msg call_msg
;
118 XDR
*xdrs
= &clp
->xdr_stream
;
119 CLIENT
*client
= &clp
->client_object
;
122 clp
= (struct clntraw_private
*)calloc(1, sizeof (*clp
));
125 clntraw_private
= clp
;
128 * pre-serialize the staic part of the call msg and stash it away
130 call_msg
.rm_direction
= CALL
;
131 call_msg
.rm_call
.cb_rpcvers
= RPC_MSG_VERSION
;
132 call_msg
.rm_call
.cb_prog
= prog
;
133 call_msg
.rm_call
.cb_vers
= vers
;
134 xdrmem_create(xdrs
, clp
->mashl_callmsg
, MCALL_MSG_SIZE
, XDR_ENCODE
);
135 if (! xdr_callhdr(xdrs
, &call_msg
)) {
136 perror("clnt_raw.c - Fatal header serialization error.");
138 clp
->mcnt
= XDR_GETPOS(xdrs
);
142 * Set xdrmem for client/server shared buffer
144 xdrmem_create(xdrs
, clp
->_raw_buf
, UDPMSGSIZE
, XDR_FREE
);
147 * create client handle
149 client
->cl_ops
= &client_ops
;
150 client
->cl_auth
= authnone_create();
154 static enum clnt_stat
155 clntraw_call(h
, proc
, xargs
, argsp
, xresults
, resultsp
, timeout
)
162 struct timeval timeout
;
164 register struct clntraw_private
*clp
= clntraw_private
;
165 register XDR
*xdrs
= &clp
->xdr_stream
;
167 enum clnt_stat status
;
168 struct rpc_err error
;
176 xdrs
->x_op
= XDR_ENCODE
;
178 ((struct rpc_msg
*)clp
->mashl_callmsg
)->rm_xid
++ ;
179 if ((! XDR_PUTBYTES(xdrs
, clp
->mashl_callmsg
, clp
->mcnt
)) ||
180 (! XDR_PUTLONG(xdrs
, (long *)&proc
)) ||
181 (! AUTH_MARSHALL(h
->cl_auth
, xdrs
)) ||
182 (! (*xargs
)(xdrs
, argsp
))) {
183 return (RPC_CANTENCODEARGS
);
185 (void)XDR_GETPOS(xdrs
); /* called just to cause overhead */
188 * We have to call server input routine here because this is
189 * all going on in one process. Yuk.
196 xdrs
->x_op
= XDR_DECODE
;
198 msg
.acpted_rply
.ar_verf
= _null_auth
;
199 msg
.acpted_rply
.ar_results
.where
= resultsp
;
200 msg
.acpted_rply
.ar_results
.proc
= xresults
;
201 if (! xdr_replymsg(xdrs
, &msg
))
202 return (RPC_CANTDECODERES
);
203 _seterr_reply(&msg
, &error
);
204 status
= error
.re_status
;
206 if (status
== RPC_SUCCESS
) {
207 if (! AUTH_VALIDATE(h
->cl_auth
, &msg
.acpted_rply
.ar_verf
)) {
208 status
= RPC_AUTHERROR
;
210 } /* end successful completion */
212 if (AUTH_REFRESH(h
->cl_auth
))
214 } /* end of unsuccessful completion */
216 if (status
== RPC_SUCCESS
) {
217 if (! AUTH_VALIDATE(h
->cl_auth
, &msg
.acpted_rply
.ar_verf
)) {
218 status
= RPC_AUTHERROR
;
220 if (msg
.acpted_rply
.ar_verf
.oa_base
!= NULL
) {
221 xdrs
->x_op
= XDR_FREE
;
222 (void)xdr_opaque_auth(xdrs
, &(msg
.acpted_rply
.ar_verf
));
236 clntraw_freeres(cl
, xdr_res
, res_ptr
)
241 register struct clntraw_private
*clp
= clntraw_private
;
242 register XDR
*xdrs
= &clp
->xdr_stream
;
247 rval
= (bool_t
) RPC_FAILED
;
250 xdrs
->x_op
= XDR_FREE
;
251 return ((*xdr_res
)(xdrs
, res_ptr
));