clnt.h revision 1.13 1 1.13 christos /* $NetBSD: clnt.h,v 1.13 1998/11/16 12:07:43 christos Exp $ */
2 1.4 cgd
3 1.1 deraadt /*
4 1.1 deraadt * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
5 1.1 deraadt * unrestricted use provided that this legend is included on all tape
6 1.1 deraadt * media and as a part of the software program in whole or part. Users
7 1.1 deraadt * may copy or modify Sun RPC without charge, but are not authorized
8 1.1 deraadt * to license or distribute it to anyone else except as part of a product or
9 1.1 deraadt * program developed by the user.
10 1.1 deraadt *
11 1.1 deraadt * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
12 1.1 deraadt * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
13 1.1 deraadt * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
14 1.1 deraadt *
15 1.1 deraadt * Sun RPC is provided with no support and without any obligation on the
16 1.1 deraadt * part of Sun Microsystems, Inc. to assist in its use, correction,
17 1.1 deraadt * modification or enhancement.
18 1.1 deraadt *
19 1.1 deraadt * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
20 1.1 deraadt * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
21 1.1 deraadt * OR ANY PART THEREOF.
22 1.1 deraadt *
23 1.1 deraadt * In no event will Sun Microsystems, Inc. be liable for any lost revenue
24 1.1 deraadt * or profits or other special, indirect and consequential damages, even if
25 1.1 deraadt * Sun has been advised of the possibility of such damages.
26 1.1 deraadt *
27 1.1 deraadt * Sun Microsystems, Inc.
28 1.1 deraadt * 2550 Garcia Avenue
29 1.1 deraadt * Mountain View, California 94043
30 1.3 mycroft *
31 1.3 mycroft * from: @(#)clnt.h 1.31 88/02/08 SMI
32 1.4 cgd * @(#)clnt.h 2.1 88/07/29 4.0 RPCSRC
33 1.1 deraadt */
34 1.1 deraadt
35 1.1 deraadt /*
36 1.1 deraadt * clnt.h - Client side remote procedure call interface.
37 1.1 deraadt *
38 1.1 deraadt * Copyright (C) 1984, Sun Microsystems, Inc.
39 1.1 deraadt */
40 1.1 deraadt
41 1.2 brezak #ifndef _RPC_CLNT_H_
42 1.2 brezak #define _RPC_CLNT_H_
43 1.2 brezak #include <sys/cdefs.h>
44 1.1 deraadt
45 1.1 deraadt /*
46 1.10 lukem * Rpc calls return an enum clnt_stat. This should be looked at more,
47 1.1 deraadt * since each implementation is required to live with this (implementation
48 1.1 deraadt * independent) list of errors.
49 1.1 deraadt */
50 1.1 deraadt enum clnt_stat {
51 1.1 deraadt RPC_SUCCESS=0, /* call succeeded */
52 1.1 deraadt /*
53 1.1 deraadt * local errors
54 1.1 deraadt */
55 1.1 deraadt RPC_CANTENCODEARGS=1, /* can't encode arguments */
56 1.1 deraadt RPC_CANTDECODERES=2, /* can't decode results */
57 1.1 deraadt RPC_CANTSEND=3, /* failure in sending call */
58 1.1 deraadt RPC_CANTRECV=4, /* failure in receiving result */
59 1.1 deraadt RPC_TIMEDOUT=5, /* call timed out */
60 1.1 deraadt /*
61 1.1 deraadt * remote errors
62 1.1 deraadt */
63 1.10 lukem RPC_VERSMISMATCH=6, /* rpc versions not compatible */
64 1.1 deraadt RPC_AUTHERROR=7, /* authentication error */
65 1.1 deraadt RPC_PROGUNAVAIL=8, /* program not available */
66 1.1 deraadt RPC_PROGVERSMISMATCH=9, /* program version mismatched */
67 1.1 deraadt RPC_PROCUNAVAIL=10, /* procedure unavailable */
68 1.1 deraadt RPC_CANTDECODEARGS=11, /* decode arguments error */
69 1.1 deraadt RPC_SYSTEMERROR=12, /* generic "other problem" */
70 1.1 deraadt
71 1.1 deraadt /*
72 1.1 deraadt * callrpc & clnt_create errors
73 1.1 deraadt */
74 1.1 deraadt RPC_UNKNOWNHOST=13, /* unknown host name */
75 1.1 deraadt RPC_UNKNOWNPROTO=17, /* unkown protocol */
76 1.1 deraadt
77 1.1 deraadt /*
78 1.1 deraadt * _ create errors
79 1.1 deraadt */
80 1.1 deraadt RPC_PMAPFAILURE=14, /* the pmapper failed in its call */
81 1.1 deraadt RPC_PROGNOTREGISTERED=15, /* remote program is not registered */
82 1.1 deraadt /*
83 1.1 deraadt * unspecified error
84 1.1 deraadt */
85 1.1 deraadt RPC_FAILED=16
86 1.1 deraadt };
87 1.1 deraadt
88 1.1 deraadt
89 1.1 deraadt /*
90 1.1 deraadt * Error info.
91 1.1 deraadt */
92 1.1 deraadt struct rpc_err {
93 1.1 deraadt enum clnt_stat re_status;
94 1.1 deraadt union {
95 1.11 lukem int RE_errno; /* related system error */
96 1.1 deraadt enum auth_stat RE_why; /* why the auth error occurred */
97 1.1 deraadt struct {
98 1.11 lukem u_int32_t low; /* lowest version supported */
99 1.11 lukem u_int32_t high; /* highest version supported */
100 1.1 deraadt } RE_vers;
101 1.1 deraadt struct { /* maybe meaningful if RPC_FAILED */
102 1.6 cgd int32_t s1;
103 1.6 cgd int32_t s2;
104 1.1 deraadt } RE_lb; /* life boot & debugging only */
105 1.1 deraadt } ru;
106 1.1 deraadt #define re_errno ru.RE_errno
107 1.1 deraadt #define re_why ru.RE_why
108 1.1 deraadt #define re_vers ru.RE_vers
109 1.1 deraadt #define re_lb ru.RE_lb
110 1.1 deraadt };
111 1.1 deraadt
112 1.1 deraadt
113 1.1 deraadt /*
114 1.10 lukem * Client rpc handle.
115 1.1 deraadt * Created by individual implementations, see e.g. rpc_udp.c.
116 1.1 deraadt * Client is responsible for initializing auth, see e.g. auth_none.c.
117 1.1 deraadt */
118 1.5 cgd typedef struct __rpc_client {
119 1.1 deraadt AUTH *cl_auth; /* authenticator */
120 1.12 mycroft const struct clnt_ops {
121 1.10 lukem /* call remote procedure */
122 1.5 cgd enum clnt_stat (*cl_call) __P((struct __rpc_client *,
123 1.10 lukem u_long, xdrproc_t, caddr_t, xdrproc_t,
124 1.10 lukem caddr_t, struct timeval));
125 1.10 lukem /* abort a call */
126 1.5 cgd void (*cl_abort) __P((struct __rpc_client *));
127 1.10 lukem /* get specific error code */
128 1.5 cgd void (*cl_geterr) __P((struct __rpc_client *,
129 1.10 lukem struct rpc_err *));
130 1.10 lukem /* frees results */
131 1.5 cgd bool_t (*cl_freeres) __P((struct __rpc_client *,
132 1.10 lukem xdrproc_t, caddr_t));
133 1.10 lukem /* destroy this structure */
134 1.5 cgd void (*cl_destroy) __P((struct __rpc_client *));
135 1.10 lukem /* the ioctl() of rpc */
136 1.10 lukem bool_t (*cl_control) __P((struct __rpc_client *, u_int,
137 1.10 lukem char *));
138 1.1 deraadt } *cl_ops;
139 1.13 christos void *cl_private; /* private stuff */
140 1.1 deraadt } CLIENT;
141 1.1 deraadt
142 1.1 deraadt
143 1.1 deraadt /*
144 1.10 lukem * client side rpc interface ops
145 1.1 deraadt *
146 1.1 deraadt * Parameter types are:
147 1.1 deraadt *
148 1.1 deraadt */
149 1.1 deraadt
150 1.1 deraadt /*
151 1.1 deraadt * enum clnt_stat
152 1.1 deraadt * CLNT_CALL(rh, proc, xargs, argsp, xres, resp, timeout)
153 1.10 lukem * CLIENT *rh;
154 1.10 lukem * u_long proc;
155 1.10 lukem * xdrproc_t xargs;
156 1.10 lukem * caddr_t argsp;
157 1.10 lukem * xdrproc_t xres;
158 1.10 lukem * caddr_t resp;
159 1.10 lukem * struct timeval timeout;
160 1.1 deraadt */
161 1.5 cgd #define CLNT_CALL(rh, proc, xargs, argsp, xres, resp, secs) \
162 1.13 christos ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, \
163 1.13 christos (caddr_t)(void *)argsp, xres, (caddr_t)(void *)resp, secs))
164 1.5 cgd #define clnt_call(rh, proc, xargs, argsp, xres, resp, secs) \
165 1.13 christos ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, \
166 1.13 christos (caddr_t)(void *)argsp, xres, (caddr_t)(void *)resp, secs))
167 1.1 deraadt
168 1.1 deraadt /*
169 1.1 deraadt * void
170 1.1 deraadt * CLNT_ABORT(rh);
171 1.10 lukem * CLIENT *rh;
172 1.1 deraadt */
173 1.1 deraadt #define CLNT_ABORT(rh) ((*(rh)->cl_ops->cl_abort)(rh))
174 1.1 deraadt #define clnt_abort(rh) ((*(rh)->cl_ops->cl_abort)(rh))
175 1.1 deraadt
176 1.1 deraadt /*
177 1.1 deraadt * struct rpc_err
178 1.1 deraadt * CLNT_GETERR(rh);
179 1.10 lukem * CLIENT *rh;
180 1.1 deraadt */
181 1.1 deraadt #define CLNT_GETERR(rh,errp) ((*(rh)->cl_ops->cl_geterr)(rh, errp))
182 1.1 deraadt #define clnt_geterr(rh,errp) ((*(rh)->cl_ops->cl_geterr)(rh, errp))
183 1.1 deraadt
184 1.1 deraadt
185 1.1 deraadt /*
186 1.1 deraadt * bool_t
187 1.1 deraadt * CLNT_FREERES(rh, xres, resp);
188 1.10 lukem * CLIENT *rh;
189 1.10 lukem * xdrproc_t xres;
190 1.10 lukem * caddr_t resp;
191 1.1 deraadt */
192 1.1 deraadt #define CLNT_FREERES(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
193 1.1 deraadt #define clnt_freeres(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
194 1.1 deraadt
195 1.1 deraadt /*
196 1.1 deraadt * bool_t
197 1.1 deraadt * CLNT_CONTROL(cl, request, info)
198 1.10 lukem * CLIENT *cl;
199 1.10 lukem * u_int request;
200 1.10 lukem * char *info;
201 1.1 deraadt */
202 1.1 deraadt #define CLNT_CONTROL(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
203 1.1 deraadt #define clnt_control(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
204 1.1 deraadt
205 1.1 deraadt /*
206 1.1 deraadt * control operations that apply to both udp and tcp transports
207 1.1 deraadt */
208 1.1 deraadt #define CLSET_TIMEOUT 1 /* set timeout (timeval) */
209 1.1 deraadt #define CLGET_TIMEOUT 2 /* get timeout (timeval) */
210 1.1 deraadt #define CLGET_SERVER_ADDR 3 /* get server's address (sockaddr) */
211 1.1 deraadt /*
212 1.1 deraadt * udp only control operations
213 1.1 deraadt */
214 1.1 deraadt #define CLSET_RETRY_TIMEOUT 4 /* set retry timeout (timeval) */
215 1.1 deraadt #define CLGET_RETRY_TIMEOUT 5 /* get retry timeout (timeval) */
216 1.1 deraadt
217 1.1 deraadt /*
218 1.1 deraadt * void
219 1.1 deraadt * CLNT_DESTROY(rh);
220 1.10 lukem * CLIENT *rh;
221 1.1 deraadt */
222 1.1 deraadt #define CLNT_DESTROY(rh) ((*(rh)->cl_ops->cl_destroy)(rh))
223 1.1 deraadt #define clnt_destroy(rh) ((*(rh)->cl_ops->cl_destroy)(rh))
224 1.1 deraadt
225 1.1 deraadt
226 1.1 deraadt /*
227 1.10 lukem * RPCTEST is a test program which is accessable on every rpc
228 1.1 deraadt * transport/port. It is used for testing, performance evaluation,
229 1.1 deraadt * and network administration.
230 1.1 deraadt */
231 1.1 deraadt
232 1.10 lukem #define RPCTEST_PROGRAM ((u_long)1)
233 1.10 lukem #define RPCTEST_VERSION ((u_long)1)
234 1.10 lukem #define RPCTEST_NULL_PROC ((u_long)2)
235 1.10 lukem #define RPCTEST_NULL_BATCH_PROC ((u_long)3)
236 1.1 deraadt
237 1.1 deraadt /*
238 1.1 deraadt * By convention, procedure 0 takes null arguments and returns them
239 1.1 deraadt */
240 1.1 deraadt
241 1.10 lukem #define NULLPROC ((u_long)0)
242 1.1 deraadt
243 1.1 deraadt /*
244 1.1 deraadt * Below are the client handle creation routines for the various
245 1.10 lukem * implementations of client side rpc. They can return NULL if a
246 1.1 deraadt * creation failure occurs.
247 1.1 deraadt */
248 1.1 deraadt
249 1.1 deraadt /*
250 1.10 lukem * Memory based rpc (for speed check and testing)
251 1.1 deraadt * CLIENT *
252 1.1 deraadt * clntraw_create(prog, vers)
253 1.10 lukem * u_long prog;
254 1.10 lukem * u_long vers;
255 1.1 deraadt */
256 1.2 brezak __BEGIN_DECLS
257 1.10 lukem extern CLIENT *clntraw_create __P((u_long, u_long));
258 1.2 brezak __END_DECLS
259 1.1 deraadt
260 1.1 deraadt
261 1.1 deraadt /*
262 1.1 deraadt * Generic client creation routine. Supported protocols are "udp" and "tcp"
263 1.2 brezak * CLIENT *
264 1.2 brezak * clnt_create(host, prog, vers, prot);
265 1.10 lukem * char *host; -- hostname
266 1.10 lukem * u_long prog; -- program number
267 1.10 lukem * u_long vers; -- version number
268 1.10 lukem * char *prot; -- protocol
269 1.2 brezak */
270 1.2 brezak __BEGIN_DECLS
271 1.10 lukem extern CLIENT *clnt_create __P((char *, u_long, u_long, char *));
272 1.2 brezak __END_DECLS
273 1.1 deraadt
274 1.1 deraadt
275 1.1 deraadt /*
276 1.10 lukem * TCP based rpc
277 1.1 deraadt * CLIENT *
278 1.1 deraadt * clnttcp_create(raddr, prog, vers, sockp, sendsz, recvsz)
279 1.1 deraadt * struct sockaddr_in *raddr;
280 1.10 lukem * u_long prog;
281 1.10 lukem * u_long version;
282 1.10 lukem * register int *sockp;
283 1.10 lukem * u_int sendsz;
284 1.10 lukem * u_int recvsz;
285 1.1 deraadt */
286 1.2 brezak __BEGIN_DECLS
287 1.10 lukem extern CLIENT *clnttcp_create __P((struct sockaddr_in *,
288 1.10 lukem u_long,
289 1.10 lukem u_long,
290 1.10 lukem int *,
291 1.10 lukem u_int,
292 1.10 lukem u_int));
293 1.2 brezak __END_DECLS
294 1.1 deraadt
295 1.2 brezak
296 1.1 deraadt /*
297 1.10 lukem * UDP based rpc.
298 1.1 deraadt * CLIENT *
299 1.1 deraadt * clntudp_create(raddr, program, version, wait, sockp)
300 1.1 deraadt * struct sockaddr_in *raddr;
301 1.10 lukem * u_long program;
302 1.10 lukem * u_long version;
303 1.10 lukem * struct timeval wait;
304 1.10 lukem * int *sockp;
305 1.1 deraadt *
306 1.1 deraadt * Same as above, but you specify max packet sizes.
307 1.1 deraadt * CLIENT *
308 1.1 deraadt * clntudp_bufcreate(raddr, program, version, wait, sockp, sendsz, recvsz)
309 1.1 deraadt * struct sockaddr_in *raddr;
310 1.10 lukem * u_long program;
311 1.10 lukem * u_long version;
312 1.10 lukem * struct timeval wait;
313 1.10 lukem * int *sockp;
314 1.10 lukem * u_int sendsz;
315 1.10 lukem * u_int recvsz;
316 1.1 deraadt */
317 1.2 brezak __BEGIN_DECLS
318 1.10 lukem extern CLIENT *clntudp_create __P((struct sockaddr_in *,
319 1.10 lukem u_long,
320 1.10 lukem u_long,
321 1.10 lukem struct timeval,
322 1.10 lukem int *));
323 1.2 brezak extern CLIENT *clntudp_bufcreate __P((struct sockaddr_in *,
324 1.10 lukem u_long,
325 1.10 lukem u_long,
326 1.10 lukem struct timeval,
327 1.10 lukem int *,
328 1.10 lukem u_int,
329 1.10 lukem u_int));
330 1.2 brezak __END_DECLS
331 1.2 brezak
332 1.1 deraadt
333 1.1 deraadt /*
334 1.1 deraadt * Print why creation failed
335 1.1 deraadt */
336 1.2 brezak __BEGIN_DECLS
337 1.10 lukem extern void clnt_pcreateerror __P((char *)); /* stderr */
338 1.10 lukem extern char *clnt_spcreateerror __P((char *)); /* string */
339 1.2 brezak __END_DECLS
340 1.1 deraadt
341 1.1 deraadt /*
342 1.1 deraadt * Like clnt_perror(), but is more verbose in its output
343 1.1 deraadt */
344 1.2 brezak __BEGIN_DECLS
345 1.2 brezak extern void clnt_perrno __P((enum clnt_stat)); /* stderr */
346 1.2 brezak extern char *clnt_sperrno __P((enum clnt_stat)); /* string */
347 1.2 brezak __END_DECLS
348 1.1 deraadt
349 1.1 deraadt /*
350 1.1 deraadt * Print an English error message, given the client error code
351 1.1 deraadt */
352 1.2 brezak __BEGIN_DECLS
353 1.10 lukem extern void clnt_perror __P((CLIENT *, char *)); /* stderr */
354 1.10 lukem extern char *clnt_sperror __P((CLIENT *, char *)); /* string */
355 1.2 brezak __END_DECLS
356 1.2 brezak
357 1.1 deraadt
358 1.1 deraadt /*
359 1.1 deraadt * If a creation fails, the following allows the user to figure out why.
360 1.1 deraadt */
361 1.1 deraadt struct rpc_createerr {
362 1.1 deraadt enum clnt_stat cf_stat;
363 1.1 deraadt struct rpc_err cf_error; /* useful when cf_stat == RPC_PMAPFAILURE */
364 1.1 deraadt };
365 1.1 deraadt
366 1.1 deraadt extern struct rpc_createerr rpc_createerr;
367 1.1 deraadt
368 1.1 deraadt
369 1.10 lukem #define UDPMSGSIZE 8800 /* rpc imposed limit on udp msg size */
370 1.1 deraadt #define RPCSMALLMSGSIZE 400 /* a more reasonable packet size */
371 1.1 deraadt
372 1.7 perry #endif /* !_RPC_CLNT_H_ */
373