clnt.h 12 KB

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