clnt.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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 _RPC_CLNT_H
  36. #define _RPC_CLNT_H 1
  37. #include <rpc/types.h>
  38. #include <rpc/auth.h>
  39. #include <lwip/sockets.h>
  40. /*
  41. * Rpc calls return an enum clnt_stat. This should be looked at more,
  42. * since each implementation is required to live with this (implementation
  43. * independent) list of errors.
  44. */
  45. enum clnt_stat {
  46. RPC_SUCCESS=0, /* call succeeded */
  47. /*
  48. * local errors
  49. */
  50. RPC_CANTENCODEARGS=1, /* can't encode arguments */
  51. RPC_CANTDECODERES=2, /* can't decode results */
  52. RPC_CANTSEND=3, /* failure in sending call */
  53. RPC_CANTRECV=4, /* failure in receiving result */
  54. RPC_TIMEDOUT=5, /* call timed out */
  55. /*
  56. * remote errors
  57. */
  58. RPC_VERSMISMATCH=6, /* rpc versions not compatible */
  59. RPC_AUTHERROR=7, /* authentication error */
  60. RPC_PROGUNAVAIL=8, /* program not available */
  61. RPC_PROGVERSMISMATCH=9, /* program version mismatched */
  62. RPC_PROCUNAVAIL=10, /* procedure unavailable */
  63. RPC_CANTDECODEARGS=11, /* decode arguments error */
  64. RPC_SYSTEMERROR=12, /* generic "other problem" */
  65. RPC_NOBROADCAST = 21, /* Broadcasting not supported */
  66. /*
  67. * callrpc & clnt_create errors
  68. */
  69. RPC_UNKNOWNHOST=13, /* unknown host name */
  70. RPC_UNKNOWNPROTO=17, /* unknown protocol */
  71. RPC_UNKNOWNADDR = 19, /* Remote address unknown */
  72. /*
  73. * rpcbind errors
  74. */
  75. RPC_RPCBFAILURE=14, /* portmapper failed in its call */
  76. #define RPC_PMAPFAILURE RPC_RPCBFAILURE
  77. RPC_PROGNOTREGISTERED=15, /* remote program is not registered */
  78. RPC_N2AXLATEFAILURE = 22, /* Name to addr translation failed */
  79. /*
  80. * unspecified error
  81. */
  82. RPC_FAILED=16,
  83. RPC_INTR=18,
  84. RPC_TLIERROR=20,
  85. RPC_UDERROR=23,
  86. /*
  87. * asynchronous errors
  88. */
  89. RPC_INPROGRESS = 24,
  90. RPC_STALERACHANDLE = 25
  91. };
  92. /*
  93. * Error info.
  94. */
  95. struct rpc_err {
  96. int re_status;
  97. union {
  98. int RE_errno; /* related system error */
  99. int RE_why; /* why the auth error occurred */
  100. struct {
  101. unsigned long low; /* lowest verion supported */
  102. unsigned long high; /* highest verion supported */
  103. } RE_vers;
  104. struct { /* maybe meaningful if RPC_FAILED */
  105. long s1;
  106. long s2;
  107. } RE_lb; /* life boot & debugging only */
  108. } ru;
  109. #define re_errno ru.RE_errno
  110. #define re_why ru.RE_why
  111. #define re_vers ru.RE_vers
  112. #define re_lb ru.RE_lb
  113. };
  114. /*
  115. * Client rpc handle.
  116. * Created by individual implementations, see e.g. rpc_udp.c.
  117. * Client is responsible for initializing auth, see e.g. auth_none.c.
  118. */
  119. typedef struct CLIENT CLIENT;
  120. struct CLIENT {
  121. AUTH *cl_auth; /* authenticator */
  122. struct clnt_ops {
  123. enum clnt_stat (*cl_call) (CLIENT *, unsigned long, xdrproc_t, char*, xdrproc_t,
  124. char*, struct timeval);
  125. /* call remote procedure */
  126. void (*cl_abort) (void); /* abort a call */
  127. void (*cl_geterr) (CLIENT *, struct rpc_err *);
  128. /* get specific error code */
  129. bool_t (*cl_freeres) (CLIENT *, xdrproc_t, char*);
  130. /* frees results */
  131. void (*cl_destroy) (CLIENT *); /* destroy this structure */
  132. bool_t (*cl_control) (CLIENT *, int, char *);
  133. /* the ioctl() of rpc */
  134. } *cl_ops;
  135. char* cl_private; /* private stuff */
  136. };
  137. /*
  138. * client side rpc interface ops
  139. *
  140. * Parameter types are:
  141. *
  142. */
  143. /*
  144. * enum clnt_stat
  145. * CLNT_CALL(rh, proc, xargs, argsp, xres, resp, timeout)
  146. * CLIENT *rh;
  147. * unsigned long proc;
  148. * xdrproc_t xargs;
  149. * char* argsp;
  150. * xdrproc_t xres;
  151. * char* resp;
  152. * struct timeval timeout;
  153. */
  154. #define CLNT_CALL(rh, proc, xargs, argsp, xres, resp, secs) \
  155. ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, argsp, xres, resp, secs))
  156. #define clnt_call(rh, proc, xargs, argsp, xres, resp, secs) \
  157. ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, argsp, xres, resp, secs))
  158. /*
  159. * void
  160. * CLNT_ABORT(rh);
  161. * CLIENT *rh;
  162. */
  163. #define CLNT_ABORT(rh) ((*(rh)->cl_ops->cl_abort)(rh))
  164. #define clnt_abort(rh) ((*(rh)->cl_ops->cl_abort)(rh))
  165. /*
  166. * struct rpc_err
  167. * CLNT_GETERR(rh);
  168. * CLIENT *rh;
  169. */
  170. #define CLNT_GETERR(rh,errp) ((*(rh)->cl_ops->cl_geterr)(rh, errp))
  171. #define clnt_geterr(rh,errp) ((*(rh)->cl_ops->cl_geterr)(rh, errp))
  172. /*
  173. * bool_t
  174. * CLNT_FREERES(rh, xres, resp);
  175. * CLIENT *rh;
  176. * xdrproc_t xres;
  177. * char* resp;
  178. */
  179. #define CLNT_FREERES(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
  180. #define clnt_freeres(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
  181. /*
  182. * bool_t
  183. * CLNT_CONTROL(cl, request, info)
  184. * CLIENT *cl;
  185. * unsigned int request;
  186. * char *info;
  187. */
  188. #define CLNT_CONTROL(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
  189. #define clnt_control(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
  190. /*
  191. * control operations that apply to all transports
  192. *
  193. * Note: options marked XXX are no-ops in this implementation of RPC.
  194. * The are present in TI-RPC but can't be implemented here since they
  195. * depend on the presence of STREAMS/TLI, which we don't have.
  196. */
  197. #define CLSET_TIMEOUT 1 /* set timeout (timeval) */
  198. #define CLGET_TIMEOUT 2 /* get timeout (timeval) */
  199. #define CLGET_SERVER_ADDR 3 /* get server's address (sockaddr) */
  200. #define CLGET_FD 6 /* get connections file descriptor */
  201. #define CLGET_SVC_ADDR 7 /* get server's address (netbuf) XXX */
  202. #define CLSET_FD_CLOSE 8 /* close fd while clnt_destroy */
  203. #define CLSET_FD_NCLOSE 9 /* Do not close fd while clnt_destroy*/
  204. #define CLGET_XID 10 /* Get xid */
  205. #define CLSET_XID 11 /* Set xid */
  206. #define CLGET_VERS 12 /* Get version number */
  207. #define CLSET_VERS 13 /* Set version number */
  208. #define CLGET_PROG 14 /* Get program number */
  209. #define CLSET_PROG 15 /* Set program number */
  210. #define CLSET_SVC_ADDR 16 /* get server's address (netbuf) XXX */
  211. #define CLSET_PUSH_TIMOD 17 /* push timod if not already present XXX */
  212. #define CLSET_POP_TIMOD 18 /* pop timod XXX */
  213. /*
  214. * Connectionless only control operations
  215. */
  216. #define CLSET_RETRY_TIMEOUT 4 /* set retry timeout (timeval) */
  217. #define CLGET_RETRY_TIMEOUT 5 /* get retry timeout (timeval) */
  218. /*
  219. * void
  220. * CLNT_DESTROY(rh);
  221. * CLIENT *rh;
  222. */
  223. #define CLNT_DESTROY(rh) ((*(rh)->cl_ops->cl_destroy)(rh))
  224. #define clnt_destroy(rh) ((*(rh)->cl_ops->cl_destroy)(rh))
  225. /*
  226. * RPCTEST is a test program which is accessible on every rpc
  227. * transport/port. It is used for testing, performance evaluation,
  228. * and network administration.
  229. */
  230. #define RPCTEST_PROGRAM ((unsigned long)1)
  231. #define RPCTEST_VERSION ((unsigned long)1)
  232. #define RPCTEST_NULL_PROC ((unsigned long)2)
  233. #define RPCTEST_NULL_BATCH_PROC ((unsigned long)3)
  234. /*
  235. * By convention, procedure 0 takes null arguments and returns them
  236. */
  237. #define NULLPROC ((unsigned long)0)
  238. /*
  239. * Below are the client handle creation routines for the various
  240. * implementations of client side rpc. They can return NULL if a
  241. * creation failure occurs.
  242. */
  243. /*
  244. * Generic client creation routine. Supported protocols are "udp", "tcp" and
  245. * "unix"
  246. * CLIENT *
  247. * clnt_create(host, prog, vers, prot)
  248. * char *host; -- hostname
  249. * unsigned long prog; -- program number
  250. * u_ong vers; -- version number
  251. * char *prot; -- protocol
  252. */
  253. extern CLIENT *clnt_create (const char *__host, const unsigned long __prog,
  254. const unsigned long __vers, const char *__prot)
  255. ;
  256. /*
  257. * UDP based rpc.
  258. * CLIENT *
  259. * clntudp_create(raddr, program, version, wait, sockp)
  260. * struct sockaddr_in *raddr;
  261. * unsigned long program;
  262. * unsigned long version;
  263. * struct timeval wait_resend;
  264. * int *sockp;
  265. *
  266. * Same as above, but you specify max packet sizes.
  267. * CLIENT *
  268. * clntudp_bufcreate(raddr, program, version, wait, sockp, sendsz, recvsz)
  269. * struct sockaddr_in *raddr;
  270. * unsigned long program;
  271. * unsigned long version;
  272. * struct timeval wait_resend;
  273. * int *sockp;
  274. * unsigned int sendsz;
  275. * unsigned int recvsz;
  276. */
  277. extern CLIENT *clntudp_create (struct sockaddr_in *__raddr, unsigned long __program,
  278. unsigned long __version, struct timeval __wait_resend,
  279. int *__sockp);
  280. extern CLIENT *clntudp_bufcreate (struct sockaddr_in *__raddr,
  281. unsigned long __program, unsigned long __version,
  282. struct timeval __wait_resend, int *__sockp,
  283. unsigned int __sendsz, unsigned int __recvsz);
  284. extern int callrpc (const char *__host, const unsigned long __prognum,
  285. const unsigned long __versnum, const unsigned long __procnum,
  286. const xdrproc_t __inproc, const char *__in,
  287. const xdrproc_t __outproc, char *__out);
  288. #define UDPMSGSIZE 8800 /* rpc imposed limit on udp msg size */
  289. #define RPCSMALLMSGSIZE 400 /* a more reasonable packet size */
  290. void clnt_perror(CLIENT *rpch, const char *s);
  291. #endif /* rpc/clnt.h */