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