clnt_raw.c 5.6 KB

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