umount: getopt return value is int, not char
[minix.git] / include / rpc / clnt.h
blob48707b2b447a361a0cc1e19df5098644a01dcb88
1 /* $NetBSD: clnt.h,v 1.21 2011/08/30 17:06:20 plunky 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, (xdrproc_t)xargs, \
210 (const char *)(const void *)(argsp), (xdrproc_t)xres, \
211 (caddr_t)(void *)resp, secs))
212 #define clnt_call(rh, proc, xargs, argsp, xres, resp, secs) \
213 ((*(rh)->cl_ops->cl_call)(rh, proc, (xdrproc_t)xargs, \
214 (const char *)(const void *)(argsp), (xdrproc_t)xres, \
215 (caddr_t)(void *)resp, secs))
218 * void
219 * CLNT_ABORT(rh);
220 * CLIENT *rh;
222 #define CLNT_ABORT(rh) ((*(rh)->cl_ops->cl_abort)(rh))
223 #define clnt_abort(rh) ((*(rh)->cl_ops->cl_abort)(rh))
226 * struct rpc_err
227 * CLNT_GETERR(rh);
228 * CLIENT *rh;
230 #define CLNT_GETERR(rh,errp) ((*(rh)->cl_ops->cl_geterr)(rh, errp))
231 #define clnt_geterr(rh,errp) ((*(rh)->cl_ops->cl_geterr)(rh, errp))
235 * bool_t
236 * CLNT_FREERES(rh, xres, resp);
237 * CLIENT *rh;
238 * xdrproc_t xres;
239 * caddr_t resp;
241 #define CLNT_FREERES(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
242 #define clnt_freeres(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
245 * bool_t
246 * CLNT_CONTROL(cl, request, info)
247 * CLIENT *cl;
248 * u_int request;
249 * char *info;
251 #define CLNT_CONTROL(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
252 #define clnt_control(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
255 * control operations that apply to both udp and tcp transports
257 #define CLSET_TIMEOUT 1 /* set timeout (timeval) */
258 #define CLGET_TIMEOUT 2 /* get timeout (timeval) */
259 #define CLGET_SERVER_ADDR 3 /* get server's address (sockaddr) */
260 #define CLGET_FD 6 /* get connections file descriptor */
261 #define CLGET_SVC_ADDR 7 /* get server's address (netbuf) */
262 #define CLSET_FD_CLOSE 8 /* close fd while clnt_destroy */
263 #define CLSET_FD_NCLOSE 9 /* Do not close fd while clnt_destroy */
264 #define CLGET_XID 10 /* Get xid */
265 #define CLSET_XID 11 /* Set xid */
266 #define CLGET_VERS 12 /* Get version number */
267 #define CLSET_VERS 13 /* Set version number */
268 #define CLGET_PROG 14 /* Get program number */
269 #define CLSET_PROG 15 /* Set program number */
270 #define CLSET_SVC_ADDR 16 /* get server's address (netbuf) */
271 #define CLSET_PUSH_TIMOD 17 /* push timod if not already present */
272 #define CLSET_POP_TIMOD 18 /* pop timod */
274 * Connectionless only control operations
276 #define CLSET_RETRY_TIMEOUT 4 /* set retry timeout (timeval) */
277 #define CLGET_RETRY_TIMEOUT 5 /* get retry timeout (timeval) */
280 * void
281 * CLNT_DESTROY(rh);
282 * CLIENT *rh;
284 #define CLNT_DESTROY(rh) ((*(rh)->cl_ops->cl_destroy)(rh))
285 #define clnt_destroy(rh) ((*(rh)->cl_ops->cl_destroy)(rh))
289 * RPCTEST is a test program which is accessible on every rpc
290 * transport/port. It is used for testing, performance evaluation,
291 * and network administration.
294 #define RPCTEST_PROGRAM ((rpcprog_t)1)
295 #define RPCTEST_VERSION ((rpcvers_t)1)
296 #define RPCTEST_NULL_PROC ((rpcproc_t)2)
297 #define RPCTEST_NULL_BATCH_PROC ((rpcproc_t)3)
300 * By convention, procedure 0 takes null arguments and returns them
303 #define NULLPROC ((rpcproc_t)0)
306 * Below are the client handle creation routines for the various
307 * implementations of client side rpc. They can return NULL if a
308 * creation failure occurs.
312 * Generic client creation routine. Supported protocols are those that
313 * belong to the nettype namespace (/etc/netconfig).
314 * CLIENT *
315 * clnt_create(host, prog, vers, prot);
316 * const char *host; -- hostname
317 * const rpcprog_t prog; -- program number
318 * const rpcvers_t vers; -- version number
319 * const char *prot; -- protocol
321 __BEGIN_DECLS
322 extern CLIENT *clnt_create(const char *, const rpcprog_t, const rpcvers_t,
323 const char *);
326 * const char *hostname; -- hostname
327 * const rpcprog_t prog; -- program number
328 * const rpcvers_t vers; -- version number
329 * const char *nettype; -- network type
333 * Generic client creation routine. Supported protocols are which belong
334 * to the nettype name space.
336 extern CLIENT *clnt_create_vers(const char *, const rpcprog_t, rpcvers_t *,
337 const rpcvers_t, const rpcvers_t,
338 const char *);
340 * const char *host; -- hostname
341 * const rpcprog_t prog; -- program number
342 * rpcvers_t *vers_out; -- servers highest available version
343 * const rpcvers_t vers_low; -- low version number
344 * const rpcvers_t vers_high; -- high version number
345 * const char *nettype; -- network type
350 * Generic client creation routine. It takes a netconfig structure
351 * instead of nettype
353 extern CLIENT *clnt_tp_create(const char *, const rpcprog_t,
354 const rpcvers_t, const struct netconfig *);
356 * const char *hostname; -- hostname
357 * const rpcprog_t prog; -- program number
358 * const rpcvers_t vers; -- version number
359 * const struct netconfig *netconf; -- network config structure
363 * Generic TLI create routine. Only provided for compatibility.
366 extern CLIENT *clnt_tli_create(const int, const struct netconfig *,
367 const struct netbuf *, const rpcprog_t,
368 const rpcvers_t, const u_int, const u_int);
370 * const register int fd; -- fd
371 * const struct netconfig *nconf; -- netconfig structure
372 * const struct netbuf *svcaddr; -- servers address
373 * const u_long prog; -- program number
374 * const u_long vers; -- version number
375 * const u_int sendsz; -- send size
376 * const u_int recvsz; -- recv size
380 * Low level clnt create routine for connectionful transports, e.g. tcp.
382 extern CLIENT *clnt_vc_create(const int, const struct netbuf *,
383 const rpcprog_t, const rpcvers_t,
384 const u_int, const u_int);
386 * const int fd; -- open file descriptor
387 * const struct netbuf *svcaddr; -- servers address
388 * const rpcprog_t prog; -- program number
389 * const rpcvers_t vers; -- version number
390 * const u_int sendsz; -- buffer recv size
391 * const u_int recvsz; -- buffer send size
395 * Low level clnt create routine for connectionless transports, e.g. udp.
397 extern CLIENT *clnt_dg_create(const int, const struct netbuf *,
398 const rpcprog_t, const rpcvers_t,
399 const u_int, const u_int);
401 * const int fd; -- open file descriptor
402 * const struct netbuf *svcaddr; -- servers address
403 * const rpcprog_t program; -- program number
404 * const rpcvers_t version; -- version number
405 * const u_int sendsz; -- buffer recv size
406 * const u_int recvsz; -- buffer send size
410 * Memory based rpc (for speed check and testing)
411 * CLIENT *
412 * clnt_raw_create(prog, vers)
413 * u_long prog;
414 * u_long vers;
416 extern CLIENT *clnt_raw_create (rpcprog_t, rpcvers_t);
418 __END_DECLS
422 * Print why creation failed
424 __BEGIN_DECLS
425 extern void clnt_pcreateerror (const char *); /* stderr */
426 extern char *clnt_spcreateerror (const char *); /* string */
427 __END_DECLS
430 * Like clnt_perror(), but is more verbose in its output
432 __BEGIN_DECLS
433 extern void clnt_perrno (enum clnt_stat); /* stderr */
434 extern char *clnt_sperrno (enum clnt_stat); /* string */
435 __END_DECLS
438 * Print an English error message, given the client error code
440 __BEGIN_DECLS
441 extern void clnt_perror (CLIENT *, const char *); /* stderr */
442 extern char *clnt_sperror (CLIENT *, const char *); /* string */
443 __END_DECLS
447 * If a creation fails, the following allows the user to figure out why.
449 struct rpc_createerr {
450 enum clnt_stat cf_stat;
451 struct rpc_err cf_error; /* useful when cf_stat == RPC_PMAPFAILURE */
454 #ifdef _REENTRANT
455 __BEGIN_DECLS
456 extern struct rpc_createerr *__rpc_createerr(void);
457 __END_DECLS
458 #define rpc_createerr (*(__rpc_createerr()))
459 #else
460 extern struct rpc_createerr rpc_createerr;
461 #endif /* _REENTRANT */
464 * The simplified interface:
465 * enum clnt_stat
466 * rpc_call(host, prognum, versnum, procnum, inproc, in, outproc, out, nettype)
467 * const char *host;
468 * const rpcprog_t prognum;
469 * const rpcvers_t versnum;
470 * const rpcproc_t procnum;
471 * const xdrproc_t inproc, outproc;
472 * const char *in;
473 * char *out;
474 * const char *nettype;
476 __BEGIN_DECLS
477 extern enum clnt_stat rpc_call(const char *, const rpcprog_t,
478 const rpcvers_t, const rpcproc_t,
479 const xdrproc_t, const char *,
480 const xdrproc_t, char *, const char *);
481 __END_DECLS
484 * RPC broadcast interface
485 * The call is broadcasted to all locally connected nets.
487 * extern enum clnt_stat
488 * rpc_broadcast(prog, vers, proc, xargs, argsp, xresults, resultsp,
489 * eachresult, nettype)
490 * const rpcprog_t prog; -- program number
491 * const rpcvers_t vers; -- version number
492 * const rpcproc_t proc; -- procedure number
493 * const xdrproc_t xargs; -- xdr routine for args
494 * caddr_t argsp; -- pointer to args
495 * const xdrproc_t xresults; -- xdr routine for results
496 * caddr_t resultsp; -- pointer to results
497 * const resultproc_t eachresult; -- call with each result
498 * const char *nettype; -- Transport type
500 * For each valid response received, the procedure eachresult is called.
501 * Its form is:
502 * done = eachresult(resp, raddr, nconf)
503 * bool_t done;
504 * caddr_t resp;
505 * struct netbuf *raddr;
506 * struct netconfig *nconf;
507 * where resp points to the results of the call and raddr is the
508 * address if the responder to the broadcast. nconf is the transport
509 * on which the response was received.
511 * extern enum clnt_stat
512 * rpc_broadcast_exp(prog, vers, proc, xargs, argsp, xresults, resultsp,
513 * eachresult, inittime, waittime, nettype)
514 * const rpcprog_t prog; -- program number
515 * const rpcvers_t vers; -- version number
516 * const rpcproc_t proc; -- procedure number
517 * const xdrproc_t xargs; -- xdr routine for args
518 * caddr_t argsp; -- pointer to args
519 * const xdrproc_t xresults; -- xdr routine for results
520 * caddr_t resultsp; -- pointer to results
521 * const resultproc_t eachresult; -- call with each result
522 * const int inittime; -- how long to wait initially
523 * const int waittime; -- maximum time to wait
524 * const char *nettype; -- Transport type
527 typedef bool_t (*resultproc_t)(caddr_t, ...);
529 __BEGIN_DECLS
530 extern enum clnt_stat rpc_broadcast(const rpcprog_t, const rpcvers_t,
531 const rpcproc_t, const xdrproc_t, const char *, const xdrproc_t, caddr_t,
532 const resultproc_t, const char *);
533 extern enum clnt_stat rpc_broadcast_exp(const rpcprog_t, const rpcvers_t,
534 const rpcproc_t, const xdrproc_t, const char *, const xdrproc_t, caddr_t,
535 const resultproc_t, const int, const int, const char *);
536 __END_DECLS
538 /* For backward compatibility */
539 #include <rpc/clnt_soc.h>
541 #endif /* !_RPC_CLNT_H_ */