1: /*
   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.
   8:  *
   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.
  12:  *
  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.
  16:  *
  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.
  20:  *
  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.
  24:  *
  25:  * Sun Microsystems, Inc.
  26:  * 2550 Garcia Avenue
  27:  * Mountain View, California  94043
  28:  */
  29: #ifndef lint
  30: static char sccsid[] = "@(#)clnt_raw.c 1.4 85/03/17 Copyr 1984 Sun Micro";
  31: #endif
  32: 
  33: /*
  34:  * clnt_raw.c
  35:  *
  36:  * Copyright (C) 1984, Sun Microsystems, Inc.
  37:  *
  38:  * Memory based rpc for simple testing and timing.
  39:  * Interface to create an rpc client and server in the same process.
  40:  * This lets us similate rpc and get round trip overhead, without
  41:  * any interference from the kernal.
  42:  */
  43: 
  44: #include "types.h"
  45: #include <sys/time.h>
  46: #include <netinet/in.h>
  47: #include "xdr.h"
  48: #include "auth.h"
  49: #include "clnt.h"
  50: #include "rpc_msg.h"
  51: 
  52: #define NULL ((caddr_t)0)
  53: #define MCALL_MSG_SIZE 24
  54: 
  55: /*
  56:  * This is the "network" we will be moving stuff over.
  57:  */
  58: char _raw_buf[UDPMSGSIZE];
  59: 
  60: static char mashl_callmsg[MCALL_MSG_SIZE];
  61: static u_int    mcnt;
  62: 
  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 void     clntraw_destroy();
  68: 
  69: static struct clnt_ops client_ops = {
  70:     clntraw_call,
  71:     clntraw_abort,
  72:     clntraw_geterr,
  73:     clntraw_freeres,
  74:     clntraw_destroy
  75: };
  76: 
  77: static CLIENT   client_object;
  78: static CLIENT   *client = &client_object;
  79: static XDR  xdr_stream;
  80: 
  81: void    svc_getreq();
  82: 
  83: /*
  84:  * Create a client handle for memory based rpc.
  85:  */
  86: CLIENT *
  87: clntraw_create(prog, vers)
  88:     u_long prog;
  89:     u_long vers;
  90: {
  91:     struct rpc_msg call_msg;
  92:     XDR *xdrs = &xdr_stream;
  93: 
  94:     /*
  95: 	 * pre-serialize the staic part of the call msg and stash it away
  96: 	 */
  97:     call_msg.rm_direction = CALL;
  98:     call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
  99:     call_msg.rm_call.cb_prog = prog;
 100:     call_msg.rm_call.cb_vers = vers;
 101:     xdrmem_create(xdrs, mashl_callmsg, MCALL_MSG_SIZE, XDR_ENCODE);
 102:     if (! xdr_callhdr(xdrs, &call_msg)) {
 103:         perror("clnt_raw.c - Fatal header serialization error.");
 104:     }
 105:     mcnt = XDR_GETPOS(xdrs);
 106:     XDR_DESTROY(xdrs);
 107: 
 108:     /*
 109: 	 * Set xdrmem for client/server shared buffer
 110: 	 */
 111:     xdrmem_create(xdrs, _raw_buf, UDPMSGSIZE, XDR_FREE);
 112: 
 113:     /*
 114: 	 * create client handle
 115: 	 */
 116:     client->cl_ops = &client_ops;
 117:     client->cl_auth = authnone_create();
 118:     return (client);
 119: }
 120: 
 121: static enum clnt_stat
 122: clntraw_call(h, proc, xargs, argsp, xresults, resultsp, timeout)
 123:     CLIENT *h;
 124:     u_long proc;
 125:     xdrproc_t xargs;
 126:     caddr_t argsp;
 127:     xdrproc_t xresults;
 128:     caddr_t resultsp;
 129:     struct timeval timeout;
 130: {
 131:     register XDR *xdrs = &xdr_stream;
 132:     struct rpc_msg msg;
 133:     enum clnt_stat status;
 134:     struct rpc_err error;
 135: 
 136: call_again:
 137:     /*
 138: 	 * send request
 139: 	 */
 140:     xdrs->x_op = XDR_ENCODE;
 141:     XDR_SETPOS(xdrs, 0);
 142:     ((struct rpc_msg *)mashl_callmsg)->rm_xid ++ ;
 143:     if ((! XDR_PUTBYTES(xdrs, mashl_callmsg, mcnt)) ||
 144:         (! XDR_PUTLONG(xdrs, (long *)&proc)) ||
 145:         (! AUTH_MARSHALL(h->cl_auth, xdrs)) ||
 146:         (! (*xargs)(xdrs, argsp))) {
 147:         return (RPC_CANTENCODEARGS);
 148:     }
 149:     (void)XDR_GETPOS(xdrs);  /* called just to cause overhead */
 150: 
 151:     /*
 152: 	 * We have to call server input routine here because this is
 153: 	 * all going on in one process. Yuk.
 154: 	 */
 155:     svc_getreq(1);
 156: 
 157:     /*
 158: 	 * get results
 159: 	 */
 160:     xdrs->x_op = XDR_DECODE;
 161:     XDR_SETPOS(xdrs, 0);
 162:     msg.acpted_rply.ar_verf = _null_auth;
 163:     msg.acpted_rply.ar_results.where = resultsp;
 164:     msg.acpted_rply.ar_results.proc = xresults;
 165:     if (! xdr_replymsg(xdrs, &msg))
 166:         return (RPC_CANTDECODERES);
 167:     _seterr_reply(&msg, &error);
 168:     status = error.re_status;
 169: 
 170:     if (status == RPC_SUCCESS) {
 171:         if (! AUTH_VALIDATE(h->cl_auth, &msg.acpted_rply.ar_verf)) {
 172:             status = RPC_AUTHERROR;
 173:         }
 174:     }  /* end successful completion */
 175:     else {
 176:         if (AUTH_REFRESH(h->cl_auth))
 177:             goto call_again;
 178:     }  /* end of unsuccessful completion */
 179: 
 180:     if (status == RPC_SUCCESS) {
 181:         if (! AUTH_VALIDATE(h->cl_auth, &msg.acpted_rply.ar_verf)) {
 182:             status = RPC_AUTHERROR;
 183:         }
 184:         if (msg.acpted_rply.ar_verf.oa_base != NULL) {
 185:             xdrs->x_op = XDR_FREE;
 186:             (void)xdr_opaque_auth(xdrs, &(msg.acpted_rply.ar_verf));
 187:         }
 188:     }
 189: 
 190:     return (status);
 191: }
 192: 
 193: static void
 194: clntraw_geterr()
 195: {
 196: }
 197: 
 198: 
 199: static bool_t
 200: clntraw_freeres(cl, xdr_res, res_ptr)
 201:     CLIENT *cl;
 202:     xdrproc_t xdr_res;
 203:     caddr_t res_ptr;
 204: {
 205:     register XDR *xdrs = &xdr_stream;
 206: 
 207:     xdrs->x_op = XDR_FREE;
 208:     return ((*xdr_res)(xdrs, res_ptr));
 209: }
 210: 
 211: static void
 212: clntraw_abort()
 213: {
 214: }
 215: 
 216: static void
 217: clntraw_destroy()
 218: {
 219: }

Defined functions

clntraw_abort defined in line 211; used 2 times
clntraw_call defined in line 121; used 2 times
clntraw_create defined in line 86; used 1 times
clntraw_destroy defined in line 216; used 2 times
clntraw_freeres defined in line 199; used 2 times
clntraw_geterr defined in line 193; used 2 times

Defined variables

_raw_buf defined in line 58; used 2 times
bool_t defined in line 199; never used
client_ops defined in line 69; used 1 times
mashl_callmsg defined in line 60; used 3 times
sccsid defined in line 30; never used

Defined macros

MCALL_MSG_SIZE defined in line 53; used 2 times
NULL defined in line 52; used 1 times
Last modified: 1985-04-19
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1224
Valid CSS Valid XHTML 1.0 Strict