clnt.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  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. /* not sure whether non-const-ness is a part of the spec... if it is,
  126. * enclose "const" in #ifdef _LIBC / #endif
  127. * to make it effective only for libc compile */
  128. const
  129. struct clnt_ops {
  130. enum clnt_stat (*cl_call) (CLIENT *, u_long, xdrproc_t, caddr_t, xdrproc_t,
  131. caddr_t, struct timeval);
  132. /* call remote procedure */
  133. void (*cl_abort) (void); /* abort a call */
  134. void (*cl_geterr) (CLIENT *, struct rpc_err *);
  135. /* get specific error code */
  136. bool_t (*cl_freeres) (CLIENT *, xdrproc_t, caddr_t);
  137. /* frees results */
  138. void (*cl_destroy) (CLIENT *); /* destroy this structure */
  139. bool_t (*cl_control) (CLIENT *, int, char *);
  140. /* the ioctl() of rpc */
  141. } *cl_ops;
  142. caddr_t cl_private; /* private stuff */
  143. };
  144. /*
  145. * client side rpc interface ops
  146. *
  147. * Parameter types are:
  148. *
  149. */
  150. /*
  151. * enum clnt_stat
  152. * CLNT_CALL(rh, proc, xargs, argsp, xres, resp, timeout)
  153. * CLIENT *rh;
  154. * u_long proc;
  155. * xdrproc_t xargs;
  156. * caddr_t argsp;
  157. * xdrproc_t xres;
  158. * caddr_t resp;
  159. * struct timeval timeout;
  160. */
  161. #define CLNT_CALL(rh, proc, xargs, argsp, xres, resp, secs) \
  162. ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, argsp, xres, resp, secs))
  163. #define clnt_call(rh, proc, xargs, argsp, xres, resp, secs) \
  164. ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, argsp, xres, resp, secs))
  165. /*
  166. * void
  167. * CLNT_ABORT(rh);
  168. * CLIENT *rh;
  169. */
  170. #define CLNT_ABORT(rh) ((*(rh)->cl_ops->cl_abort)(rh))
  171. #define clnt_abort(rh) ((*(rh)->cl_ops->cl_abort)(rh))
  172. /*
  173. * struct rpc_err
  174. * CLNT_GETERR(rh);
  175. * CLIENT *rh;
  176. */
  177. #define CLNT_GETERR(rh,errp) ((*(rh)->cl_ops->cl_geterr)(rh, errp))
  178. #define clnt_geterr(rh,errp) ((*(rh)->cl_ops->cl_geterr)(rh, errp))
  179. /*
  180. * bool_t
  181. * CLNT_FREERES(rh, xres, resp);
  182. * CLIENT *rh;
  183. * xdrproc_t xres;
  184. * caddr_t resp;
  185. */
  186. #define CLNT_FREERES(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
  187. #define clnt_freeres(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
  188. /*
  189. * bool_t
  190. * CLNT_CONTROL(cl, request, info)
  191. * CLIENT *cl;
  192. * u_int request;
  193. * char *info;
  194. */
  195. #define CLNT_CONTROL(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
  196. #define clnt_control(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
  197. /*
  198. * control operations that apply to all transports
  199. *
  200. * Note: options marked XXX are no-ops in this implementation of RPC.
  201. * The are present in TI-RPC but can't be implemented here since they
  202. * depend on the presence of STREAMS/TLI, which we don't have.
  203. */
  204. #define CLSET_TIMEOUT 1 /* set timeout (timeval) */
  205. #define CLGET_TIMEOUT 2 /* get timeout (timeval) */
  206. #define CLGET_SERVER_ADDR 3 /* get server's address (sockaddr) */
  207. #define CLGET_FD 6 /* get connections file descriptor */
  208. #define CLGET_SVC_ADDR 7 /* get server's address (netbuf) XXX */
  209. #define CLSET_FD_CLOSE 8 /* close fd while clnt_destroy */
  210. #define CLSET_FD_NCLOSE 9 /* Do not close fd while clnt_destroy*/
  211. #define CLGET_XID 10 /* Get xid */
  212. #define CLSET_XID 11 /* Set xid */
  213. #define CLGET_VERS 12 /* Get version number */
  214. #define CLSET_VERS 13 /* Set version number */
  215. #define CLGET_PROG 14 /* Get program number */
  216. #define CLSET_PROG 15 /* Set program number */
  217. #define CLSET_SVC_ADDR 16 /* get server's address (netbuf) XXX */
  218. #define CLSET_PUSH_TIMOD 17 /* push timod if not already present XXX */
  219. #define CLSET_POP_TIMOD 18 /* pop timod XXX */
  220. /*
  221. * Connectionless only control operations
  222. */
  223. #define CLSET_RETRY_TIMEOUT 4 /* set retry timeout (timeval) */
  224. #define CLGET_RETRY_TIMEOUT 5 /* get retry timeout (timeval) */
  225. /*
  226. * void
  227. * CLNT_DESTROY(rh);
  228. * CLIENT *rh;
  229. */
  230. #define CLNT_DESTROY(rh) ((*(rh)->cl_ops->cl_destroy)(rh))
  231. #define clnt_destroy(rh) ((*(rh)->cl_ops->cl_destroy)(rh))
  232. /*
  233. * RPCTEST is a test program which is accessible on every rpc
  234. * transport/port. It is used for testing, performance evaluation,
  235. * and network administration.
  236. */
  237. #define RPCTEST_PROGRAM ((u_long)1)
  238. #define RPCTEST_VERSION ((u_long)1)
  239. #define RPCTEST_NULL_PROC ((u_long)2)
  240. #define RPCTEST_NULL_BATCH_PROC ((u_long)3)
  241. /*
  242. * By convention, procedure 0 takes null arguments and returns them
  243. */
  244. #define NULLPROC ((u_long)0)
  245. /*
  246. * Below are the client handle creation routines for the various
  247. * implementations of client side rpc. They can return NULL if a
  248. * creation failure occurs.
  249. */
  250. /*
  251. * Memory based rpc (for speed check and testing)
  252. * CLIENT *
  253. * clntraw_create(prog, vers)
  254. * u_long prog;
  255. * u_long vers;
  256. */
  257. extern CLIENT *clntraw_create (__const u_long __prog, __const u_long __vers)
  258. __THROW;
  259. /*
  260. * Generic client creation routine. Supported protocols are "udp", "tcp" and
  261. * "unix"
  262. * CLIENT *
  263. * clnt_create(host, prog, vers, prot)
  264. * char *host; -- hostname
  265. * u_long prog; -- program number
  266. * u_ong vers; -- version number
  267. * char *prot; -- protocol
  268. */
  269. extern CLIENT *clnt_create (__const char *__host, __const u_long __prog,
  270. __const u_long __vers, __const char *__prot)
  271. __THROW;
  272. /*
  273. * TCP based rpc
  274. * CLIENT *
  275. * clnttcp_create(raddr, prog, vers, sockp, sendsz, recvsz)
  276. * struct sockaddr_in *raddr;
  277. * u_long prog;
  278. * u_long version;
  279. * register int *sockp;
  280. * u_int sendsz;
  281. * u_int recvsz;
  282. */
  283. extern CLIENT *clnttcp_create (struct sockaddr_in *__raddr, u_long __prog,
  284. u_long __version, int *__sockp, u_int __sendsz,
  285. u_int __recvsz) __THROW;
  286. libc_hidden_proto(clnttcp_create)
  287. /*
  288. * UDP based rpc.
  289. * CLIENT *
  290. * clntudp_create(raddr, program, version, wait, sockp)
  291. * struct sockaddr_in *raddr;
  292. * u_long program;
  293. * u_long version;
  294. * struct timeval wait_resend;
  295. * int *sockp;
  296. *
  297. * Same as above, but you specify max packet sizes.
  298. * CLIENT *
  299. * clntudp_bufcreate(raddr, program, version, wait, sockp, sendsz, recvsz)
  300. * struct sockaddr_in *raddr;
  301. * u_long program;
  302. * u_long version;
  303. * struct timeval wait_resend;
  304. * int *sockp;
  305. * u_int sendsz;
  306. * u_int recvsz;
  307. */
  308. extern CLIENT *clntudp_create (struct sockaddr_in *__raddr, u_long __program,
  309. u_long __version, struct timeval __wait_resend,
  310. int *__sockp) __THROW;
  311. libc_hidden_proto(clntudp_create)
  312. extern CLIENT *clntudp_bufcreate (struct sockaddr_in *__raddr,
  313. u_long __program, u_long __version,
  314. struct timeval __wait_resend, int *__sockp,
  315. u_int __sendsz, u_int __recvsz) __THROW;
  316. libc_hidden_proto(clntudp_bufcreate)
  317. /*
  318. * AF_UNIX based rpc
  319. * CLIENT *
  320. * clntunix_create(raddr, prog, vers, sockp, sendsz, recvsz)
  321. * struct sockaddr_un *raddr;
  322. * u_long prog;
  323. * u_long version;
  324. * register int *sockp;
  325. * u_int sendsz;
  326. * u_int recvsz;
  327. */
  328. extern CLIENT *clntunix_create (struct sockaddr_un *__raddr, u_long __program,
  329. u_long __version, int *__sockp,
  330. u_int __sendsz, u_int __recvsz) __THROW;
  331. libc_hidden_proto(clntunix_create)
  332. extern int callrpc (__const char *__host, __const u_long __prognum,
  333. __const u_long __versnum, __const u_long __procnum,
  334. __const xdrproc_t __inproc, __const char *__in,
  335. __const xdrproc_t __outproc, char *__out) __THROW;
  336. extern int _rpc_dtablesize (void) __THROW;
  337. libc_hidden_proto(_rpc_dtablesize)
  338. /*
  339. * Print why creation failed
  340. */
  341. extern void clnt_pcreateerror (__const char *__msg); /* stderr */
  342. extern char *clnt_spcreateerror(__const char *__msg) __THROW; /* string */
  343. libc_hidden_proto(clnt_spcreateerror)
  344. /*
  345. * Like clnt_perror(), but is more verbose in its output
  346. */
  347. extern void clnt_perrno (enum clnt_stat __num); /* stderr */
  348. /*
  349. * Print an English error message, given the client error code
  350. */
  351. extern void clnt_perror (CLIENT *__clnt, __const char *__msg);
  352. /* stderr */
  353. libc_hidden_proto(clnt_perror)
  354. extern char *clnt_sperror (CLIENT *__clnt, __const char *__msg) __THROW;
  355. /* string */
  356. libc_hidden_proto(clnt_sperror)
  357. /*
  358. * If a creation fails, the following allows the user to figure out why.
  359. */
  360. struct rpc_createerr {
  361. enum clnt_stat cf_stat;
  362. struct rpc_err cf_error; /* useful when cf_stat == RPC_PMAPFAILURE */
  363. };
  364. extern struct rpc_createerr rpc_createerr;
  365. /*
  366. * Copy error message to buffer.
  367. */
  368. extern char *clnt_sperrno (enum clnt_stat __num) __THROW; /* string */
  369. libc_hidden_proto(clnt_sperrno)
  370. /*
  371. * get the port number on the host for the rpc program,version and proto
  372. */
  373. extern int getrpcport (__const char * __host, u_long __prognum,
  374. u_long __versnum, u_int proto) __THROW;
  375. /*
  376. * get the local host's IP address without consulting
  377. * name service library functions
  378. */
  379. extern void get_myaddress (struct sockaddr_in *) __THROW;
  380. #define UDPMSGSIZE 8800 /* rpc imposed limit on udp msg size */
  381. #define RPCSMALLMSGSIZE 400 /* a more reasonable packet size */
  382. __END_DECLS
  383. #endif /* rpc/clnt.h */