1 /*********************************************************************
2 * RPC for the Windows NT Operating System
3 * 1993 by Martin F. Gergeleit
4 * Users may use, copy or modify Sun RPC for the Windows NT Operating
5 * System according to the Sun copyright below.
7 * RPC for the Windows NT Operating System COMES WITH ABSOLUTELY NO
8 * WARRANTY, NOR WILL I BE LIABLE FOR ANY DAMAGES INCURRED FROM THE
9 * USE OF. USE ENTIRELY AT YOUR OWN RISK!!!
10 *********************************************************************/
12 /* @(#)clnt_raw.c 2.2 88/08/01 4.0 RPCSRC */
14 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
15 * unrestricted use provided that this legend is included on all tape
16 * media and as a part of the software program in whole or part. Users
17 * may copy or modify Sun RPC without charge, but are not authorized
18 * to license or distribute it to anyone else except as part of a product or
19 * program developed by the user.
21 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
22 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
25 * Sun RPC is provided with no support and without any obligation on the
26 * part of Sun Microsystems, Inc. to assist in its use, correction,
27 * modification or enhancement.
29 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
30 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
31 * OR ANY PART THEREOF.
33 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
34 * or profits or other special, indirect and consequential damages, even if
35 * Sun has been advised of the possibility of such damages.
37 * Sun Microsystems, Inc.
39 * Mountain View, California 94043
41 #if !defined(lint) && defined(SCCSIDS)
42 static char sccsid[] = "@(#)clnt_raw.c 1.22 87/08/11 Copyr 1984 Sun Micro";
48 * Copyright (C) 1984, Sun Microsystems, Inc.
50 * Memory based rpc for simple testing and timing.
51 * Interface to create an rpc client and server in the same process.
52 * This lets us similate rpc and get round trip overhead, without
53 * any interference from the kernal.
61 #define MCALL_MSG_SIZE 24
64 * This is the "network" we will be moving stuff over.
66 static struct clntraw_private {
69 char _raw_buf[UDPMSGSIZE];
70 char mashl_callmsg[MCALL_MSG_SIZE];
74 static enum clnt_stat clntraw_call();
75 static void clntraw_abort();
76 static void clntraw_geterr();
77 static bool_t clntraw_freeres();
78 static bool_t clntraw_control();
79 static void clntraw_destroy();
81 static struct clnt_ops client_ops = {
93 * Create a client handle for memory based rpc.
96 clntraw_create(prog, vers)
100 register struct clntraw_private *clp = clntraw_private;
101 struct rpc_msg call_msg;
102 XDR *xdrs = &clp->xdr_stream;
103 CLIENT *client = &clp->client_object;
106 clp = (struct clntraw_private *)calloc(1, sizeof (*clp));
109 clntraw_private = clp;
112 * pre-serialize the staic part of the call msg and stash it away
114 call_msg.rm_direction = CALL;
115 call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
116 call_msg.rm_call.cb_prog = prog;
117 call_msg.rm_call.cb_vers = vers;
118 xdrmem_create(xdrs, clp->mashl_callmsg, MCALL_MSG_SIZE, XDR_ENCODE);
119 if (! xdr_callhdr(xdrs, &call_msg)) {
120 perror("clnt_raw.c - Fatal header serialization error.");
122 clp->mcnt = XDR_GETPOS(xdrs);
126 * Set xdrmem for client/server shared buffer
128 xdrmem_create(xdrs, clp->_raw_buf, UDPMSGSIZE, XDR_FREE);
131 * create client handle
133 client->cl_ops = &client_ops;
134 client->cl_auth = authnone_create();
138 static enum clnt_stat
139 clntraw_call(h, proc, xargs, argsp, xresults, resultsp, timeout)
146 struct timeval timeout;
148 register struct clntraw_private *clp = clntraw_private;
149 register XDR *xdrs = &clp->xdr_stream;
151 enum clnt_stat status;
152 struct rpc_err error;
160 xdrs->x_op = XDR_ENCODE;
162 ((struct rpc_msg *)clp->mashl_callmsg)->rm_xid ++ ;
163 if ((! XDR_PUTBYTES(xdrs, clp->mashl_callmsg, clp->mcnt)) ||
164 (! XDR_PUTLONG(xdrs, (long *)&proc)) ||
165 (! AUTH_MARSHALL(h->cl_auth, xdrs)) ||
166 (! (*xargs)(xdrs, argsp))) {
167 return (RPC_CANTENCODEARGS);
169 (void)XDR_GETPOS(xdrs); /* called just to cause overhead */
172 * We have to call server input routine here because this is
173 * all going on in one process. Yuk.
180 xdrs->x_op = XDR_DECODE;
182 msg.acpted_rply.ar_verf = _null_auth;
183 msg.acpted_rply.ar_results.where = resultsp;
184 msg.acpted_rply.ar_results.proc = xresults;
185 if (! xdr_replymsg(xdrs, &msg))
186 return (RPC_CANTDECODERES);
187 _seterr_reply(&msg, &error);
188 status = error.re_status;
190 if (status == RPC_SUCCESS) {
191 if (! AUTH_VALIDATE(h->cl_auth, &msg.acpted_rply.ar_verf)) {
192 status = RPC_AUTHERROR;
194 } /* end successful completion */
196 if (AUTH_REFRESH(h->cl_auth))
198 } /* end of unsuccessful completion */
200 if (status == RPC_SUCCESS) {
201 if (! AUTH_VALIDATE(h->cl_auth, &msg.acpted_rply.ar_verf)) {
202 status = RPC_AUTHERROR;
204 if (msg.acpted_rply.ar_verf.oa_base != NULL) {
205 xdrs->x_op = XDR_FREE;
206 (void)xdr_opaque_auth(xdrs, &(msg.acpted_rply.ar_verf));
220 clntraw_freeres(cl, xdr_res, res_ptr)
225 register struct clntraw_private *clp = clntraw_private;
226 register XDR *xdrs = &clp->xdr_stream;
231 rval = (bool_t) RPC_FAILED;
234 xdrs->x_op = XDR_FREE;
235 return ((*xdr_res)(xdrs, res_ptr));