clnt.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. /* @(#)clnt.h 2.1 88/07/29 4.0 RPCSRC; from 1.31 88/02/08 SMI*/
  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. /*
  31. * clnt.h - Client side remote procedure call interface.
  32. *
  33. * Copyright (C) 1984, Sun Microsystems, Inc.
  34. */
  35. #ifndef _CLNT_
  36. #define _CLNT_
  37. /*
  38. * Rpc calls return an enum clnt_stat. This should be looked at more,
  39. * since each implementation is required to live with this (implementation
  40. * independent) list of errors.
  41. */
  42. enum clnt_stat {
  43. RPC_SUCCESS=0, /* call succeeded */
  44. /*
  45. * local errors
  46. */
  47. RPC_CANTENCODEARGS=1, /* can't encode arguments */
  48. RPC_CANTDECODERES=2, /* can't decode results */
  49. RPC_CANTSEND=3, /* failure in sending call */
  50. RPC_CANTRECV=4, /* failure in receiving result */
  51. RPC_TIMEDOUT=5, /* call timed out */
  52. /*
  53. * remote errors
  54. */
  55. RPC_VERSMISMATCH=6, /* rpc versions not compatible */
  56. RPC_AUTHERROR=7, /* authentication error */
  57. RPC_PROGUNAVAIL=8, /* program not available */
  58. RPC_PROGVERSMISMATCH=9, /* program version mismatched */
  59. RPC_PROCUNAVAIL=10, /* procedure unavailable */
  60. RPC_CANTDECODEARGS=11, /* decode arguments error */
  61. RPC_SYSTEMERROR=12, /* generic "other problem" */
  62. /*
  63. * callrpc & clnt_create errors
  64. */
  65. RPC_UNKNOWNHOST=13, /* unknown host name */
  66. RPC_UNKNOWNPROTO=17, /* unkown protocol */
  67. /*
  68. * _ create errors
  69. */
  70. RPC_PMAPFAILURE=14, /* the pmapper failed in its call */
  71. RPC_PROGNOTREGISTERED=15, /* remote program is not registered */
  72. /*
  73. * unspecified error
  74. */
  75. RPC_FAILED=16
  76. };
  77. /*
  78. * Error info.
  79. */
  80. struct rpc_err {
  81. enum clnt_stat re_status;
  82. union {
  83. int RE_errno; /* realated system error */
  84. enum auth_stat RE_why; /* why the auth error occurred */
  85. struct {
  86. u_long low; /* lowest verion supported */
  87. u_long high; /* highest verion supported */
  88. } RE_vers;
  89. struct { /* maybe meaningful if RPC_FAILED */
  90. long s1;
  91. long s2;
  92. } RE_lb; /* life boot & debugging only */
  93. } ru;
  94. #define re_errno ru.RE_errno
  95. #define re_why ru.RE_why
  96. #define re_vers ru.RE_vers
  97. #define re_lb ru.RE_lb
  98. };
  99. /*
  100. * Client rpc handle.
  101. * Created by individual implementations, see e.g. rpc_udp.c.
  102. * Client is responsible for initializing auth, see e.g. auth_none.c.
  103. */
  104. typedef struct {
  105. AUTH *cl_auth; /* authenticator */
  106. struct clnt_ops {
  107. enum clnt_stat (*cl_call)(); /* call remote procedure */
  108. void (*cl_abort)(); /* abort a call */
  109. void (*cl_geterr)(); /* get specific error code */
  110. bool_t (*cl_freeres)(); /* frees results */
  111. void (*cl_destroy)();/* destroy this structure */
  112. bool_t (*cl_control)();/* the ioctl() of rpc */
  113. } *cl_ops;
  114. caddr_t cl_private; /* private stuff */
  115. } CLIENT;
  116. /*
  117. * client side rpc interface ops
  118. *
  119. * Parameter types are:
  120. *
  121. */
  122. /*
  123. * enum clnt_stat
  124. * CLNT_CALL(rh, proc, xargs, argsp, xres, resp, timeout)
  125. * CLIENT *rh;
  126. * u_long proc;
  127. * xdrproc_t xargs;
  128. * caddr_t argsp;
  129. * xdrproc_t xres;
  130. * caddr_t resp;
  131. * struct timeval timeout;
  132. */
  133. #define CLNT_CALL(rh, proc, xargs, argsp, xres, resp, secs) \
  134. ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, argsp, xres, resp, secs))
  135. #define clnt_call(rh, proc, xargs, argsp, xres, resp, secs) \
  136. ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, argsp, xres, resp, secs))
  137. /*
  138. * void
  139. * CLNT_ABORT(rh);
  140. * CLIENT *rh;
  141. */
  142. #define CLNT_ABORT(rh) ((*(rh)->cl_ops->cl_abort)(rh))
  143. #define clnt_abort(rh) ((*(rh)->cl_ops->cl_abort)(rh))
  144. /*
  145. * struct rpc_err
  146. * CLNT_GETERR(rh);
  147. * CLIENT *rh;
  148. */
  149. #define CLNT_GETERR(rh,errp) ((*(rh)->cl_ops->cl_geterr)(rh, errp))
  150. #define clnt_geterr(rh,errp) ((*(rh)->cl_ops->cl_geterr)(rh, errp))
  151. /*
  152. * bool_t
  153. * CLNT_FREERES(rh, xres, resp);
  154. * CLIENT *rh;
  155. * xdrproc_t xres;
  156. * caddr_t resp;
  157. */
  158. #define CLNT_FREERES(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
  159. #define clnt_freeres(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
  160. /*
  161. * bool_t
  162. * CLNT_CONTROL(cl, request, info)
  163. * CLIENT *cl;
  164. * u_int request;
  165. * char *info;
  166. */
  167. #define CLNT_CONTROL(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
  168. #define clnt_control(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
  169. /*
  170. * control operations that apply to both udp and tcp transports
  171. */
  172. #define CLSET_TIMEOUT 1 /* set timeout (timeval) */
  173. #define CLGET_TIMEOUT 2 /* get timeout (timeval) */
  174. #define CLGET_SERVER_ADDR 3 /* get server's address (sockaddr) */
  175. /*
  176. * udp only control operations
  177. */
  178. #define CLSET_RETRY_TIMEOUT 4 /* set retry timeout (timeval) */
  179. #define CLGET_RETRY_TIMEOUT 5 /* get retry timeout (timeval) */
  180. /*
  181. * void
  182. * CLNT_DESTROY(rh);
  183. * CLIENT *rh;
  184. */
  185. #define CLNT_DESTROY(rh) ((*(rh)->cl_ops->cl_destroy)(rh))
  186. #define clnt_destroy(rh) ((*(rh)->cl_ops->cl_destroy)(rh))
  187. /*
  188. * RPCTEST is a test program which is accessable on every rpc
  189. * transport/port. It is used for testing, performance evaluation,
  190. * and network administration.
  191. */
  192. #define RPCTEST_PROGRAM ((u_long)1)
  193. #define RPCTEST_VERSION ((u_long)1)
  194. #define RPCTEST_NULL_PROC ((u_long)2)
  195. #define RPCTEST_NULL_BATCH_PROC ((u_long)3)
  196. /*
  197. * By convention, procedure 0 takes null arguments and returns them
  198. */
  199. #define NULLPROC ((u_long)0)
  200. /*
  201. * Below are the client handle creation routines for the various
  202. * implementations of client side rpc. They can return NULL if a
  203. * creation failure occurs.
  204. */
  205. /*
  206. * Memory based rpc (for speed check and testing)
  207. * CLIENT *
  208. * clntraw_create(prog, vers)
  209. * u_long prog;
  210. * u_long vers;
  211. */
  212. extern CLIENT *clntraw_create();
  213. /*
  214. * Generic client creation routine. Supported protocols are "udp" and "tcp"
  215. */
  216. extern CLIENT *
  217. clnt_create(/*host, prog, vers, prot*/); /*
  218. char *host; -- hostname
  219. u_long prog; -- program number
  220. u_long vers; -- version number
  221. char *prot; -- protocol
  222. */
  223. /*
  224. * TCP based rpc
  225. * CLIENT *
  226. * clnttcp_create(raddr, prog, vers, sockp, sendsz, recvsz)
  227. * struct sockaddr_in *raddr;
  228. * u_long prog;
  229. * u_long version;
  230. * register int *sockp;
  231. * u_int sendsz;
  232. * u_int recvsz;
  233. */
  234. extern CLIENT *clnttcp_create();
  235. /*
  236. * UDP based rpc.
  237. * CLIENT *
  238. * clntudp_create(raddr, program, version, wait, sockp)
  239. * struct sockaddr_in *raddr;
  240. * u_long program;
  241. * u_long version;
  242. * struct timeval wait;
  243. * int *sockp;
  244. *
  245. * Same as above, but you specify max packet sizes.
  246. * CLIENT *
  247. * clntudp_bufcreate(raddr, program, version, wait, sockp, sendsz, recvsz)
  248. * struct sockaddr_in *raddr;
  249. * u_long program;
  250. * u_long version;
  251. * struct timeval wait;
  252. * int *sockp;
  253. * u_int sendsz;
  254. * u_int recvsz;
  255. */
  256. extern CLIENT *clntudp_create();
  257. extern CLIENT *clntudp_bufcreate();
  258. /*
  259. * Print why creation failed
  260. */
  261. void clnt_pcreateerror(/* char *msg */); /* stderr */
  262. char *clnt_spcreateerror(/* char *msg */); /* string */
  263. /*
  264. * Like clnt_perror(), but is more verbose in its output
  265. */
  266. void clnt_perrno(/* enum clnt_stat num */); /* stderr */
  267. /*
  268. * Print an English error message, given the client error code
  269. */
  270. void clnt_perror(/* CLIENT *clnt, char *msg */); /* stderr */
  271. char *clnt_sperror(/* CLIENT *clnt, char *msg */); /* string */
  272. /*
  273. * If a creation fails, the following allows the user to figure out why.
  274. */
  275. struct rpc_createerr {
  276. enum clnt_stat cf_stat;
  277. struct rpc_err cf_error; /* useful when cf_stat == RPC_PMAPFAILURE */
  278. };
  279. extern struct rpc_createerr rpc_createerr;
  280. /*
  281. * Copy error message to buffer.
  282. */
  283. char *clnt_sperrno(/* enum clnt_stat num */); /* string */
  284. #define UDPMSGSIZE 8800 /* rpc imposed limit on udp msg size */
  285. #define RPCSMALLMSGSIZE 400 /* a more reasonable packet size */
  286. #endif /*!_CLNT_*/