clnt.h
上传用户:luoyougen
上传日期:2008-05-12
资源大小:23136k
文件大小:11k
源码类别:

VxWorks

开发平台:

C/C++

  1. /* clnt.h - Client side remote procedure call interface. */
  2. /* Copyright 1984-1992 Wind River Systems, Inc. */
  3. /*
  4.  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  5.  * unrestricted use provided that this legend is included on all tape
  6.  * media and as a part of the software program in whole or part.  Users
  7.  * may copy or modify Sun RPC without charge, but are not authorized
  8.  * to license or distribute it to anyone else except as part of a product or
  9.  * program developed by the user.
  10.  *
  11.  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  12.  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  13.  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  14.  *
  15.  * Sun RPC is provided with no support and without any obligation on the
  16.  * part of Sun Microsystems, Inc. to assist in its use, correction,
  17.  * modification or enhancement.
  18.  *
  19.  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  20.  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  21.  * OR ANY PART THEREOF.
  22.  *
  23.  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  24.  * or profits or other special, indirect and consequential damages, even if
  25.  * Sun has been advised of the possibility of such damages.
  26.  *
  27.  * Sun Microsystems, Inc.
  28.  * 2550 Garcia Avenue
  29.  * Mountain View, California  94043
  30.  */
  31. /* @(#)clnt.h 1.1 86/02/03 SMI      */
  32. /*
  33.  * clnt.h - Client side remote procedure call interface.
  34.  *
  35.  * Copyright (C) 1984, Sun Microsystems, Inc.
  36.  */
  37. /*
  38. modification history
  39. --------------------
  40. 01k,22sep92,rrr  added support for c++
  41. 01j,07sep92,smb  added includes of sys/times.h, rpc/xdr.h, rpc/auth.h
  42. 01i,26may92,rrr  the tree shuffle
  43.   -changed includes to have absolute path from h/
  44. 01h,04oct91,rrr  passed through the ansification filter
  45.   -fixed #else and #endif
  46.   -changed copyright notice
  47. 01g,01may01,elh  removed clnt_tcpInit.
  48. 01f,10jan91,shl  fixed prototype of callrpc(), included in.h.
  49. 01e,25oct90,dnw  changed clnt_tcpInit from int to void.
  50. 01d,24oct90,shl  commented out redundant function declarations.
  51. 01c,05oct90,shl  added ANSI function prototypes.
  52.                  added copyright notice.
  53. 01b,26oct89,hjb  upgraded to release 4.0
  54. */
  55. #ifndef __INCclnth
  56. #define __INCclnth
  57. #ifdef __cplusplus
  58. extern "C" {
  59. #endif
  60. #include "netinet/in.h"
  61. #include "sys/times.h"
  62. #include "rpc/xdr.h"
  63. #include "rpc/auth.h"
  64. /*
  65.  * Rpc calls return an enum clnt_stat.  This should be looked at more,
  66.  * since each implementation is required to live with this (implementation
  67.  * independent) list of errors.
  68.  */
  69. enum clnt_stat {
  70. RPC_SUCCESS=0, /* call succeeded */
  71. /*
  72.  * local errors
  73.  */
  74. RPC_CANTENCODEARGS=1, /* can't encode arguments */
  75. RPC_CANTDECODERES=2, /* can't decode results */
  76. RPC_CANTSEND=3, /* failure in sending call */
  77. RPC_CANTRECV=4, /* failure in receiving result */
  78. RPC_TIMEDOUT=5, /* call timed out */
  79. /*
  80.  * remote errors
  81.  */
  82. RPC_VERSMISMATCH=6, /* rpc versions not compatible */
  83. RPC_AUTHERROR=7, /* authentication error */
  84. RPC_PROGUNAVAIL=8, /* program not available */
  85. RPC_PROGVERSMISMATCH=9, /* program version mismatched */
  86. RPC_PROCUNAVAIL=10, /* procedure unavailable */
  87. RPC_CANTDECODEARGS=11, /* decode arguments error */
  88. RPC_SYSTEMERROR=12, /* generic "other problem" */
  89. /*
  90.  * callrpc errors
  91.  */
  92. RPC_UNKNOWNHOST=13, /* unknown host name */
  93. RPC_UNKNOWNPROTO=17, /* unknown protocol -- 4.0 */
  94. /*
  95.  * _ create errors
  96.  */
  97. RPC_PMAPFAILURE=14, /* the pmapper failed in its call */
  98. RPC_PROGNOTREGISTERED=15, /* remote program is not registered */
  99. /*
  100.  * unspecified error
  101.  */
  102. RPC_FAILED=16
  103. };
  104. /*
  105.  * Error info.
  106.  */
  107. struct rpc_err {
  108. enum clnt_stat re_status;
  109. union {
  110. int RE_errno; /* realated system error */
  111. enum auth_stat RE_why; /* why the auth error occurred */
  112. struct {
  113. u_long low; /* lowest verion supported */
  114. u_long high; /* highest verion supported */
  115. } RE_vers;
  116. struct { /* maybe meaningful if RPC_FAILED */
  117. long s1;
  118. long s2;
  119. } RE_lb; /* life boot & debugging only */
  120. } ru;
  121. #define re_errno ru.RE_errno
  122. #define re_why ru.RE_why
  123. #define re_vers ru.RE_vers
  124. #define re_lb ru.RE_lb
  125. };
  126. /*
  127.  * Client rpc handle.
  128.  * Created by individual implementations, see e.g. rpc_udp.c.
  129.  * Client is responsible for initializing auth, see e.g. auth_none.c.
  130.  */
  131. typedef struct {
  132. AUTH *cl_auth; /* authenticator */
  133. struct clnt_ops {
  134. enum clnt_stat (*cl_call)(); /* call remote procedure */
  135. void (*cl_abort)(); /* abort a call */
  136. void (*cl_geterr)(); /* get specific error code */
  137. bool_t (*cl_freeres)(); /* frees results */
  138. void (*cl_destroy)();/* destroy this structure */
  139. bool_t (*cl_control)(); /*the ioctl() of rpc -- 4.0 */
  140. } *cl_ops;
  141. caddr_t cl_private; /* private stuff */
  142. } CLIENT;
  143. /*
  144.  * client side rpc interface ops
  145.  *
  146.  * Parameter types are:
  147.  *
  148.  */
  149. /*
  150.  * enum clnt_stat
  151.  * CLNT_CALL(rh, proc, xargs, argsp, xres, resp, timeout)
  152.  *  CLIENT *rh;
  153.  * u_long proc;
  154.  * xdrproc_t xargs;
  155.  * caddr_t argsp;
  156.  * xdrproc_t xres;
  157.  * caddr_t resp;
  158.  * struct timeval timeout;
  159.  */
  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. #define clnt_call(rh, proc, xargs, argsp, xres, resp, secs)
  163. ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, argsp, xres, resp, secs))
  164. /*
  165.  * void
  166.  * CLNT_ABORT(rh);
  167.  *  CLIENT *rh;
  168.  */
  169. #define CLNT_ABORT(rh) ((*(rh)->cl_ops->cl_abort)(rh))
  170. #define clnt_abort(rh) ((*(rh)->cl_ops->cl_abort)(rh))
  171. /*
  172.  * struct rpc_err
  173.  * CLNT_GETERR(rh);
  174.  *  CLIENT *rh;
  175.  */
  176. #define CLNT_GETERR(rh,errp) ((*(rh)->cl_ops->cl_geterr)(rh, errp))
  177. #define clnt_geterr(rh,errp) ((*(rh)->cl_ops->cl_geterr)(rh, errp))
  178. /*
  179.  * bool_t
  180.  * CLNT_FREERES(rh, xres, resp);
  181.  *  CLIENT *rh;
  182.  * xdrproc_t xres;
  183.  * caddr_t resp;
  184.  */
  185. #define CLNT_FREERES(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
  186. #define clnt_freeres(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
  187. /*
  188.  * bool_t
  189.  * CLNT_CONTROL(cl, request, info)
  190.  *      CLIENT *cl;
  191.  *      u_int request;
  192.  *      char *info;
  193.  */
  194. #define CLNT_CONTROL(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in)) /* 4.0 */
  195. #define clnt_control(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in)) /* 4.0 */
  196. /*
  197.  * control operations that apply to both udp and tcp transports
  198.  */
  199. #define CLSET_TIMEOUT       1   /* set timeout (timeval) */
  200. #define CLGET_TIMEOUT       2   /* get timeout (timeval) */
  201. #define CLGET_SERVER_ADDR   3   /* get server's address (sockaddr) */
  202. /*
  203.  * udp only control operations
  204.  */
  205. #define CLSET_RETRY_TIMEOUT 4   /* set retry timeout (timeval) */
  206. #define CLGET_RETRY_TIMEOUT 5   /* get retry timeout (timeval) */
  207. /*
  208.  * void
  209.  * CLNT_DESTROY(rh);
  210.  *  CLIENT *rh;
  211.  */
  212. #define CLNT_DESTROY(rh) ((*(rh)->cl_ops->cl_destroy)(rh))
  213. #define clnt_destroy(rh) ((*(rh)->cl_ops->cl_destroy)(rh))
  214. /*
  215.  * RPCTEST is a test program which is accessable on every rpc
  216.  * transport/port.  It is used for testing, performance evaluation,
  217.  * and network administration.
  218.  */
  219. #define RPCTEST_PROGRAM ((u_long)1)
  220. #define RPCTEST_VERSION ((u_long)1)
  221. #define RPCTEST_NULL_PROC ((u_long)2)
  222. #define RPCTEST_NULL_BATCH_PROC ((u_long)3)
  223. /*
  224.  * By convention, procedure 0 takes null arguments and returns them
  225.  */
  226. #define NULLPROC ((u_long)0)
  227. /*
  228.  * Below are the client handle creation routines for the various
  229.  * implementations of client side rpc.  They can return NULL if a
  230.  * creation failure occurs.
  231.  */
  232. /*
  233.  * Memory based rpc (for speed check and testing)
  234.  * CLIENT *
  235.  * clntraw_create(prog, vers)
  236.  * u_long prog;
  237.  * u_long vers;
  238.  */
  239. /* extern CLIENT *clntraw_create(); */
  240. /*
  241.  * Generic client creation routine. Supported protocols are "udp" and "tcp"
  242.  */
  243. /* extern CLIENT * clnt_create(host, prog, vers, prot); */ /* 4.0 */
  244. /*
  245. char *host; -- hostname
  246. u_long prog; -- program number
  247. u_long vers; -- version number
  248. char *prot; -- protocol
  249. */
  250. /*
  251.  * TCP based rpc
  252.  * CLIENT *
  253.  * clnttcp_create(raddr, prog, vers, sockp, sendsz, recvsz)
  254.  * struct sockaddr_in *raddr;
  255.  * u_long prog;
  256.  * u_long version;
  257.  * register int *sockp;
  258.  * u_int sendsz;
  259.  * u_int recvsz;
  260.  */
  261. /* extern CLIENT *clnttcp_create(); */
  262. /*
  263.  * UDP based rpc.
  264.  * CLIENT *
  265.  * clntudp_create(raddr, program, version, wait, sockp)
  266.  * struct sockaddr_in *raddr;
  267.  * u_long program;
  268.  * u_long version;
  269.  * struct timeval wait;
  270.  * int *sockp;
  271.  *
  272.  * Same as above, but you specify max packet sizes.
  273.  * CLIENT *
  274.  * clntudp_bufcreate(raddr, program, version, wait, sockp, sendsz, recvsz)
  275.  * struct sockaddr_in *raddr;
  276.  * u_long program;
  277.  * u_long version;
  278.  * struct timeval wait;
  279.  * int *sockp;
  280.  * u_int sendsz;
  281.  * u_int recvsz;
  282.  */
  283. /* extern CLIENT *clntudp_create(); */
  284. /* extern CLIENT *clntudp_bufcreate(); */
  285. /*
  286.  * Print why creation failed
  287.  */
  288. /* void clnt_pcreateerror(char *msg); */ /* stderr -- 4.0 */
  289. /* char *clnt_spcreateerror(char *msg); */ /* string -- 4.0 */
  290. /*
  291.  * Like clnt_perror () but is more verbose in its output
  292.  */
  293. /* void clnt_perrno(enum clnt_stat num); */ /* stderr -- 4.0 */
  294. /*
  295.  * Print an english error message, given the client error code
  296.  */
  297. /* void clnt_perror(CLIENT *clnt, char *msg); */ /* stderr -- 4.0 */
  298. /* char *clnt_sperror(CLIENT *clnt, char *msg);*/ /* string -- 4.0 */
  299. /*
  300.  * If a creation fails, the following allows the user to figure out why.
  301.  */
  302. struct rpc_createerr {
  303.   enum clnt_stat cf_stat;
  304.   struct rpc_err cf_error; /* useful when cf_stat == RPC_PMAPFAILURE */
  305. };
  306. /* XXX this is now in the taskModuleList */
  307. /* XXX extern struct rpc_createerr rpc_createerr; */
  308. /*
  309.  * copy error message to buffer.
  310.  */
  311. /* char *clnt_sperrno(enum clnt_stat num); */ /* string -- 4.0 */
  312. #define UDPMSGSIZE 8800 /* rpc imposed limit on udp msg size */
  313. #define RPCSMALLMSGSIZE 400 /* a more reasonable packet size */
  314. /* function declarations */
  315. #if defined(__STDC__) || defined(__cplusplus)
  316. extern   CLIENT *    clnt_create (char *hostname, unsigned prog,
  317.    unsigned vers, char *proto);
  318. extern   char *      clnt_sperror (CLIENT *rpch, char *s);
  319. extern   void       clnt_perror (CLIENT *rpch, char *s);
  320. extern   char *      clnt_sperrno (enum clnt_stat stat);
  321. extern   void       clnt_perrno (enum clnt_stat num);
  322. extern   char *      clnt_spcreateerror (char *s);
  323. extern   void       clnt_pcreateerror (char *s);
  324. extern   CLIENT *    clntraw_create (u_long prog, u_long vers);
  325. extern   int       callrpc (char *host, int prognum, int versnum,
  326.        int procnum, xdrproc_t inproc, char* in,
  327.        xdrproc_t outproc, char *out);
  328. extern   CLIENT *    clnttcp_create (struct sockaddr_in *raddr, u_long prog,
  329.       u_long vers, int *sockp, u_int sendsz,
  330.       u_int recvsz);
  331. extern   CLIENT *    clntudp_bufcreate (struct sockaddr_in *raddr,
  332.  u_long program, u_long version,
  333.  struct timeval wait, int *sockp,
  334.  u_int sendsz, u_int recvsz);
  335. extern   CLIENT *    clntudp_create (struct sockaddr_in *raddr, u_long program,
  336.       u_long version, struct timeval wait,
  337.       int *sockp);
  338. extern   bool_t      clntudp_freeres (CLIENT *cl, xdrproc_t xdr_res,
  339.        caddr_t res_ptr);
  340. #else
  341. extern   CLIENT *    clnt_create ();
  342. extern   char *      clnt_sperror ();
  343. extern   void       clnt_perror ();
  344. extern   char *      clnt_sperrno ();
  345. extern   void       clnt_perrno ();
  346. extern   char *      clnt_spcreateerror ();
  347. extern   void       clnt_pcreateerror ();
  348. extern   CLIENT *    clntraw_create ();
  349. extern   int       callrpc ();
  350. extern   CLIENT *    clnttcp_create ();
  351. extern   CLIENT *    clntudp_bufcreate ();
  352. extern   CLIENT *    clntudp_create ();
  353. extern   bool_t      clntudp_freeres ();
  354. #endif /* __STDC__ */
  355. #ifdef __cplusplus
  356. }
  357. #endif
  358. #endif /* __INCclnth */