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 * @(#)clnt_raw.c 1.22 87/08/11 Copyr 1984 Sun Micro
30 * @(#)clnt_raw.c 2.2 88/08/01 4.0 RPCSRC
31 * $FreeBSD: src/lib/libc/rpc/clnt_raw.c,v 1.10 1999/08/28 00:00:36 peter Exp $
32 * $DragonFly: src/lib/libcr/rpc/Attic/clnt_raw.c,v 1.3 2004/10/25 19:38:25 drhodus Exp $
38 * Copyright (C) 1984, Sun Microsystems, Inc.
40 * Memory based rpc for simple testing and timing.
41 * Interface to create an rpc client and server in the same process.
42 * This lets us similate rpc and get round trip overhead, without
43 * any interference from the kernal.
50 #define MCALL_MSG_SIZE 24
53 * This is the "network" we will be moving stuff over.
55 static struct clntraw_private {
58 char _raw_buf[UDPMSGSIZE];
59 char mashl_callmsg[MCALL_MSG_SIZE];
63 static enum clnt_stat clntraw_call();
64 static void clntraw_abort();
65 static void clntraw_geterr();
66 static bool_t clntraw_freeres();
67 static bool_t clntraw_control();
68 static void clntraw_destroy();
70 static struct clnt_ops client_ops = {
82 * Create a client handle for memory based rpc.
85 clntraw_create(prog, vers)
89 struct clntraw_private *clp = clntraw_private;
90 struct rpc_msg call_msg;
91 XDR *xdrs = &clp->xdr_stream;
92 CLIENT *client = &clp->client_object;
95 clp = (struct clntraw_private *)calloc(1, sizeof (*clp));
98 clntraw_private = clp;
101 * pre-serialize the static part of the call msg and stash it away
103 call_msg.rm_direction = CALL;
104 call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
105 call_msg.rm_call.cb_prog = prog;
106 call_msg.rm_call.cb_vers = vers;
107 xdrmem_create(xdrs, clp->mashl_callmsg, MCALL_MSG_SIZE, XDR_ENCODE);
108 if (! xdr_callhdr(xdrs, &call_msg)) {
109 perror("clnt_raw.c - Fatal header serialization error.");
111 clp->mcnt = XDR_GETPOS(xdrs);
115 * Set xdrmem for client/server shared buffer
117 xdrmem_create(xdrs, clp->_raw_buf, UDPMSGSIZE, XDR_FREE);
120 * create client handle
122 client->cl_ops = &client_ops;
123 client->cl_auth = authnone_create();
127 static enum clnt_stat
128 clntraw_call(h, proc, xargs, argsp, xresults, resultsp, timeout)
135 struct timeval timeout;
137 struct clntraw_private *clp = clntraw_private;
138 XDR *xdrs = &clp->xdr_stream;
140 enum clnt_stat status;
141 struct rpc_err error;
149 xdrs->x_op = XDR_ENCODE;
151 ((struct rpc_msg *)clp->mashl_callmsg)->rm_xid ++ ;
152 if ((! XDR_PUTBYTES(xdrs, clp->mashl_callmsg, clp->mcnt)) ||
153 (! XDR_PUTLONG(xdrs, (long *)&proc)) ||
154 (! AUTH_MARSHALL(h->cl_auth, xdrs)) ||
155 (! (*xargs)(xdrs, argsp))) {
156 return (RPC_CANTENCODEARGS);
158 (void)XDR_GETPOS(xdrs); /* called just to cause overhead */
161 * We have to call server input routine here because this is
162 * all going on in one process. Yuk.
169 xdrs->x_op = XDR_DECODE;
171 msg.acpted_rply.ar_verf = _null_auth;
172 msg.acpted_rply.ar_results.where = resultsp;
173 msg.acpted_rply.ar_results.proc = xresults;
174 if (! xdr_replymsg(xdrs, &msg))
175 return (RPC_CANTDECODERES);
176 _seterr_reply(&msg, &error);
177 status = error.re_status;
179 if (status == RPC_SUCCESS) {
180 if (! AUTH_VALIDATE(h->cl_auth, &msg.acpted_rply.ar_verf)) {
181 status = RPC_AUTHERROR;
183 } /* end successful completion */
185 if (AUTH_REFRESH(h->cl_auth))
187 } /* end of unsuccessful completion */
189 if (status == RPC_SUCCESS) {
190 if (! AUTH_VALIDATE(h->cl_auth, &msg.acpted_rply.ar_verf)) {
191 status = RPC_AUTHERROR;
193 if (msg.acpted_rply.ar_verf.oa_base != NULL) {
194 xdrs->x_op = XDR_FREE;
195 (void)xdr_opaque_auth(xdrs, &(msg.acpted_rply.ar_verf));
209 clntraw_freeres(cl, xdr_res, res_ptr)
214 struct clntraw_private *clp = clntraw_private;
215 XDR *xdrs = &clp->xdr_stream;
220 rval = (bool_t) RPC_FAILED;
223 xdrs->x_op = XDR_FREE;
224 return ((*xdr_res)(xdrs, res_ptr));