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