1 /* $NetBSD: clnt.h,v 1.14 2000/06/02 22:57:55 fvdl Exp $ */
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.
11 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
12 * WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
13 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
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.
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.
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.
27 * Sun Microsystems, Inc.
29 * Mountain View, California 94043
31 * from: @(#)clnt.h 1.31 94/04/29 SMI
32 * from: @(#)clnt.h 2.1 88/07/29 4.0 RPCSRC
33 * $FreeBSD: src/include/rpc/clnt.h,v 1.17 2002/04/28 15:18:45 des Exp $
37 * clnt.h - Client side remote procedure call interface.
39 * Copyright (C) 1984, Sun Microsystems, Inc.
44 #include <rpc/clnt_stat.h>
45 #include <sys/cdefs.h>
46 #include <netconfig.h>
50 * Well-known IPV6 RPC broadcast address.
52 #define RPCB_MULTICAST_ADDR "ff02::202"
55 * the following errors are in general unrecoverable. The caller
56 * should give up rather than retry.
58 #define IS_UNRECOVERABLE_RPC(s) (((s) == RPC_AUTHERROR) || \
59 ((s) == RPC_CANTENCODEARGS) || \
60 ((s) == RPC_CANTDECODERES) || \
61 ((s) == RPC_VERSMISMATCH) || \
62 ((s) == RPC_PROCUNAVAIL) || \
63 ((s) == RPC_PROGUNAVAIL) || \
64 ((s) == RPC_PROGVERSMISMATCH) || \
65 ((s) == RPC_CANTDECODEARGS))
71 enum clnt_stat re_status;
73 int RE_errno; /* related system error */
74 enum auth_stat RE_why; /* why the auth error occurred */
76 rpcvers_t low; /* lowest version supported */
77 rpcvers_t high; /* highest version supported */
79 struct { /* maybe meaningful if RPC_FAILED */
82 } RE_lb; /* life boot & debugging only */
84 #define re_errno ru.RE_errno
85 #define re_why ru.RE_why
86 #define re_vers ru.RE_vers
87 #define re_lb ru.RE_lb
93 * Created by individual implementations
94 * Client is responsible for initializing auth, see e.g. auth_none.c.
96 typedef struct __rpc_client {
97 AUTH *cl_auth; /* authenticator */
99 /* call remote procedure */
100 enum clnt_stat (*cl_call)(struct __rpc_client *,
101 rpcproc_t, xdrproc_t, void *, xdrproc_t,
102 void *, struct timeval);
104 void (*cl_abort)(struct __rpc_client *);
105 /* get specific error code */
106 void (*cl_geterr)(struct __rpc_client *,
109 bool_t (*cl_freeres)(struct __rpc_client *,
111 /* destroy this structure */
112 void (*cl_destroy)(struct __rpc_client *);
113 /* the ioctl() of rpc */
114 bool_t (*cl_control)(struct __rpc_client *, u_int,
117 void *cl_private; /* private stuff */
118 char *cl_netid; /* network token */
119 char *cl_tp; /* device name */
124 * Timers used for the pseudo-transport protocol when using datagrams
127 u_short rt_srtt; /* smoothed round-trip time */
128 u_short rt_deviate; /* estimated deviation */
129 u_long rt_rtxcur; /* current (backed-off) rto */
133 * Feedback values used for possible congestion and rate control
135 #define FEEDBACK_REXMIT1 1 /* first retransmit */
136 #define FEEDBACK_OK 2 /* no retransmits */
138 /* Used to set version of portmapper used in broadcast */
140 #define CLCR_SET_LOWVERS 3
141 #define CLCR_GET_LOWVERS 4
143 #define RPCSMALLMSGSIZE 400 /* a more reasonable packet size */
146 * client side rpc interface ops
148 * Parameter types are:
154 * CLNT_CALL(rh, proc, xargs, argsp, xres, resp, timeout)
161 * struct timeval timeout;
163 #define CLNT_CALL(rh, proc, xargs, argsp, xres, resp, secs) \
164 ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, \
165 argsp, xres, resp, secs))
166 #define clnt_call(rh, proc, xargs, argsp, xres, resp, secs) \
167 ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, \
168 argsp, xres, resp, secs))
175 #define CLNT_ABORT(rh) ((*(rh)->cl_ops->cl_abort)(rh))
176 #define clnt_abort(rh) ((*(rh)->cl_ops->cl_abort)(rh))
183 #define CLNT_GETERR(rh,errp) ((*(rh)->cl_ops->cl_geterr)(rh, errp))
184 #define clnt_geterr(rh,errp) ((*(rh)->cl_ops->cl_geterr)(rh, errp))
189 * CLNT_FREERES(rh, xres, resp);
194 #define CLNT_FREERES(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
195 #define clnt_freeres(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
199 * CLNT_CONTROL(cl, request, info)
204 #define CLNT_CONTROL(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
205 #define clnt_control(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
208 * control operations that apply to both udp and tcp transports
210 #define CLSET_TIMEOUT 1 /* set timeout (timeval) */
211 #define CLGET_TIMEOUT 2 /* get timeout (timeval) */
212 #define CLGET_SERVER_ADDR 3 /* get server's address (sockaddr) */
213 #define CLGET_FD 6 /* get connections file descriptor */
214 #define CLGET_SVC_ADDR 7 /* get server's address (netbuf) */
215 #define CLSET_FD_CLOSE 8 /* close fd while clnt_destroy */
216 #define CLSET_FD_NCLOSE 9 /* Do not close fd while clnt_destroy */
217 #define CLGET_XID 10 /* Get xid */
218 #define CLSET_XID 11 /* Set xid */
219 #define CLGET_VERS 12 /* Get version number */
220 #define CLSET_VERS 13 /* Set version number */
221 #define CLGET_PROG 14 /* Get program number */
222 #define CLSET_PROG 15 /* Set program number */
223 #define CLSET_SVC_ADDR 16 /* get server's address (netbuf) */
224 #define CLSET_PUSH_TIMOD 17 /* push timod if not already present */
225 #define CLSET_POP_TIMOD 18 /* pop timod */
227 * Connectionless only control operations
229 #define CLSET_RETRY_TIMEOUT 4 /* set retry timeout (timeval) */
230 #define CLGET_RETRY_TIMEOUT 5 /* get retry timeout (timeval) */
231 #define CLSET_ASYNC 19
232 #define CLSET_CONNECT 20 /* Use connect() for UDP. (int) */
239 #define CLNT_DESTROY(rh) ((*(rh)->cl_ops->cl_destroy)(rh))
240 #define clnt_destroy(rh) ((*(rh)->cl_ops->cl_destroy)(rh))
244 * RPCTEST is a test program which is accessible on every rpc
245 * transport/port. It is used for testing, performance evaluation,
246 * and network administration.
249 #define RPCTEST_PROGRAM ((rpcprog_t)1)
250 #define RPCTEST_VERSION ((rpcvers_t)1)
251 #define RPCTEST_NULL_PROC ((rpcproc_t)2)
252 #define RPCTEST_NULL_BATCH_PROC ((rpcproc_t)3)
255 * By convention, procedure 0 takes null arguments and returns them
258 #define NULLPROC ((rpcproc_t)0)
261 * Below are the client handle creation routines for the various
262 * implementations of client side rpc. They can return NULL if a
263 * creation failure occurs.
267 * Generic client creation routine. Supported protocols are those that
268 * belong to the nettype namespace (/etc/netconfig).
270 * clnt_create(host, prog, vers, prot);
271 * const char *host; -- hostname
272 * const rpcprog_t prog; -- program number
273 * const rpcvers_t vers; -- version number
274 * const char *prot; -- protocol
277 extern CLIENT *clnt_create(const char *, const rpcprog_t, const rpcvers_t,
281 * const char *hostname; -- hostname
282 * const rpcprog_t prog; -- program number
283 * const rpcvers_t vers; -- version number
284 * const char *nettype; -- network type
288 * Generic client creation routine. Supported protocols are which belong
289 * to the nettype name space.
291 extern CLIENT *clnt_create_vers(const char *, const rpcprog_t, rpcvers_t *,
292 const rpcvers_t, const rpcvers_t,
295 * const char *host; -- hostname
296 * const rpcprog_t prog; -- program number
297 * rpcvers_t *vers_out; -- servers highest available version
298 * const rpcvers_t vers_low; -- low version number
299 * const rpcvers_t vers_high; -- high version number
300 * const char *nettype; -- network type
305 * Generic client creation routine. It takes a netconfig structure
308 extern CLIENT *clnt_tp_create(const char *, const rpcprog_t,
309 const rpcvers_t, const struct netconfig *);
311 * const char *hostname; -- hostname
312 * const rpcprog_t prog; -- program number
313 * const rpcvers_t vers; -- version number
314 * const struct netconfig *netconf; -- network config structure
318 * Generic TLI create routine. Only provided for compatibility.
321 extern CLIENT *clnt_tli_create(const int, const struct netconfig *,
322 const struct netbuf *, const rpcprog_t,
323 const rpcvers_t, const u_int, const u_int);
325 * const register int fd; -- fd
326 * const struct netconfig *nconf; -- netconfig structure
327 * const struct netbuf *svcaddr; -- servers address
328 * const u_long prog; -- program number
329 * const u_long vers; -- version number
330 * const u_int sendsz; -- send size
331 * const u_int recvsz; -- recv size
335 * Low level clnt create routine for connectionful transports, e.g. tcp.
337 extern CLIENT *clnt_vc_create(const int, const struct netbuf *,
338 const rpcprog_t, const rpcvers_t,
339 const u_int, const u_int);
341 * Added for compatibility to old rpc 4.0. Obsoleted by clnt_vc_create().
343 extern CLIENT *clntunix_create(struct sockaddr_un *,
344 u_long, u_long, int *, u_int, u_int);
346 * const int fd; -- open file descriptor
347 * const struct netbuf *svcaddr; -- servers address
348 * const rpcprog_t prog; -- program number
349 * const rpcvers_t vers; -- version number
350 * const u_int sendsz; -- buffer recv size
351 * const u_int recvsz; -- buffer send size
355 * Low level clnt create routine for connectionless transports, e.g. udp.
357 extern CLIENT *clnt_dg_create(const int, const struct netbuf *,
358 const rpcprog_t, const rpcvers_t,
359 const u_int, const u_int);
361 * const int fd; -- open file descriptor
362 * const struct netbuf *svcaddr; -- servers address
363 * const rpcprog_t program; -- program number
364 * const rpcvers_t version; -- version number
365 * const u_int sendsz; -- buffer recv size
366 * const u_int recvsz; -- buffer send size
370 * Memory based rpc (for speed check and testing)
372 * clnt_raw_create(prog, vers)
376 extern CLIENT *clnt_raw_create(rpcprog_t, rpcvers_t);
382 * Print why creation failed
385 extern void clnt_pcreateerror(const char *); /* stderr */
386 extern char *clnt_spcreateerror(const char *); /* string */
390 * Like clnt_perror(), but is more verbose in its output
393 extern void clnt_perrno(enum clnt_stat); /* stderr */
394 extern char *clnt_sperrno(enum clnt_stat); /* string */
398 * Print an English error message, given the client error code
401 extern void clnt_perror(CLIENT *, const char *); /* stderr */
402 extern char *clnt_sperror(CLIENT *, const char *); /* string */
407 * If a creation fails, the following allows the user to figure out why.
409 struct rpc_createerr {
410 enum clnt_stat cf_stat;
411 struct rpc_err cf_error; /* useful when cf_stat == RPC_PMAPFAILURE */
416 extern struct rpc_createerr *__rpc_createerr(void);
418 #define rpc_createerr (*(__rpc_createerr()))
420 extern struct rpc_createerr rpc_createerr;
421 #endif /* _THREAD_SAFE */
424 * The simplified interface:
426 * rpc_call(host, prognum, versnum, procnum, inproc, in, outproc, out, nettype)
428 * const rpcprog_t prognum;
429 * const rpcvers_t versnum;
430 * const rpcproc_t procnum;
431 * const xdrproc_t inproc, outproc;
434 * const char *nettype;
437 extern enum clnt_stat rpc_call(const char *, const rpcprog_t,
438 const rpcvers_t, const rpcproc_t,
439 const xdrproc_t, const char *,
440 const xdrproc_t, char *, const char *);
444 * RPC broadcast interface
445 * The call is broadcasted to all locally connected nets.
447 * extern enum clnt_stat
448 * rpc_broadcast(prog, vers, proc, xargs, argsp, xresults, resultsp,
449 * eachresult, nettype)
450 * const rpcprog_t prog; -- program number
451 * const rpcvers_t vers; -- version number
452 * const rpcproc_t proc; -- procedure number
453 * const xdrproc_t xargs; -- xdr routine for args
454 * caddr_t argsp; -- pointer to args
455 * const xdrproc_t xresults; -- xdr routine for results
456 * caddr_t resultsp; -- pointer to results
457 * const resultproc_t eachresult; -- call with each result
458 * const char *nettype; -- Transport type
460 * For each valid response received, the procedure eachresult is called.
462 * done = eachresult(resp, raddr, nconf)
465 * struct netbuf *raddr;
466 * struct netconfig *nconf;
467 * where resp points to the results of the call and raddr is the
468 * address if the responder to the broadcast. nconf is the transport
469 * on which the response was received.
471 * extern enum clnt_stat
472 * rpc_broadcast_exp(prog, vers, proc, xargs, argsp, xresults, resultsp,
473 * eachresult, inittime, waittime, nettype)
474 * const rpcprog_t prog; -- program number
475 * const rpcvers_t vers; -- version number
476 * const rpcproc_t proc; -- procedure number
477 * const xdrproc_t xargs; -- xdr routine for args
478 * caddr_t argsp; -- pointer to args
479 * const xdrproc_t xresults; -- xdr routine for results
480 * caddr_t resultsp; -- pointer to results
481 * const resultproc_t eachresult; -- call with each result
482 * const int inittime; -- how long to wait initially
483 * const int waittime; -- maximum time to wait
484 * const char *nettype; -- Transport type
487 typedef bool_t (*resultproc_t)(caddr_t, ...);
490 extern enum clnt_stat rpc_broadcast(const rpcprog_t, const rpcvers_t,
491 const rpcproc_t, const xdrproc_t,
492 caddr_t, const xdrproc_t, caddr_t,
493 const resultproc_t, const char *);
494 extern enum clnt_stat rpc_broadcast_exp(const rpcprog_t, const rpcvers_t,
495 const rpcproc_t, const xdrproc_t,
496 caddr_t, const xdrproc_t, caddr_t,
497 const resultproc_t, const int,
498 const int, const char *);
501 /* For backward compatibility */
502 #include <rpc/clnt_soc.h>
504 #endif /* !_RPC_CLNT_H_ */