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