clnt.h 10 KB

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