clnt.h revision 23037
1/*
2 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
3 * unrestricted use provided that this legend is included on all tape
4 * media and as a part of the software program in whole or part.  Users
5 * may copy or modify Sun RPC without charge, but are not authorized
6 * to license or distribute it to anyone else except as part of a product or
7 * program developed by the user.
8 *
9 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
10 * WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
11 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
12 *
13 * Sun RPC is provided with no support and without any obligation on the
14 * part of Sun Microsystems, Inc. to assist in its use, correction,
15 * modification or enhancement.
16 *
17 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
18 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
19 * OR ANY PART THEREOF.
20 *
21 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
22 * or profits or other special, indirect and consequential damages, even if
23 * Sun has been advised of the possibility of such damages.
24 *
25 * Sun Microsystems, Inc.
26 * 2550 Garcia Avenue
27 * Mountain View, California  94043
28 *
29 *	from: @(#)clnt.h 1.31 88/02/08 SMI
30 *	from: @(#)clnt.h	2.1 88/07/29 4.0 RPCSRC
31 *	$Id$
32 */
33
34/*
35 * clnt.h - Client side remote procedure call interface.
36 *
37 * Copyright (C) 1984, Sun Microsystems, Inc.
38 */
39
40#ifndef _RPC_CLNT_H_
41#define _RPC_CLNT_H_
42#include <sys/cdefs.h>
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 */
49enum 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 */
91struct rpc_err {
92	enum clnt_stat re_status;
93	union {
94		int RE_errno;		/* related system error */
95		enum auth_stat RE_why;	/* why the auth error occurred */
96		struct {
97			u_int32_t low;	/* lowest verion supported */
98			u_int32_t high;	/* highest verion supported */
99		} RE_vers;
100		struct {		/* maybe meaningful if RPC_FAILED */
101			int32_t s1;
102			int32_t 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 */
117typedef struct __rpc_client {
118	AUTH	*cl_auth;			/* authenticator */
119	struct clnt_ops {
120		/* call remote procedure */
121		enum clnt_stat	(*cl_call) __P((struct __rpc_client *,
122					u_long, xdrproc_t, caddr_t, xdrproc_t,
123					caddr_t, struct timeval));
124		/* abort a call */
125		void		(*cl_abort) __P((struct __rpc_client *));
126		/* get specific error code */
127		void		(*cl_geterr) __P((struct __rpc_client *,
128					struct rpc_err *));
129		/* frees results */
130		bool_t		(*cl_freeres) __P((struct __rpc_client *,
131					xdrproc_t, caddr_t));
132		/* destroy this structure */
133		void		(*cl_destroy) __P((struct __rpc_client *));
134		/* the ioctl() of rpc */
135		bool_t          (*cl_control) __P((struct __rpc_client *, u_int,
136					void *));
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, (caddr_t)argsp, \
162		xres, (caddr_t)resp, secs))
163#define	clnt_call(rh, proc, xargs, argsp, xres, resp, secs)	\
164	((*(rh)->cl_ops->cl_call)(rh, proc, xargs, (caddr_t)argsp, \
165		xres, (caddr_t)resp, secs))
166
167/*
168 * void
169 * CLNT_ABORT(rh);
170 * 	CLIENT *rh;
171 */
172#define	CLNT_ABORT(rh)	((*(rh)->cl_ops->cl_abort)(rh))
173#define	clnt_abort(rh)	((*(rh)->cl_ops->cl_abort)(rh))
174
175/*
176 * struct rpc_err
177 * CLNT_GETERR(rh);
178 * 	CLIENT *rh;
179 */
180#define	CLNT_GETERR(rh,errp)	((*(rh)->cl_ops->cl_geterr)(rh, errp))
181#define	clnt_geterr(rh,errp)	((*(rh)->cl_ops->cl_geterr)(rh, errp))
182
183
184/*
185 * bool_t
186 * CLNT_FREERES(rh, xres, resp);
187 * 	CLIENT *rh;
188 *	xdrproc_t xres;
189 *	caddr_t resp;
190 */
191#define	CLNT_FREERES(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
192#define	clnt_freeres(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
193
194/*
195 * bool_t
196 * CLNT_CONTROL(cl, request, info)
197 *      CLIENT *cl;
198 *      u_int request;
199 *      char *info;
200 */
201#define	CLNT_CONTROL(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
202#define	clnt_control(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
203
204/*
205 * control operations that apply to both udp and tcp transports
206 */
207#define CLSET_TIMEOUT       1   /* set timeout (timeval) */
208#define CLGET_TIMEOUT       2   /* get timeout (timeval) */
209#define CLGET_SERVER_ADDR   3   /* get server's address (sockaddr) */
210/*
211 * udp only control operations
212 */
213#define CLSET_RETRY_TIMEOUT 4   /* set retry timeout (timeval) */
214#define CLGET_RETRY_TIMEOUT 5   /* get retry timeout (timeval) */
215
216/*
217 * void
218 * CLNT_DESTROY(rh);
219 * 	CLIENT *rh;
220 */
221#define	CLNT_DESTROY(rh)	((*(rh)->cl_ops->cl_destroy)(rh))
222#define	clnt_destroy(rh)	((*(rh)->cl_ops->cl_destroy)(rh))
223
224
225/*
226 * RPCTEST is a test program which is accessible on every rpc
227 * transport/port.  It is used for testing, performance evaluation,
228 * and network administration.
229 */
230
231#define RPCTEST_PROGRAM		((u_long)1)
232#define RPCTEST_VERSION		((u_long)1)
233#define RPCTEST_NULL_PROC	((u_long)2)
234#define RPCTEST_NULL_BATCH_PROC	((u_long)3)
235
236/*
237 * By convention, procedure 0 takes null arguments and returns them
238 */
239
240#define NULLPROC ((u_long)0)
241
242/*
243 * Below are the client handle creation routines for the various
244 * implementations of client side rpc.  They can return NULL if a
245 * creation failure occurs.
246 */
247
248/*
249 * Memory based rpc (for speed check and testing)
250 * CLIENT *
251 * clntraw_create(prog, vers)
252 *	u_long prog;
253 *	u_long vers;
254 */
255__BEGIN_DECLS
256extern CLIENT *clntraw_create	__P((u_long, u_long));
257__END_DECLS
258
259
260/*
261 * Generic client creation routine. Supported protocols are "udp" and "tcp"
262 * CLIENT *
263 * clnt_create(host, prog, vers, prot);
264 *	char *host; 	-- hostname
265 *	u_long prog;	-- program number
266 *	u_long vers;	-- version number
267 *	char *prot;	-- protocol
268 */
269__BEGIN_DECLS
270extern CLIENT *clnt_create	__P((char *, u_long, u_long, char *));
271__END_DECLS
272
273
274/*
275 * TCP based rpc
276 * CLIENT *
277 * clnttcp_create(raddr, prog, vers, sockp, sendsz, recvsz)
278 *	struct sockaddr_in *raddr;
279 *	u_long prog;
280 *	u_long version;
281 *	register int *sockp;
282 *	u_int sendsz;
283 *	u_int recvsz;
284 */
285__BEGIN_DECLS
286extern CLIENT *clnttcp_create	__P((struct sockaddr_in *,
287				     u_long,
288				     u_long,
289				     int *,
290				     u_int,
291				     u_int));
292__END_DECLS
293
294
295/*
296 * UDP based rpc.
297 * CLIENT *
298 * clntudp_create(raddr, program, version, wait, sockp)
299 *	struct sockaddr_in *raddr;
300 *	u_long program;
301 *	u_long version;
302 *	struct timeval wait;
303 *	int *sockp;
304 *
305 * Same as above, but you specify max packet sizes.
306 * CLIENT *
307 * clntudp_bufcreate(raddr, program, version, wait, sockp, sendsz, recvsz)
308 *	struct sockaddr_in *raddr;
309 *	u_long program;
310 *	u_long version;
311 *	struct timeval wait;
312 *	int *sockp;
313 *	u_int sendsz;
314 *	u_int recvsz;
315 */
316__BEGIN_DECLS
317extern CLIENT *clntudp_create	__P((struct sockaddr_in *,
318				     u_long,
319				     u_long,
320				     struct timeval,
321				     int *));
322extern CLIENT *clntudp_bufcreate __P((struct sockaddr_in *,
323				     u_long,
324				     u_long,
325				     struct timeval,
326				     int *,
327				     u_int,
328				     u_int));
329__END_DECLS
330
331
332/*
333 * Print why creation failed
334 */
335__BEGIN_DECLS
336extern void clnt_pcreateerror	__P((char *));			/* stderr */
337extern char *clnt_spcreateerror	__P((char *));			/* string */
338__END_DECLS
339
340/*
341 * Like clnt_perror(), but is more verbose in its output
342 */
343__BEGIN_DECLS
344extern void clnt_perrno		__P((enum clnt_stat));		/* stderr */
345extern char *clnt_sperrno	__P((enum clnt_stat));		/* string */
346__END_DECLS
347
348/*
349 * Print an English error message, given the client error code
350 */
351__BEGIN_DECLS
352extern void clnt_perror		__P((CLIENT *, char *)); 	/* stderr */
353extern char *clnt_sperror	__P((CLIENT *, char *));	/* string */
354__END_DECLS
355
356
357/*
358 * If a creation fails, the following allows the user to figure out why.
359 */
360struct rpc_createerr {
361	enum clnt_stat cf_stat;
362	struct rpc_err cf_error; /* useful when cf_stat == RPC_PMAPFAILURE */
363};
364
365extern struct rpc_createerr rpc_createerr;
366
367
368#define UDPMSGSIZE	8800	/* rpc imposed limit on udp msg size */
369#define RPCSMALLMSGSIZE	400	/* a more reasonable packet size */
370
371#endif /* !_RPC_CLNT_H */
372