Fix up mix of man(7)/mdoc(7).
[netbsd-mini2440.git] / include / rpc / clnt.h
blobefd2cac949f2a3b74ca7dd8ef0b53030df1397ca
1 /* $NetBSD: clnt.h,v 1.19 2005/02/03 04:39:32 perry Exp $ */
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.
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.
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.
28 * 2550 Garcia Avenue
29 * Mountain View, California 94043
31 * from: @(#)clnt.h 1.31 94/04/29 SMI
32 * @(#)clnt.h 2.1 88/07/29 4.0 RPCSRC
36 * clnt.h - Client side remote procedure call interface.
38 * Copyright (C) 1984, Sun Microsystems, Inc.
41 #ifndef _RPC_CLNT_H_
42 #define _RPC_CLNT_H_
43 #include <sys/cdefs.h>
45 #include <rpc/rpc_com.h>
48 * Well-known IPV6 RPC broadcast address.
50 #define RPCB_MULTICAST_ADDR "ff02::202"
53 * Rpc calls return an enum clnt_stat. This should be looked at more,
54 * since each implementation is required to live with this (implementation
55 * independent) list of errors.
57 enum clnt_stat {
58 RPC_SUCCESS=0, /* call succeeded */
60 * local errors
62 RPC_CANTENCODEARGS=1, /* can't encode arguments */
63 RPC_CANTDECODERES=2, /* can't decode results */
64 RPC_CANTSEND=3, /* failure in sending call */
65 RPC_CANTRECV=4, /* failure in receiving result */
66 RPC_TIMEDOUT=5, /* call timed out */
68 * remote errors
70 RPC_VERSMISMATCH=6, /* rpc versions not compatible */
71 RPC_AUTHERROR=7, /* authentication error */
72 RPC_PROGUNAVAIL=8, /* program not available */
73 RPC_PROGVERSMISMATCH=9, /* program version mismatched */
74 RPC_PROCUNAVAIL=10, /* procedure unavailable */
75 RPC_CANTDECODEARGS=11, /* decode arguments error */
76 RPC_SYSTEMERROR=12, /* generic "other problem" */
79 * rpc_call & clnt_create errors
81 RPC_UNKNOWNHOST=13, /* unknown host name */
82 RPC_UNKNOWNPROTO=17, /* unknown protocol */
83 RPC_UNKNOWNADDR = 19, /* Remote address unknown */
84 RPC_NOBROADCAST = 21, /* Broadcasting not supported */
87 * rpcbind errors
89 RPC_RPCBFAILURE=14, /* the pmapper failed in its call */
90 #define RPC_PMAPFAILURE RPC_RPCBFAILURE
91 RPC_PROGNOTREGISTERED=15, /* remote program is not registered */
92 RPC_N2AXLATEFAILURE = 22, /* name -> addr translation failed */
95 * Misc error in the TLI library (provided for compatibility)
97 RPC_TLIERROR = 20,
100 * unspecified error
102 RPC_FAILED=16,
105 * asynchronous errors
107 RPC_INPROGRESS = 24,
108 RPC_STALERACHANDLE = 25
113 * Error info.
115 struct rpc_err {
116 enum clnt_stat re_status;
117 union {
118 int RE_errno; /* related system error */
119 enum auth_stat RE_why; /* why the auth error occurred */
120 struct {
121 rpcvers_t low; /* lowest version supported */
122 rpcvers_t high; /* highest version supported */
123 } RE_vers;
124 struct { /* maybe meaningful if RPC_FAILED */
125 int32_t s1;
126 int32_t s2;
127 } RE_lb; /* life boot & debugging only */
128 } ru;
129 #define re_errno ru.RE_errno
130 #define re_why ru.RE_why
131 #define re_vers ru.RE_vers
132 #define re_lb ru.RE_lb
137 * Client rpc handle.
138 * Created by individual implementations
139 * Client is responsible for initializing auth, see e.g. auth_none.c.
141 typedef struct __rpc_client {
142 AUTH *cl_auth; /* authenticator */
143 const struct clnt_ops {
144 /* call remote procedure */
145 enum clnt_stat (*cl_call)(struct __rpc_client *,
146 rpcproc_t, xdrproc_t, const char *,
147 xdrproc_t, caddr_t, struct timeval);
148 /* abort a call */
149 void (*cl_abort)(struct __rpc_client *);
150 /* get specific error code */
151 void (*cl_geterr)(struct __rpc_client *,
152 struct rpc_err *);
153 /* frees results */
154 bool_t (*cl_freeres)(struct __rpc_client *,
155 xdrproc_t, caddr_t);
156 /* destroy this structure */
157 void (*cl_destroy)(struct __rpc_client *);
158 /* the ioctl() of rpc */
159 bool_t (*cl_control)(struct __rpc_client *, u_int,
160 char *);
161 } *cl_ops;
162 void *cl_private; /* private stuff */
163 char *cl_netid; /* network token */
164 char *cl_tp; /* device name */
165 } CLIENT;
169 * Timers used for the pseudo-transport protocol when using datagrams
171 struct rpc_timers {
172 u_short rt_srtt; /* smoothed round-trip time */
173 u_short rt_deviate; /* estimated deviation */
174 u_long rt_rtxcur; /* current (backed-off) rto */
178 * Feedback values used for possible congestion and rate control
180 #define FEEDBACK_REXMIT1 1 /* first retransmit */
181 #define FEEDBACK_OK 2 /* no retransmits */
183 /* Used to set version of portmapper used in broadcast */
185 #define CLCR_SET_LOWVERS 3
186 #define CLCR_GET_LOWVERS 4
188 #define RPCSMALLMSGSIZE 400 /* a more reasonable packet size */
191 * client side rpc interface ops
193 * Parameter types are:
198 * enum clnt_stat
199 * CLNT_CALL(rh, proc, xargs, argsp, xres, resp, timeout)
200 * CLIENT *rh;
201 * rpcproc_t proc;
202 * xdrproc_t xargs;
203 * caddr_t argsp;
204 * xdrproc_t xres;
205 * caddr_t resp;
206 * struct timeval timeout;
208 #define CLNT_CALL(rh, proc, xargs, argsp, xres, resp, secs) \
209 ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, \
210 (const char *)(const void *)(argsp), xres, (caddr_t)(void *)resp, secs))
211 #define clnt_call(rh, proc, xargs, argsp, xres, resp, secs) \
212 ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, \
213 (const char *)(const void *)(argsp), xres, (caddr_t)(void *)resp, secs))
216 * void
217 * CLNT_ABORT(rh);
218 * CLIENT *rh;
220 #define CLNT_ABORT(rh) ((*(rh)->cl_ops->cl_abort)(rh))
221 #define clnt_abort(rh) ((*(rh)->cl_ops->cl_abort)(rh))
224 * struct rpc_err
225 * CLNT_GETERR(rh);
226 * CLIENT *rh;
228 #define CLNT_GETERR(rh,errp) ((*(rh)->cl_ops->cl_geterr)(rh, errp))
229 #define clnt_geterr(rh,errp) ((*(rh)->cl_ops->cl_geterr)(rh, errp))
233 * bool_t
234 * CLNT_FREERES(rh, xres, resp);
235 * CLIENT *rh;
236 * xdrproc_t xres;
237 * caddr_t resp;
239 #define CLNT_FREERES(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
240 #define clnt_freeres(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
243 * bool_t
244 * CLNT_CONTROL(cl, request, info)
245 * CLIENT *cl;
246 * u_int request;
247 * char *info;
249 #define CLNT_CONTROL(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
250 #define clnt_control(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
253 * control operations that apply to both udp and tcp transports
255 #define CLSET_TIMEOUT 1 /* set timeout (timeval) */
256 #define CLGET_TIMEOUT 2 /* get timeout (timeval) */
257 #define CLGET_SERVER_ADDR 3 /* get server's address (sockaddr) */
258 #define CLGET_FD 6 /* get connections file descriptor */
259 #define CLGET_SVC_ADDR 7 /* get server's address (netbuf) */
260 #define CLSET_FD_CLOSE 8 /* close fd while clnt_destroy */
261 #define CLSET_FD_NCLOSE 9 /* Do not close fd while clnt_destroy */
262 #define CLGET_XID 10 /* Get xid */
263 #define CLSET_XID 11 /* Set xid */
264 #define CLGET_VERS 12 /* Get version number */
265 #define CLSET_VERS 13 /* Set version number */
266 #define CLGET_PROG 14 /* Get program number */
267 #define CLSET_PROG 15 /* Set program number */
268 #define CLSET_SVC_ADDR 16 /* get server's address (netbuf) */
269 #define CLSET_PUSH_TIMOD 17 /* push timod if not already present */
270 #define CLSET_POP_TIMOD 18 /* pop timod */
272 * Connectionless only control operations
274 #define CLSET_RETRY_TIMEOUT 4 /* set retry timeout (timeval) */
275 #define CLGET_RETRY_TIMEOUT 5 /* get retry timeout (timeval) */
278 * void
279 * CLNT_DESTROY(rh);
280 * CLIENT *rh;
282 #define CLNT_DESTROY(rh) ((*(rh)->cl_ops->cl_destroy)(rh))
283 #define clnt_destroy(rh) ((*(rh)->cl_ops->cl_destroy)(rh))
287 * RPCTEST is a test program which is accessible on every rpc
288 * transport/port. It is used for testing, performance evaluation,
289 * and network administration.
292 #define RPCTEST_PROGRAM ((rpcprog_t)1)
293 #define RPCTEST_VERSION ((rpcvers_t)1)
294 #define RPCTEST_NULL_PROC ((rpcproc_t)2)
295 #define RPCTEST_NULL_BATCH_PROC ((rpcproc_t)3)
298 * By convention, procedure 0 takes null arguments and returns them
301 #define NULLPROC ((rpcproc_t)0)
304 * Below are the client handle creation routines for the various
305 * implementations of client side rpc. They can return NULL if a
306 * creation failure occurs.
310 * Generic client creation routine. Supported protocols are those that
311 * belong to the nettype namespace (/etc/netconfig).
312 * CLIENT *
313 * clnt_create(host, prog, vers, prot);
314 * const char *host; -- hostname
315 * const rpcprog_t prog; -- program number
316 * const rpcvers_t vers; -- version number
317 * const char *prot; -- protocol
319 __BEGIN_DECLS
320 extern CLIENT *clnt_create(const char *, const rpcprog_t, const rpcvers_t,
321 const char *);
324 * const char *hostname; -- hostname
325 * const rpcprog_t prog; -- program number
326 * const rpcvers_t vers; -- version number
327 * const char *nettype; -- network type
331 * Generic client creation routine. Supported protocols are which belong
332 * to the nettype name space.
334 extern CLIENT *clnt_create_vers(const char *, const rpcprog_t, rpcvers_t *,
335 const rpcvers_t, const rpcvers_t,
336 const char *);
338 * const char *host; -- hostname
339 * const rpcprog_t prog; -- program number
340 * rpcvers_t *vers_out; -- servers highest available version
341 * const rpcvers_t vers_low; -- low version number
342 * const rpcvers_t vers_high; -- high version number
343 * const char *nettype; -- network type
348 * Generic client creation routine. It takes a netconfig structure
349 * instead of nettype
351 extern CLIENT *clnt_tp_create(const char *, const rpcprog_t,
352 const rpcvers_t, const struct netconfig *);
354 * const char *hostname; -- hostname
355 * const rpcprog_t prog; -- program number
356 * const rpcvers_t vers; -- version number
357 * const struct netconfig *netconf; -- network config structure
361 * Generic TLI create routine. Only provided for compatibility.
364 extern CLIENT *clnt_tli_create(const int, const struct netconfig *,
365 const struct netbuf *, const rpcprog_t,
366 const rpcvers_t, const u_int, const u_int);
368 * const register int fd; -- fd
369 * const struct netconfig *nconf; -- netconfig structure
370 * const struct netbuf *svcaddr; -- servers address
371 * const u_long prog; -- program number
372 * const u_long vers; -- version number
373 * const u_int sendsz; -- send size
374 * const u_int recvsz; -- recv size
378 * Low level clnt create routine for connectionful transports, e.g. tcp.
380 extern CLIENT *clnt_vc_create(const int, const struct netbuf *,
381 const rpcprog_t, const rpcvers_t,
382 const u_int, const u_int);
384 * const int fd; -- open file descriptor
385 * const struct netbuf *svcaddr; -- servers address
386 * const rpcprog_t prog; -- program number
387 * const rpcvers_t vers; -- version number
388 * const u_int sendsz; -- buffer recv size
389 * const u_int recvsz; -- buffer send size
393 * Low level clnt create routine for connectionless transports, e.g. udp.
395 extern CLIENT *clnt_dg_create(const int, const struct netbuf *,
396 const rpcprog_t, const rpcvers_t,
397 const u_int, const u_int);
399 * const int fd; -- open file descriptor
400 * const struct netbuf *svcaddr; -- servers address
401 * const rpcprog_t program; -- program number
402 * const rpcvers_t version; -- version number
403 * const u_int sendsz; -- buffer recv size
404 * const u_int recvsz; -- buffer send size
408 * Memory based rpc (for speed check and testing)
409 * CLIENT *
410 * clnt_raw_create(prog, vers)
411 * u_long prog;
412 * u_long vers;
414 extern CLIENT *clnt_raw_create (rpcprog_t, rpcvers_t);
416 __END_DECLS
420 * Print why creation failed
422 __BEGIN_DECLS
423 extern void clnt_pcreateerror (const char *); /* stderr */
424 extern char *clnt_spcreateerror (const char *); /* string */
425 __END_DECLS
428 * Like clnt_perror(), but is more verbose in its output
430 __BEGIN_DECLS
431 extern void clnt_perrno (enum clnt_stat); /* stderr */
432 extern char *clnt_sperrno (enum clnt_stat); /* string */
433 __END_DECLS
436 * Print an English error message, given the client error code
438 __BEGIN_DECLS
439 extern void clnt_perror (CLIENT *, const char *); /* stderr */
440 extern char *clnt_sperror (CLIENT *, const char *); /* string */
441 __END_DECLS
445 * If a creation fails, the following allows the user to figure out why.
447 struct rpc_createerr {
448 enum clnt_stat cf_stat;
449 struct rpc_err cf_error; /* useful when cf_stat == RPC_PMAPFAILURE */
452 #ifdef _REENTRANT
453 __BEGIN_DECLS
454 extern struct rpc_createerr *__rpc_createerr(void);
455 __END_DECLS
456 #define rpc_createerr (*(__rpc_createerr()))
457 #else
458 extern struct rpc_createerr rpc_createerr;
459 #endif /* _REENTRANT */
462 * The simplified interface:
463 * enum clnt_stat
464 * rpc_call(host, prognum, versnum, procnum, inproc, in, outproc, out, nettype)
465 * const char *host;
466 * const rpcprog_t prognum;
467 * const rpcvers_t versnum;
468 * const rpcproc_t procnum;
469 * const xdrproc_t inproc, outproc;
470 * const char *in;
471 * char *out;
472 * const char *nettype;
474 __BEGIN_DECLS
475 extern enum clnt_stat rpc_call(const char *, const rpcprog_t,
476 const rpcvers_t, const rpcproc_t,
477 const xdrproc_t, const char *,
478 const xdrproc_t, char *, const char *);
479 __END_DECLS
482 * RPC broadcast interface
483 * The call is broadcasted to all locally connected nets.
485 * extern enum clnt_stat
486 * rpc_broadcast(prog, vers, proc, xargs, argsp, xresults, resultsp,
487 * eachresult, nettype)
488 * const rpcprog_t prog; -- program number
489 * const rpcvers_t vers; -- version number
490 * const rpcproc_t proc; -- procedure number
491 * const xdrproc_t xargs; -- xdr routine for args
492 * caddr_t argsp; -- pointer to args
493 * const xdrproc_t xresults; -- xdr routine for results
494 * caddr_t resultsp; -- pointer to results
495 * const resultproc_t eachresult; -- call with each result
496 * const char *nettype; -- Transport type
498 * For each valid response received, the procedure eachresult is called.
499 * Its form is:
500 * done = eachresult(resp, raddr, nconf)
501 * bool_t done;
502 * caddr_t resp;
503 * struct netbuf *raddr;
504 * struct netconfig *nconf;
505 * where resp points to the results of the call and raddr is the
506 * address if the responder to the broadcast. nconf is the transport
507 * on which the response was received.
509 * extern enum clnt_stat
510 * rpc_broadcast_exp(prog, vers, proc, xargs, argsp, xresults, resultsp,
511 * eachresult, inittime, waittime, nettype)
512 * const rpcprog_t prog; -- program number
513 * const rpcvers_t vers; -- version number
514 * const rpcproc_t proc; -- procedure number
515 * const xdrproc_t xargs; -- xdr routine for args
516 * caddr_t argsp; -- pointer to args
517 * const xdrproc_t xresults; -- xdr routine for results
518 * caddr_t resultsp; -- pointer to results
519 * const resultproc_t eachresult; -- call with each result
520 * const int inittime; -- how long to wait initially
521 * const int waittime; -- maximum time to wait
522 * const char *nettype; -- Transport type
525 typedef bool_t (*resultproc_t)(caddr_t, ...);
527 __BEGIN_DECLS
528 extern enum clnt_stat rpc_broadcast(const rpcprog_t, const rpcvers_t,
529 const rpcproc_t, const xdrproc_t, const char *, const xdrproc_t, caddr_t,
530 const resultproc_t, const char *);
531 extern enum clnt_stat rpc_broadcast_exp(const rpcprog_t, const rpcvers_t,
532 const rpcproc_t, const xdrproc_t, const char *, const xdrproc_t, caddr_t,
533 const resultproc_t, const int, const int, const char *);
534 __END_DECLS
536 /* For backward compatibility */
537 #include <rpc/clnt_soc.h>
539 #endif /* !_RPC_CLNT_H_ */