2 * RPC client-side interface.
6 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
7 * unrestricted use provided that this legend is included on all tape
8 * media and as a part of the software program in whole or part. Users
9 * may copy or modify Sun RPC without charge, but are not authorized
10 * to license or distribute it to anyone else except as part of a product or
11 * program developed by the user.
13 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
14 * WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
15 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
17 * Sun RPC is provided with no support and without any obligation on the
18 * part of Sun Microsystems, Inc. to assist in its use, correction,
19 * modification or enhancement.
21 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
22 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
23 * OR ANY PART THEREOF.
25 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
26 * or profits or other special, indirect and consequential damages, even if
27 * Sun has been advised of the possibility of such damages.
29 * Sun Microsystems, Inc.
31 * Mountain View, California 94043
33 * from: @(#)clnt.h 1.31 88/02/08 SMI
34 * from: @(#)clnt.h 2.1 88/07/29 4.0 RPCSRC
35 * $Id: clnt.h,v 1.4 1996/01/30 23:31:48 mpp Exp $
39 * clnt.h - Client side remote procedure call interface.
41 * Copyright (C) 1984, Sun Microsystems, Inc.
44 #ifndef __RPC_CLIENT_H
45 #define __RPC_CLIENT_H
47 #include <sys/cdefs.h>
48 #include <rpc/types.h>
52 * Rpc calls return an enum clnt_stat. This should be looked at more,
53 * since each implementation is required to live with this (implementation
54 * independent) list of errors.
57 RPC_SUCCESS=0, /* call succeeded */
61 RPC_CANTENCODEARGS=1, /* can't encode arguments */
62 RPC_CANTDECODERES=2, /* can't decode results */
63 RPC_CANTSEND=3, /* failure in sending call */
64 RPC_CANTRECV=4, /* failure in receiving result */
65 RPC_TIMEDOUT=5, /* call timed out */
69 RPC_VERSMISMATCH=6, /* rpc versions not compatible */
70 RPC_AUTHERROR=7, /* authentication error */
71 RPC_PROGUNAVAIL=8, /* program not available */
72 RPC_PROGVERSMISMATCH=9, /* program version mismatched */
73 RPC_PROCUNAVAIL=10, /* procedure unavailable */
74 RPC_CANTDECODEARGS=11, /* decode arguments error */
75 RPC_SYSTEMERROR=12, /* generic "other problem" */
78 * callrpc & clnt_create errors
80 RPC_UNKNOWNHOST=13, /* unknown host name */
81 RPC_UNKNOWNPROTO=17, /* unkown protocol */
86 RPC_PMAPFAILURE=14, /* the pmapper failed in its call */
87 RPC_PROGNOTREGISTERED=15, /* remote program is not registered */
99 enum clnt_stat re_status;
101 int RE_errno; /* related system error */
102 enum auth_stat RE_why; /* why the auth error occurred */
104 u_long low; /* lowest verion supported */
105 u_long high; /* highest verion supported */
107 struct { /* maybe meaningful if RPC_FAILED */
110 } RE_lb; /* life boot & debugging only */
112 #define re_errno ru.RE_errno
113 #define re_why ru.RE_why
114 #define re_vers ru.RE_vers
115 #define re_lb ru.RE_lb
121 * Created by individual implementations, see e.g. rpc_udp.c.
122 * Client is responsible for initializing auth, see e.g. auth_none.c.
125 AUTH *cl_auth; /* authenticator */
127 enum clnt_stat(*cl_call)(); /* call remote procedure */
128 void (*cl_abort)(); /* abort a call */
129 void (*cl_geterr)(); /* get specific error code */
130 bool_t (*cl_freeres)(); /* frees results */
131 void (*cl_destroy)(); /* destroy this structure */
132 bool_t (*cl_control)(); /* the ioctl() of rpc */
134 caddr_t cl_private; /* private stuff */
139 * client side rpc interface ops
141 * Parameter types are:
147 * CLNT_CALL(rh, proc, xargs, argsp, xres, resp, timeout)
154 * struct timeval timeout;
156 #define CLNT_CALL(rh, proc, xargs, argsp, xres, resp, secs) \
157 ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, argsp, xres, resp, secs))
158 #define clnt_call(rh, proc, xargs, argsp, xres, resp, secs) \
159 ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, argsp, xres, resp, secs))
166 #define CLNT_ABORT(rh) ((*(rh)->cl_ops->cl_abort)(rh))
167 #define clnt_abort(rh) ((*(rh)->cl_ops->cl_abort)(rh))
174 #define CLNT_GETERR(rh,errp) ((*(rh)->cl_ops->cl_geterr)(rh, errp))
175 #define clnt_geterr(rh,errp) ((*(rh)->cl_ops->cl_geterr)(rh, errp))
180 * CLNT_FREERES(rh, xres, resp);
185 #define CLNT_FREERES(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
186 #define clnt_freeres(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
190 * CLNT_CONTROL(cl, request, info)
195 #define CLNT_CONTROL(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
196 #define clnt_control(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
199 * control operations that apply to both udp and tcp transports
201 #define CLSET_TIMEOUT 1 /* set timeout (timeval) */
202 #define CLGET_TIMEOUT 2 /* get timeout (timeval) */
203 #define CLGET_SERVER_ADDR 3 /* get server's address (sockaddr) */
205 * udp only control operations
207 #define CLSET_RETRY_TIMEOUT 4 /* set retry timeout (timeval) */
208 #define CLGET_RETRY_TIMEOUT 5 /* get retry timeout (timeval) */
215 #define CLNT_DESTROY(rh) ((*(rh)->cl_ops->cl_destroy)(rh))
216 #define clnt_destroy(rh) ((*(rh)->cl_ops->cl_destroy)(rh))
220 * RPCTEST is a test program which is accessible on every rpc
221 * transport/port. It is used for testing, performance evaluation,
222 * and network administration.
225 #define RPCTEST_PROGRAM ((u_long)1)
226 #define RPCTEST_VERSION ((u_long)1)
227 #define RPCTEST_NULL_PROC ((u_long)2)
228 #define RPCTEST_NULL_BATCH_PROC ((u_long)3)
231 * By convention, procedure 0 takes null arguments and returns them
234 #define NULLPROC ((u_long)0)
239 * Below are the client handle creation routines for the various
240 * implementations of client side rpc. They can return NULL if a
241 * creation failure occurs.
245 * Memory based rpc (for speed check and testing)
247 * clntraw_create(prog, vers)
251 extern CLIENT *clntraw_create (u_long, u_long);
254 * Generic client creation routine. Supported protocols are "udp" and "tcp"
256 * clnt_create(host, prog, vers, prot);
257 * char *host; -- hostname
258 * u_long prog; -- program number
259 * u_long vers; -- version number
260 * char *prot; -- protocol
262 extern CLIENT *clnt_create (char *, u_long, u_long, char *);
268 * clnttcp_create(raddr, prog, vers, sockp, sendsz, recvsz)
269 * struct sockaddr_in *raddr;
272 * register int *sockp;
277 extern CLIENT *clnttcp_create (struct sockaddr_in *, u_long, u_long,
278 int *, u_int, u_int);
283 * clntudp_create(raddr, program, version, wait, sockp)
284 * struct sockaddr_in *raddr;
287 * struct timeval wait;
290 * Same as above, but you specify max packet sizes.
292 * clntudp_bufcreate(raddr, program, version, wait, sockp, sendsz, recvsz)
293 * struct sockaddr_in *raddr;
296 * struct timeval wait;
302 extern CLIENT *clntudp_create (struct sockaddr_in *, u_long, u_long,
303 struct timeval, int *);
304 extern CLIENT *clntudp_bufcreate(struct sockaddr_in *, u_long, u_long,
305 struct timeval, int *, u_int, u_int);
309 * Print why creation failed
312 extern void clnt_pcreateerror (char *); /* stderr */
313 extern char *clnt_spcreateerror (char *); /* string */
316 * Like clnt_perror(), but is more verbose in its output
319 extern void clnt_perrno (enum clnt_stat); /* stderr */
320 extern char *clnt_sperrno(enum clnt_stat); /* string */
323 * Print an English error message, given the client error code
326 extern void clnt_perror (CLIENT *, char *); /* stderr */
327 extern char *clnt_sperror(CLIENT *, char *); /* string */
330 * Call routine on remote host
333 extern int callrpc (char *host, u_long prognum, u_long versnum, u_long procnum,
334 xdrproc_t inproc, char *in,
335 xdrproc_t outproc, char *out);
341 * If a creation fails, the following allows the user to figure out why.
343 struct rpc_createerr {
344 enum clnt_stat cf_stat;
345 struct rpc_err cf_error; /* useful when cf_stat == RPC_PMAPFAILURE */
346 const char *cf_file; /* failed file + line */
350 extern struct rpc_createerr rpc_createerr;
353 #define UDPMSGSIZE 8800 /* rpc imposed limit on udp msg size */
354 #define RPCSMALLMSGSIZE 400 /* a more reasonable packet size */