clnt_raw.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /* @(#)clnt_raw.c 2.2 88/08/01 4.0 RPCSRC */
  2. /*
  3. * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  4. * unrestricted use provided that this legend is included on all tape
  5. * media and as a part of the software program in whole or part. Users
  6. * may copy or modify Sun RPC without charge, but are not authorized
  7. * to license or distribute it to anyone else except as part of a product or
  8. * program developed by the user.
  9. *
  10. * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  11. * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  12. * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  13. *
  14. * Sun RPC is provided with no support and without any obligation on the
  15. * part of Sun Microsystems, Inc. to assist in its use, correction,
  16. * modification or enhancement.
  17. *
  18. * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  19. * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  20. * OR ANY PART THEREOF.
  21. *
  22. * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  23. * or profits or other special, indirect and consequential damages, even if
  24. * Sun has been advised of the possibility of such damages.
  25. *
  26. * Sun Microsystems, Inc.
  27. * 2550 Garcia Avenue
  28. * Mountain View, California 94043
  29. */
  30. #if !defined(lint) && defined(SCCSIDS)
  31. static char sccsid[] = "@(#)clnt_raw.c 1.22 87/08/11 Copyr 1984 Sun Micro";
  32. #endif
  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. #include <rpc/rpc.h>
  44. #define MCALL_MSG_SIZE 24
  45. /*
  46. * This is the "network" we will be moving stuff over.
  47. */
  48. static struct clntraw_private {
  49. CLIENT client_object;
  50. XDR xdr_stream;
  51. char _raw_buf[UDPMSGSIZE];
  52. char mashl_callmsg[MCALL_MSG_SIZE];
  53. u_int mcnt;
  54. } *clntraw_private;
  55. static enum clnt_stat clntraw_call();
  56. static void clntraw_abort();
  57. static void clntraw_geterr();
  58. static bool_t clntraw_freeres();
  59. static bool_t clntraw_control();
  60. static void clntraw_destroy();
  61. static struct clnt_ops client_ops = {
  62. clntraw_call,
  63. clntraw_abort,
  64. clntraw_geterr,
  65. clntraw_freeres,
  66. clntraw_destroy,
  67. clntraw_control
  68. };
  69. void svc_getreq();
  70. /*
  71. * Create a client handle for memory based rpc.
  72. */
  73. CLIENT *clntraw_create(prog, vers)
  74. u_long prog;
  75. u_long vers;
  76. {
  77. register struct clntraw_private *clp = clntraw_private;
  78. struct rpc_msg call_msg;
  79. XDR *xdrs = &clp->xdr_stream;
  80. CLIENT *client = &clp->client_object;
  81. if (clp == 0) {
  82. clp = (struct clntraw_private *) calloc(1, sizeof(*clp));
  83. if (clp == 0)
  84. return (0);
  85. clntraw_private = clp;
  86. }
  87. /*
  88. * pre-serialize the staic part of the call msg and stash it away
  89. */
  90. call_msg.rm_direction = CALL;
  91. call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
  92. call_msg.rm_call.cb_prog = prog;
  93. call_msg.rm_call.cb_vers = vers;
  94. xdrmem_create(xdrs, clp->mashl_callmsg, MCALL_MSG_SIZE, XDR_ENCODE);
  95. if (!xdr_callhdr(xdrs, &call_msg)) {
  96. perror("clnt_raw.c - Fatal header serialization error.");
  97. }
  98. clp->mcnt = XDR_GETPOS(xdrs);
  99. XDR_DESTROY(xdrs);
  100. /*
  101. * Set xdrmem for client/server shared buffer
  102. */
  103. xdrmem_create(xdrs, clp->_raw_buf, UDPMSGSIZE, XDR_FREE);
  104. /*
  105. * create client handle
  106. */
  107. client->cl_ops = &client_ops;
  108. client->cl_auth = authnone_create();
  109. return (client);
  110. }
  111. static enum clnt_stat
  112. clntraw_call(h, proc, xargs, argsp, xresults, resultsp, timeout)
  113. CLIENT *h;
  114. u_long proc;
  115. xdrproc_t xargs;
  116. caddr_t argsp;
  117. xdrproc_t xresults;
  118. caddr_t resultsp;
  119. struct timeval timeout;
  120. {
  121. register struct clntraw_private *clp = clntraw_private;
  122. register XDR *xdrs = &clp->xdr_stream;
  123. struct rpc_msg msg;
  124. enum clnt_stat status;
  125. struct rpc_err error;
  126. if (clp == 0)
  127. return (RPC_FAILED);
  128. call_again:
  129. /*
  130. * send request
  131. */
  132. xdrs->x_op = XDR_ENCODE;
  133. XDR_SETPOS(xdrs, 0);
  134. ((struct rpc_msg *) clp->mashl_callmsg)->rm_xid++;
  135. if ((!XDR_PUTBYTES(xdrs, clp->mashl_callmsg, clp->mcnt)) ||
  136. (!XDR_PUTLONG(xdrs, (long *) &proc)) ||
  137. (!AUTH_MARSHALL(h->cl_auth, xdrs)) || (!(*xargs) (xdrs, argsp))) {
  138. return (RPC_CANTENCODEARGS);
  139. }
  140. (void) XDR_GETPOS(xdrs); /* called just to cause overhead */
  141. /*
  142. * We have to call server input routine here because this is
  143. * all going on in one process. Yuk.
  144. */
  145. svc_getreq(1);
  146. /*
  147. * get results
  148. */
  149. xdrs->x_op = XDR_DECODE;
  150. XDR_SETPOS(xdrs, 0);
  151. msg.acpted_rply.ar_verf = _null_auth;
  152. msg.acpted_rply.ar_results.where = resultsp;
  153. msg.acpted_rply.ar_results.proc = xresults;
  154. if (!xdr_replymsg(xdrs, &msg))
  155. return (RPC_CANTDECODERES);
  156. _seterr_reply(&msg, &error);
  157. status = error.re_status;
  158. if (status == RPC_SUCCESS) {
  159. if (!AUTH_VALIDATE(h->cl_auth, &msg.acpted_rply.ar_verf)) {
  160. status = RPC_AUTHERROR;
  161. }
  162. } /* end successful completion */
  163. else {
  164. if (AUTH_REFRESH(h->cl_auth))
  165. goto call_again;
  166. } /* end of unsuccessful completion */
  167. if (status == RPC_SUCCESS) {
  168. if (!AUTH_VALIDATE(h->cl_auth, &msg.acpted_rply.ar_verf)) {
  169. status = RPC_AUTHERROR;
  170. }
  171. if (msg.acpted_rply.ar_verf.oa_base != NULL) {
  172. xdrs->x_op = XDR_FREE;
  173. (void) xdr_opaque_auth(xdrs, &(msg.acpted_rply.ar_verf));
  174. }
  175. }
  176. return (status);
  177. }
  178. static void clntraw_geterr()
  179. {
  180. }
  181. static bool_t clntraw_freeres(cl, xdr_res, res_ptr)
  182. CLIENT *cl;
  183. xdrproc_t xdr_res;
  184. caddr_t res_ptr;
  185. {
  186. register struct clntraw_private *clp = clntraw_private;
  187. register XDR *xdrs = &clp->xdr_stream;
  188. bool_t rval;
  189. if (clp == 0) {
  190. rval = (bool_t) RPC_FAILED;
  191. return (rval);
  192. }
  193. xdrs->x_op = XDR_FREE;
  194. return ((*xdr_res) (xdrs, res_ptr));
  195. }
  196. static void clntraw_abort()
  197. {
  198. }
  199. static bool_t clntraw_control()
  200. {
  201. return (FALSE);
  202. }
  203. static void clntraw_destroy()
  204. {
  205. }