clnt.h revision 8858
11839Swollman/*
21839Swollman * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
31839Swollman * unrestricted use provided that this legend is included on all tape
41839Swollman * media and as a part of the software program in whole or part.  Users
51839Swollman * may copy or modify Sun RPC without charge, but are not authorized
61839Swollman * to license or distribute it to anyone else except as part of a product or
71839Swollman * program developed by the user.
88858Srgrimes *
91839Swollman * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
101839Swollman * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
111839Swollman * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
128858Srgrimes *
131839Swollman * Sun RPC is provided with no support and without any obligation on the
141839Swollman * part of Sun Microsystems, Inc. to assist in its use, correction,
151839Swollman * modification or enhancement.
168858Srgrimes *
171839Swollman * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
181839Swollman * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
191839Swollman * OR ANY PART THEREOF.
208858Srgrimes *
211839Swollman * In no event will Sun Microsystems, Inc. be liable for any lost revenue
221839Swollman * or profits or other special, indirect and consequential damages, even if
231839Swollman * Sun has been advised of the possibility of such damages.
248858Srgrimes *
251839Swollman * Sun Microsystems, Inc.
261839Swollman * 2550 Garcia Avenue
271839Swollman * Mountain View, California  94043
281903Swollman *
291903Swollman *	from: @(#)clnt.h 1.31 88/02/08 SMI
301903Swollman *	from: @(#)clnt.h	2.1 88/07/29 4.0 RPCSRC
318858Srgrimes *	$Id: clnt.h,v 1.2 1994/08/07 18:40:55 wollman Exp $
321839Swollman */
331839Swollman
341839Swollman/*
351839Swollman * clnt.h - Client side remote procedure call interface.
361839Swollman *
371839Swollman * Copyright (C) 1984, Sun Microsystems, Inc.
381839Swollman */
391839Swollman
401903Swollman#ifndef _RPC_CLNT_H_
411903Swollman#define _RPC_CLNT_H_
421903Swollman#include <sys/cdefs.h>
431839Swollman
441839Swollman/*
451839Swollman * Rpc calls return an enum clnt_stat.  This should be looked at more,
461839Swollman * since each implementation is required to live with this (implementation
471839Swollman * independent) list of errors.
481839Swollman */
491839Swollmanenum clnt_stat {
501839Swollman	RPC_SUCCESS=0,			/* call succeeded */
511839Swollman	/*
521839Swollman	 * local errors
531839Swollman	 */
541839Swollman	RPC_CANTENCODEARGS=1,		/* can't encode arguments */
551839Swollman	RPC_CANTDECODERES=2,		/* can't decode results */
561839Swollman	RPC_CANTSEND=3,			/* failure in sending call */
571839Swollman	RPC_CANTRECV=4,			/* failure in receiving result */
581839Swollman	RPC_TIMEDOUT=5,			/* call timed out */
591839Swollman	/*
601839Swollman	 * remote errors
611839Swollman	 */
621839Swollman	RPC_VERSMISMATCH=6,		/* rpc versions not compatible */
631839Swollman	RPC_AUTHERROR=7,		/* authentication error */
641839Swollman	RPC_PROGUNAVAIL=8,		/* program not available */
651839Swollman	RPC_PROGVERSMISMATCH=9,		/* program version mismatched */
661839Swollman	RPC_PROCUNAVAIL=10,		/* procedure unavailable */
671839Swollman	RPC_CANTDECODEARGS=11,		/* decode arguments error */
681839Swollman	RPC_SYSTEMERROR=12,		/* generic "other problem" */
691839Swollman
701839Swollman	/*
711839Swollman	 * callrpc & clnt_create errors
721839Swollman	 */
731839Swollman	RPC_UNKNOWNHOST=13,		/* unknown host name */
741839Swollman	RPC_UNKNOWNPROTO=17,		/* unkown protocol */
751839Swollman
761839Swollman	/*
771839Swollman	 * _ create errors
781839Swollman	 */
791839Swollman	RPC_PMAPFAILURE=14,		/* the pmapper failed in its call */
801839Swollman	RPC_PROGNOTREGISTERED=15,	/* remote program is not registered */
811839Swollman	/*
821839Swollman	 * unspecified error
831839Swollman	 */
841839Swollman	RPC_FAILED=16
851839Swollman};
861839Swollman
871839Swollman
881839Swollman/*
891839Swollman * Error info.
901839Swollman */
911839Swollmanstruct rpc_err {
921839Swollman	enum clnt_stat re_status;
931839Swollman	union {
941839Swollman		int RE_errno;		/* realated system error */
951839Swollman		enum auth_stat RE_why;	/* why the auth error occurred */
961839Swollman		struct {
971839Swollman			u_long low;	/* lowest verion supported */
981839Swollman			u_long high;	/* highest verion supported */
991839Swollman		} RE_vers;
1001839Swollman		struct {		/* maybe meaningful if RPC_FAILED */
1011839Swollman			long s1;
1021839Swollman			long s2;
1031839Swollman		} RE_lb;		/* life boot & debugging only */
1041839Swollman	} ru;
1051839Swollman#define	re_errno	ru.RE_errno
1061839Swollman#define	re_why		ru.RE_why
1071839Swollman#define	re_vers		ru.RE_vers
1081839Swollman#define	re_lb		ru.RE_lb
1091839Swollman};
1101839Swollman
1111839Swollman
1121839Swollman/*
1131839Swollman * Client rpc handle.
1141839Swollman * Created by individual implementations, see e.g. rpc_udp.c.
1151839Swollman * Client is responsible for initializing auth, see e.g. auth_none.c.
1161839Swollman */
1171839Swollmantypedef struct {
1181839Swollman	AUTH	*cl_auth;			/* authenticator */
1191839Swollman	struct clnt_ops {
1201839Swollman		enum clnt_stat	(*cl_call)();	/* call remote procedure */
1211839Swollman		void		(*cl_abort)();	/* abort a call */
1221839Swollman		void		(*cl_geterr)();	/* get specific error code */
1231839Swollman		bool_t		(*cl_freeres)(); /* frees results */
1241839Swollman		void		(*cl_destroy)();/* destroy this structure */
1251839Swollman		bool_t          (*cl_control)();/* the ioctl() of rpc */
1261839Swollman	} *cl_ops;
1271839Swollman	caddr_t			cl_private;	/* private stuff */
1281839Swollman} CLIENT;
1291839Swollman
1301839Swollman
1311839Swollman/*
1321839Swollman * client side rpc interface ops
1331839Swollman *
1341839Swollman * Parameter types are:
1351839Swollman *
1361839Swollman */
1371839Swollman
1381839Swollman/*
1391839Swollman * enum clnt_stat
1401839Swollman * CLNT_CALL(rh, proc, xargs, argsp, xres, resp, timeout)
1411839Swollman * 	CLIENT *rh;
1421839Swollman *	u_long proc;
1431839Swollman *	xdrproc_t xargs;
1441839Swollman *	caddr_t argsp;
1451839Swollman *	xdrproc_t xres;
1461839Swollman *	caddr_t resp;
1471839Swollman *	struct timeval timeout;
1481839Swollman */
1491839Swollman#define	CLNT_CALL(rh, proc, xargs, argsp, xres, resp, secs)	\
1501839Swollman	((*(rh)->cl_ops->cl_call)(rh, proc, xargs, argsp, xres, resp, secs))
1511839Swollman#define	clnt_call(rh, proc, xargs, argsp, xres, resp, secs)	\
1521839Swollman	((*(rh)->cl_ops->cl_call)(rh, proc, xargs, argsp, xres, resp, secs))
1531839Swollman
1541839Swollman/*
1551839Swollman * void
1561839Swollman * CLNT_ABORT(rh);
1571839Swollman * 	CLIENT *rh;
1581839Swollman */
1591839Swollman#define	CLNT_ABORT(rh)	((*(rh)->cl_ops->cl_abort)(rh))
1601839Swollman#define	clnt_abort(rh)	((*(rh)->cl_ops->cl_abort)(rh))
1611839Swollman
1621839Swollman/*
1631839Swollman * struct rpc_err
1641839Swollman * CLNT_GETERR(rh);
1651839Swollman * 	CLIENT *rh;
1661839Swollman */
1671839Swollman#define	CLNT_GETERR(rh,errp)	((*(rh)->cl_ops->cl_geterr)(rh, errp))
1681839Swollman#define	clnt_geterr(rh,errp)	((*(rh)->cl_ops->cl_geterr)(rh, errp))
1691839Swollman
1701839Swollman
1711839Swollman/*
1721839Swollman * bool_t
1731839Swollman * CLNT_FREERES(rh, xres, resp);
1741839Swollman * 	CLIENT *rh;
1751839Swollman *	xdrproc_t xres;
1761839Swollman *	caddr_t resp;
1771839Swollman */
1781839Swollman#define	CLNT_FREERES(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
1791839Swollman#define	clnt_freeres(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
1801839Swollman
1811839Swollman/*
1821839Swollman * bool_t
1831839Swollman * CLNT_CONTROL(cl, request, info)
1841839Swollman *      CLIENT *cl;
1851839Swollman *      u_int request;
1861839Swollman *      char *info;
1871839Swollman */
1881839Swollman#define	CLNT_CONTROL(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
1891839Swollman#define	clnt_control(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
1901839Swollman
1911839Swollman/*
1921839Swollman * control operations that apply to both udp and tcp transports
1931839Swollman */
1941839Swollman#define CLSET_TIMEOUT       1   /* set timeout (timeval) */
1951839Swollman#define CLGET_TIMEOUT       2   /* get timeout (timeval) */
1961839Swollman#define CLGET_SERVER_ADDR   3   /* get server's address (sockaddr) */
1971839Swollman/*
1981839Swollman * udp only control operations
1991839Swollman */
2001839Swollman#define CLSET_RETRY_TIMEOUT 4   /* set retry timeout (timeval) */
2011839Swollman#define CLGET_RETRY_TIMEOUT 5   /* get retry timeout (timeval) */
2021839Swollman
2031839Swollman/*
2041839Swollman * void
2051839Swollman * CLNT_DESTROY(rh);
2061839Swollman * 	CLIENT *rh;
2071839Swollman */
2081839Swollman#define	CLNT_DESTROY(rh)	((*(rh)->cl_ops->cl_destroy)(rh))
2091839Swollman#define	clnt_destroy(rh)	((*(rh)->cl_ops->cl_destroy)(rh))
2101839Swollman
2111839Swollman
2121839Swollman/*
2131839Swollman * RPCTEST is a test program which is accessable on every rpc
2141839Swollman * transport/port.  It is used for testing, performance evaluation,
2151839Swollman * and network administration.
2161839Swollman */
2171839Swollman
2181839Swollman#define RPCTEST_PROGRAM		((u_long)1)
2191839Swollman#define RPCTEST_VERSION		((u_long)1)
2201839Swollman#define RPCTEST_NULL_PROC	((u_long)2)
2211839Swollman#define RPCTEST_NULL_BATCH_PROC	((u_long)3)
2221839Swollman
2231839Swollman/*
2241839Swollman * By convention, procedure 0 takes null arguments and returns them
2251839Swollman */
2261839Swollman
2271839Swollman#define NULLPROC ((u_long)0)
2281839Swollman
2291839Swollman/*
2301839Swollman * Below are the client handle creation routines for the various
2318858Srgrimes * implementations of client side rpc.  They can return NULL if a
2321839Swollman * creation failure occurs.
2331839Swollman */
2341839Swollman
2351839Swollman/*
2361839Swollman * Memory based rpc (for speed check and testing)
2371839Swollman * CLIENT *
2381839Swollman * clntraw_create(prog, vers)
2391839Swollman *	u_long prog;
2401839Swollman *	u_long vers;
2411839Swollman */
2421903Swollman__BEGIN_DECLS
2431903Swollmanextern CLIENT *clntraw_create	__P((u_long, u_long));
2441903Swollman__END_DECLS
2451839Swollman
2461839Swollman
2471839Swollman/*
2481839Swollman * Generic client creation routine. Supported protocols are "udp" and "tcp"
2491903Swollman * CLIENT *
2501903Swollman * clnt_create(host, prog, vers, prot);
2511903Swollman *	char *host; 	-- hostname
2521903Swollman *	u_long prog;	-- program number
2531903Swollman *	u_long vers;	-- version number
2541903Swollman *	char *prot;	-- protocol
2551839Swollman */
2561903Swollman__BEGIN_DECLS
2571903Swollmanextern CLIENT *clnt_create	__P((char *, u_long, u_long, char *));
2581903Swollman__END_DECLS
2591839Swollman
2601839Swollman
2611839Swollman/*
2621839Swollman * TCP based rpc
2631839Swollman * CLIENT *
2641839Swollman * clnttcp_create(raddr, prog, vers, sockp, sendsz, recvsz)
2651839Swollman *	struct sockaddr_in *raddr;
2661839Swollman *	u_long prog;
2671839Swollman *	u_long version;
2681839Swollman *	register int *sockp;
2691839Swollman *	u_int sendsz;
2701839Swollman *	u_int recvsz;
2711839Swollman */
2721903Swollman__BEGIN_DECLS
2731903Swollmanextern CLIENT *clnttcp_create	__P((struct sockaddr_in *,
2741903Swollman				     u_long,
2751903Swollman				     u_long,
2761903Swollman				     int *,
2771903Swollman				     u_int,
2781903Swollman				     u_int));
2791903Swollman__END_DECLS
2801839Swollman
2811903Swollman
2821839Swollman/*
2831839Swollman * UDP based rpc.
2841839Swollman * CLIENT *
2851839Swollman * clntudp_create(raddr, program, version, wait, sockp)
2861839Swollman *	struct sockaddr_in *raddr;
2871839Swollman *	u_long program;
2881839Swollman *	u_long version;
2891839Swollman *	struct timeval wait;
2901839Swollman *	int *sockp;
2911839Swollman *
2921839Swollman * Same as above, but you specify max packet sizes.
2931839Swollman * CLIENT *
2941839Swollman * clntudp_bufcreate(raddr, program, version, wait, sockp, sendsz, recvsz)
2951839Swollman *	struct sockaddr_in *raddr;
2961839Swollman *	u_long program;
2971839Swollman *	u_long version;
2981839Swollman *	struct timeval wait;
2991839Swollman *	int *sockp;
3001839Swollman *	u_int sendsz;
3011839Swollman *	u_int recvsz;
3021839Swollman */
3031903Swollman__BEGIN_DECLS
3041903Swollmanextern CLIENT *clntudp_create	__P((struct sockaddr_in *,
3051903Swollman				     u_long,
3061903Swollman				     u_long,
3071903Swollman				     struct timeval,
3081903Swollman				     int *));
3091903Swollmanextern CLIENT *clntudp_bufcreate __P((struct sockaddr_in *,
3101903Swollman				     u_long,
3111903Swollman				     u_long,
3121903Swollman				     struct timeval,
3131903Swollman				     int *,
3141903Swollman				     u_int,
3151903Swollman				     u_int));
3161903Swollman__END_DECLS
3171839Swollman
3181903Swollman
3191839Swollman/*
3201839Swollman * Print why creation failed
3211839Swollman */
3221903Swollman__BEGIN_DECLS
3231903Swollmanextern void clnt_pcreateerror	__P((char *));			/* stderr */
3241903Swollmanextern char *clnt_spcreateerror	__P((char *));			/* string */
3251903Swollman__END_DECLS
3261839Swollman
3271839Swollman/*
3281839Swollman * Like clnt_perror(), but is more verbose in its output
3298858Srgrimes */
3301903Swollman__BEGIN_DECLS
3311903Swollmanextern void clnt_perrno		__P((enum clnt_stat));		/* stderr */
3321903Swollmanextern char *clnt_sperrno	__P((enum clnt_stat));		/* string */
3331903Swollman__END_DECLS
3341839Swollman
3351839Swollman/*
3361839Swollman * Print an English error message, given the client error code
3371839Swollman */
3381903Swollman__BEGIN_DECLS
3391903Swollmanextern void clnt_perror		__P((CLIENT *, char *)); 	/* stderr */
3401903Swollmanextern char *clnt_sperror	__P((CLIENT *, char *));	/* string */
3411903Swollman__END_DECLS
3421839Swollman
3431903Swollman
3448858Srgrimes/*
3451839Swollman * If a creation fails, the following allows the user to figure out why.
3461839Swollman */
3471839Swollmanstruct rpc_createerr {
3481839Swollman	enum clnt_stat cf_stat;
3491839Swollman	struct rpc_err cf_error; /* useful when cf_stat == RPC_PMAPFAILURE */
3501839Swollman};
3511839Swollman
3521839Swollmanextern struct rpc_createerr rpc_createerr;
3531839Swollman
3541839Swollman
3551839Swollman#define UDPMSGSIZE	8800	/* rpc imposed limit on udp msg size */
3561839Swollman#define RPCSMALLMSGSIZE	400	/* a more reasonable packet size */
3571839Swollman
3581903Swollman#endif /* !_RPC_CLNT_H */
359