home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 4 / DATAFILE_PDCD4.iso / unix / armlinux / alpha / PARTITIONS / USR_GZ / usr / include / rpc / clnt.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-14  |  9.6 KB  |  356 lines

  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. /*
  32.  * clnt.h - Client side remote procedure call interface.
  33.  *
  34.  * Copyright (C) 1984, Sun Microsystems, Inc.
  35.  */
  36.  
  37. #ifndef _RPC_CLNT_H
  38. #define _RPC_CLNT_H
  39.  
  40. #include <features.h>
  41.  
  42. __BEGIN_DECLS
  43.  
  44. /*
  45.  * Rpc calls return an enum clnt_stat.  This should be looked at more,
  46.  * since each implementation is required to live with this (implementation
  47.  * independent) list of errors.
  48.  */
  49. enum clnt_stat {
  50.     RPC_SUCCESS=0,            /* call succeeded */
  51.     /*
  52.      * local errors
  53.      */
  54.     RPC_CANTENCODEARGS=1,        /* can't encode arguments */
  55.     RPC_CANTDECODERES=2,        /* can't decode results */
  56.     RPC_CANTSEND=3,            /* failure in sending call */
  57.     RPC_CANTRECV=4,            /* failure in receiving result */
  58.     RPC_TIMEDOUT=5,            /* call timed out */
  59.     /*
  60.      * remote errors
  61.      */
  62.     RPC_VERSMISMATCH=6,        /* rpc versions not compatible */
  63.     RPC_AUTHERROR=7,        /* authentication error */
  64.     RPC_PROGUNAVAIL=8,        /* program not available */
  65.     RPC_PROGVERSMISMATCH=9,        /* program version mismatched */
  66.     RPC_PROCUNAVAIL=10,        /* procedure unavailable */
  67.     RPC_CANTDECODEARGS=11,        /* decode arguments error */
  68.     RPC_SYSTEMERROR=12,        /* generic "other problem" */
  69.  
  70.     /*
  71.      * callrpc & clnt_create errors
  72.      */
  73.     RPC_UNKNOWNHOST=13,        /* unknown host name */
  74.     RPC_UNKNOWNPROTO=17,        /* unkown protocol */
  75.  
  76.     /*
  77.      * _ create errors
  78.      */
  79.     RPC_PMAPFAILURE=14,        /* the pmapper failed in its call */
  80.     RPC_PROGNOTREGISTERED=15,    /* remote program is not registered */
  81.     /*
  82.      * unspecified error
  83.      */
  84.     RPC_FAILED=16
  85. };
  86.  
  87.  
  88. /*
  89.  * Error info.
  90.  */
  91. struct rpc_err {
  92.     enum clnt_stat re_status;
  93.     union {
  94.         int RE_errno;        /* realated system error */
  95.         enum auth_stat RE_why;    /* why the auth error occurred */
  96.         struct {
  97.             u_long low;    /* lowest verion supported */
  98.             u_long high;    /* highest verion supported */
  99.         } RE_vers;
  100.         struct {        /* maybe meaningful if RPC_FAILED */
  101.             long s1;
  102.             long s2;
  103.         } RE_lb;        /* life boot & debugging only */
  104.     } ru;
  105. #define    re_errno    ru.RE_errno
  106. #define    re_why        ru.RE_why
  107. #define    re_vers        ru.RE_vers
  108. #define    re_lb        ru.RE_lb
  109. };
  110.  
  111.  
  112. /*
  113.  * Client rpc handle.
  114.  * Created by individual implementations, see e.g. rpc_udp.c.
  115.  * Client is responsible for initializing auth, see e.g. auth_none.c.
  116.  */
  117. typedef struct __client {
  118.     AUTH    *cl_auth;            /* authenticator */
  119.     struct clnt_ops {
  120.         /* call remote procedure */
  121.         enum clnt_stat (*cl_call) __P ((struct __client *,
  122.             u_long, xdrproc_t, __ptr_t, xdrproc_t,
  123.             __ptr_t, struct timeval));
  124.         /* abort a call */
  125.         void        (*cl_abort) __P ((void));
  126.         /* get specific error code */
  127.         void        (*cl_geterr) __P ((struct __client *,
  128.             struct rpc_err *));
  129.         /* frees results */
  130.         bool_t        (*cl_freeres) __P ((struct __client *,
  131.             xdrproc_t, __ptr_t));
  132.         /* destroy this structure */
  133.         void        (*cl_destroy) __P((struct __client *));
  134.         /* the ioctl() of rpc */
  135.         bool_t          (*cl_control) __P((struct __client *,
  136.             int, __ptr_t));
  137.     } *cl_ops;
  138.     caddr_t            cl_private;    /* private stuff */
  139. } CLIENT;
  140.  
  141.  
  142. /*
  143.  * client side rpc interface ops
  144.  *
  145.  * Parameter types are:
  146.  *
  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. /*
  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. /*
  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.  
  182. /*
  183.  * bool_t
  184.  * CLNT_FREERES(rh, xres, resp);
  185.  *     CLIENT *rh;
  186.  *    xdrproc_t xres;
  187.  *    caddr_t resp;
  188.  */
  189. #define    CLNT_FREERES(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
  190. #define    clnt_freeres(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
  191.  
  192. /*
  193.  * bool_t
  194.  * CLNT_CONTROL(cl, request, info)
  195.  *      CLIENT *cl;
  196.  *      u_int request;
  197.  *      char *info;
  198.  */
  199. #define    CLNT_CONTROL(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
  200. #define    clnt_control(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
  201.  
  202. /*
  203.  * control operations that apply to both udp and tcp transports
  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. /*
  209.  * udp only control operations
  210.  */
  211. #define CLSET_RETRY_TIMEOUT 4   /* set retry timeout (timeval) */
  212. #define CLGET_RETRY_TIMEOUT 5   /* get retry timeout (timeval) */
  213.  
  214. /*
  215.  * void
  216.  * CLNT_DESTROY(rh);
  217.  *     CLIENT *rh;
  218.  */
  219. #define    CLNT_DESTROY(rh)    ((*(rh)->cl_ops->cl_destroy)(rh))
  220. #define    clnt_destroy(rh)    ((*(rh)->cl_ops->cl_destroy)(rh))
  221.  
  222.  
  223. /*
  224.  * RPCTEST is a test program which is accessable on every rpc
  225.  * transport/port.  It is used for testing, performance evaluation,
  226.  * and network administration.
  227.  */
  228.  
  229. #define RPCTEST_PROGRAM        ((u_long)1)
  230. #define RPCTEST_VERSION        ((u_long)1)
  231. #define RPCTEST_NULL_PROC    ((u_long)2)
  232. #define RPCTEST_NULL_BATCH_PROC    ((u_long)3)
  233.  
  234. /*
  235.  * By convention, procedure 0 takes null arguments and returns them
  236.  */
  237.  
  238. #define NULLPROC ((u_long)0)
  239.  
  240. /*
  241.  * Below are the client handle creation routines for the various
  242.  * implementations of client side rpc.  They can return NULL if a 
  243.  * creation failure occurs.
  244.  */
  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 __P ((u_long __prog, u_long __vers));
  254.  
  255.  
  256. /*
  257.  * Generic client creation routine. Supported protocols are "udp" and "tcp"
  258.  */
  259. extern CLIENT * clnt_create __P ((__const char *__host, u_long __prog,
  260.         u_long __vers, __const char *__prot));
  261.  
  262. /*
  263.  * TCP based rpc
  264.  * CLIENT *
  265.  * clnttcp_create(raddr, prog, vers, sockp, sendsz, recvsz)
  266.  *    struct sockaddr_in *raddr;
  267.  *    u_long prog;
  268.  *    u_long version;
  269.  *    register int *sockp;
  270.  *    u_int sendsz;
  271.  *    u_int recvsz;
  272.  */
  273.  
  274. struct sockaddr_in;
  275.  
  276. extern CLIENT *clnttcp_create __P ((struct sockaddr_in *__raddr, u_long __prog,
  277.     u_long __version, int *__sockp, u_int __sendsz, u_int __recvsz));
  278.  
  279. /*
  280.  * UDP based rpc.
  281.  * CLIENT *
  282.  * clntudp_create(raddr, program, version, wait, sockp)
  283.  *    struct sockaddr_in *raddr;
  284.  *    u_long program;
  285.  *    u_long version;
  286.  *    struct timeval wait;
  287.  *    int *sockp;
  288.  *
  289.  * Same as above, but you specify max packet sizes.
  290.  * CLIENT *
  291.  * clntudp_bufcreate(raddr, program, version, wait, sockp, sendsz, recvsz)
  292.  *    struct sockaddr_in *raddr;
  293.  *    u_long program;
  294.  *    u_long version;
  295.  *    struct timeval wait;
  296.  *    int *sockp;
  297.  *    u_int sendsz;
  298.  *    u_int recvsz;
  299.  */
  300. extern CLIENT *clntudp_create __P ((struct sockaddr_in *__raddr,
  301.         u_long __prog, u_long __version, struct timeval __wait,
  302.         int *__sockp));
  303. extern CLIENT *clntudp_bufcreate __P ((struct sockaddr_in *__raddr,
  304.         u_long __prog, u_long __version, struct timeval __wait,
  305.         int *__sockp, u_int __sendsz, u_int __recvsz));
  306.  
  307. extern int callrpc __P ((__const char *__host,
  308.         u_long __prognum, u_long __versnum, u_long __procnum,
  309.         xdrproc_t __inproc, __const char *__in,
  310.         xdrproc_t __outproc, char *__out));
  311. extern int _rpc_dtablesize __P ((void));
  312.  
  313. /*
  314.  * Print why creation failed
  315.  */
  316. extern void clnt_pcreateerror __P ((__const char *__msg));    /* stderr */
  317. extern char *clnt_spcreateerror __P ((__const char *__msg));    /* string */
  318.  
  319. /*
  320.  * Like clnt_perror(), but is more verbose in its output
  321.  */ 
  322. extern void clnt_perrno __P ((enum clnt_stat __num));    /* stderr */
  323.  
  324. /*
  325.  * Print an English error message, given the client error code
  326.  */
  327. extern void clnt_perror __P ((CLIENT *__clnt, __const char *__msg));     /* stderr */
  328. extern char *clnt_sperror __P ((CLIENT *__clnt, __const char *__msg));    /* string */
  329.  
  330. /* 
  331.  * If a creation fails, the following allows the user to figure out why.
  332.  */
  333. struct rpc_createerr {
  334.     enum clnt_stat cf_stat;
  335.     struct rpc_err cf_error; /* useful when cf_stat == RPC_PMAPFAILURE */
  336. };
  337.  
  338. extern struct rpc_createerr rpc_createerr;
  339.  
  340.  
  341.  
  342. /*
  343.  * Copy error message to buffer.
  344.  */
  345. extern char *clnt_sperrno __P ((enum clnt_stat __num));    /* string */
  346.  
  347. extern int getrpcport __P ((__const char * __host, u_long __prognum,
  348.                  u_long __versnum, u_int proto));
  349.  
  350. __END_DECLS
  351.  
  352. #define UDPMSGSIZE    8800    /* rpc imposed limit on udp msg size */
  353. #define RPCSMALLMSGSIZE    400    /* a more reasonable packet size */
  354.  
  355. #endif /* _RPC_CLNT_H */
  356.