clnt.h 12 KB

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