clnt.h revision 50473
11839Swollman/* 21839Swollman * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 31839Swollman * unrestricted use provided that this legend is included on all tape 41839Swollman * media and as a part of the software program in whole or part. Users 51839Swollman * may copy or modify Sun RPC without charge, but are not authorized 61839Swollman * to license or distribute it to anyone else except as part of a product or 71839Swollman * program developed by the user. 88858Srgrimes * 91839Swollman * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE 1013771Smpp * WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR 111839Swollman * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 128858Srgrimes * 131839Swollman * Sun RPC is provided with no support and without any obligation on the 141839Swollman * part of Sun Microsystems, Inc. to assist in its use, correction, 151839Swollman * modification or enhancement. 168858Srgrimes * 171839Swollman * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 181839Swollman * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC 191839Swollman * OR ANY PART THEREOF. 208858Srgrimes * 211839Swollman * In no event will Sun Microsystems, Inc. be liable for any lost revenue 221839Swollman * or profits or other special, indirect and consequential damages, even if 231839Swollman * Sun has been advised of the possibility of such damages. 248858Srgrimes * 251839Swollman * Sun Microsystems, Inc. 261839Swollman * 2550 Garcia Avenue 271839Swollman * Mountain View, California 94043 281903Swollman * 291903Swollman * from: @(#)clnt.h 1.31 88/02/08 SMI 301903Swollman * from: @(#)clnt.h 2.1 88/07/29 4.0 RPCSRC 3150473Speter * $FreeBSD: head/include/rpc/clnt.h 50473 1999-08-27 23:45:13Z peter $ 321839Swollman */ 331839Swollman 341839Swollman/* 351839Swollman * clnt.h - Client side remote procedure call interface. 361839Swollman * 371839Swollman * Copyright (C) 1984, Sun Microsystems, Inc. 381839Swollman */ 391839Swollman 401903Swollman#ifndef _RPC_CLNT_H_ 411903Swollman#define _RPC_CLNT_H_ 421903Swollman#include <sys/cdefs.h> 4326211Swpaul#include <sys/un.h> 441839Swollman 451839Swollman/* 461839Swollman * Rpc calls return an enum clnt_stat. This should be looked at more, 471839Swollman * since each implementation is required to live with this (implementation 481839Swollman * independent) list of errors. 491839Swollman */ 501839Swollmanenum clnt_stat { 511839Swollman RPC_SUCCESS=0, /* call succeeded */ 521839Swollman /* 531839Swollman * local errors 541839Swollman */ 551839Swollman RPC_CANTENCODEARGS=1, /* can't encode arguments */ 561839Swollman RPC_CANTDECODERES=2, /* can't decode results */ 571839Swollman RPC_CANTSEND=3, /* failure in sending call */ 581839Swollman RPC_CANTRECV=4, /* failure in receiving result */ 591839Swollman RPC_TIMEDOUT=5, /* call timed out */ 601839Swollman /* 611839Swollman * remote errors 621839Swollman */ 631839Swollman RPC_VERSMISMATCH=6, /* rpc versions not compatible */ 641839Swollman RPC_AUTHERROR=7, /* authentication error */ 651839Swollman RPC_PROGUNAVAIL=8, /* program not available */ 661839Swollman RPC_PROGVERSMISMATCH=9, /* program version mismatched */ 671839Swollman RPC_PROCUNAVAIL=10, /* procedure unavailable */ 681839Swollman RPC_CANTDECODEARGS=11, /* decode arguments error */ 691839Swollman RPC_SYSTEMERROR=12, /* generic "other problem" */ 701839Swollman 711839Swollman /* 721839Swollman * callrpc & clnt_create errors 731839Swollman */ 741839Swollman RPC_UNKNOWNHOST=13, /* unknown host name */ 751839Swollman RPC_UNKNOWNPROTO=17, /* unkown protocol */ 761839Swollman 771839Swollman /* 781839Swollman * _ create errors 791839Swollman */ 801839Swollman RPC_PMAPFAILURE=14, /* the pmapper failed in its call */ 811839Swollman RPC_PROGNOTREGISTERED=15, /* remote program is not registered */ 821839Swollman /* 831839Swollman * unspecified error 841839Swollman */ 851839Swollman RPC_FAILED=16 861839Swollman}; 871839Swollman 881839Swollman 891839Swollman/* 901839Swollman * Error info. 911839Swollman */ 921839Swollmanstruct rpc_err { 931839Swollman enum clnt_stat re_status; 941839Swollman union { 9513771Smpp int RE_errno; /* related system error */ 961839Swollman enum auth_stat RE_why; /* why the auth error occurred */ 971839Swollman struct { 9821059Speter u_int32_t low; /* lowest verion supported */ 9921059Speter u_int32_t high; /* highest verion supported */ 1001839Swollman } RE_vers; 1011839Swollman struct { /* maybe meaningful if RPC_FAILED */ 10221059Speter int32_t s1; 10321059Speter int32_t s2; 1041839Swollman } RE_lb; /* life boot & debugging only */ 1051839Swollman } ru; 1061839Swollman#define re_errno ru.RE_errno 1071839Swollman#define re_why ru.RE_why 1081839Swollman#define re_vers ru.RE_vers 1091839Swollman#define re_lb ru.RE_lb 1101839Swollman}; 1111839Swollman 1121839Swollman 1131839Swollman/* 1141839Swollman * Client rpc handle. 1151839Swollman * Created by individual implementations, see e.g. rpc_udp.c. 1161839Swollman * Client is responsible for initializing auth, see e.g. auth_none.c. 1171839Swollman */ 11821059Spetertypedef struct __rpc_client { 1191839Swollman AUTH *cl_auth; /* authenticator */ 1201839Swollman struct clnt_ops { 12121059Speter /* call remote procedure */ 12221059Speter enum clnt_stat (*cl_call) __P((struct __rpc_client *, 12321059Speter u_long, xdrproc_t, caddr_t, xdrproc_t, 12421059Speter caddr_t, struct timeval)); 12521059Speter /* abort a call */ 12621059Speter void (*cl_abort) __P((struct __rpc_client *)); 12721059Speter /* get specific error code */ 12821059Speter void (*cl_geterr) __P((struct __rpc_client *, 12921059Speter struct rpc_err *)); 13021059Speter /* frees results */ 13121059Speter bool_t (*cl_freeres) __P((struct __rpc_client *, 13221059Speter xdrproc_t, caddr_t)); 13321059Speter /* destroy this structure */ 13421059Speter void (*cl_destroy) __P((struct __rpc_client *)); 13521059Speter /* the ioctl() of rpc */ 13621059Speter bool_t (*cl_control) __P((struct __rpc_client *, u_int, 13721059Speter void *)); 1381839Swollman } *cl_ops; 1391839Swollman caddr_t cl_private; /* private stuff */ 1401839Swollman} CLIENT; 1411839Swollman 1421839Swollman 1431839Swollman/* 1441839Swollman * client side rpc interface ops 1451839Swollman * 1461839Swollman * Parameter types are: 1471839Swollman * 1481839Swollman */ 1491839Swollman 1501839Swollman/* 1511839Swollman * enum clnt_stat 1521839Swollman * CLNT_CALL(rh, proc, xargs, argsp, xres, resp, timeout) 1531839Swollman * CLIENT *rh; 1541839Swollman * u_long proc; 1551839Swollman * xdrproc_t xargs; 1561839Swollman * caddr_t argsp; 1571839Swollman * xdrproc_t xres; 1581839Swollman * caddr_t resp; 1591839Swollman * struct timeval timeout; 1601839Swollman */ 1611839Swollman#define CLNT_CALL(rh, proc, xargs, argsp, xres, resp, secs) \ 16221059Speter ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, (caddr_t)argsp, \ 16321059Speter xres, (caddr_t)resp, secs)) 1641839Swollman#define clnt_call(rh, proc, xargs, argsp, xres, resp, secs) \ 16521059Speter ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, (caddr_t)argsp, \ 16621059Speter xres, (caddr_t)resp, secs)) 1671839Swollman 1681839Swollman/* 1691839Swollman * void 1701839Swollman * CLNT_ABORT(rh); 1711839Swollman * CLIENT *rh; 1721839Swollman */ 1731839Swollman#define CLNT_ABORT(rh) ((*(rh)->cl_ops->cl_abort)(rh)) 1741839Swollman#define clnt_abort(rh) ((*(rh)->cl_ops->cl_abort)(rh)) 1751839Swollman 1761839Swollman/* 1771839Swollman * struct rpc_err 1781839Swollman * CLNT_GETERR(rh); 1791839Swollman * CLIENT *rh; 1801839Swollman */ 1811839Swollman#define CLNT_GETERR(rh,errp) ((*(rh)->cl_ops->cl_geterr)(rh, errp)) 1821839Swollman#define clnt_geterr(rh,errp) ((*(rh)->cl_ops->cl_geterr)(rh, errp)) 1831839Swollman 1841839Swollman 1851839Swollman/* 1861839Swollman * bool_t 1871839Swollman * CLNT_FREERES(rh, xres, resp); 1881839Swollman * CLIENT *rh; 1891839Swollman * xdrproc_t xres; 1901839Swollman * caddr_t resp; 1911839Swollman */ 1921839Swollman#define CLNT_FREERES(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp)) 1931839Swollman#define clnt_freeres(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp)) 1941839Swollman 1951839Swollman/* 1961839Swollman * bool_t 1971839Swollman * CLNT_CONTROL(cl, request, info) 1981839Swollman * CLIENT *cl; 1991839Swollman * u_int request; 2001839Swollman * char *info; 2011839Swollman */ 2021839Swollman#define CLNT_CONTROL(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in)) 2031839Swollman#define clnt_control(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in)) 2041839Swollman 2051839Swollman/* 20626211Swpaul * control operations that apply to udp, tcp and unix transports 20726211Swpaul * 20826211Swpaul * Note: options marked XXX are no-ops in this implementation of RPC. 20926211Swpaul * The are present in TI-RPC but can't be implemented here since they 21026211Swpaul * depend on the presence of STREAMS/TLI, which we don't have. 21126211Swpaul * 2121839Swollman */ 2131839Swollman#define CLSET_TIMEOUT 1 /* set timeout (timeval) */ 2141839Swollman#define CLGET_TIMEOUT 2 /* get timeout (timeval) */ 2151839Swollman#define CLGET_SERVER_ADDR 3 /* get server's address (sockaddr) */ 21626211Swpaul#define CLGET_FD 6 /* get connections file descriptor */ 21726211Swpaul#define CLGET_SVC_ADDR 7 /* get server's address (netbuf) XXX */ 21826211Swpaul#define CLSET_FD_CLOSE 8 /* close fd while clnt_destroy */ 21926211Swpaul#define CLSET_FD_NCLOSE 9 /* Do not close fd while clnt_destroy */ 22026211Swpaul#define CLGET_XID 10 /* Get xid */ 22126211Swpaul#define CLSET_XID 11 /* Set xid */ 22226211Swpaul#define CLGET_VERS 12 /* Get version number */ 22326211Swpaul#define CLSET_VERS 13 /* Set version number */ 22426211Swpaul#define CLGET_PROG 14 /* Get program number */ 22526211Swpaul#define CLSET_PROG 15 /* Set program number */ 22626211Swpaul#define CLSET_SVC_ADDR 16 /* get server's address (netbuf) XXX */ 22726211Swpaul#define CLSET_PUSH_TIMOD 17 /* push timod if not already present XXX */ 22826211Swpaul#define CLSET_POP_TIMOD 18 /* pop timod XXX */ 22926211Swpaul 2301839Swollman/* 2311839Swollman * udp only control operations 2321839Swollman */ 2331839Swollman#define CLSET_RETRY_TIMEOUT 4 /* set retry timeout (timeval) */ 2341839Swollman#define CLGET_RETRY_TIMEOUT 5 /* get retry timeout (timeval) */ 2351839Swollman 2361839Swollman/* 23726211Swpaul * Operations which GSSAPI needs. (Bletch.) 23826211Swpaul */ 23926211Swpaul#define CLGET_LOCAL_ADDR 19 /* get local addr (sockaddr) */ 24026211Swpaul 24126211Swpaul 24226211Swpaul/* 2431839Swollman * void 2441839Swollman * CLNT_DESTROY(rh); 2451839Swollman * CLIENT *rh; 2461839Swollman */ 2471839Swollman#define CLNT_DESTROY(rh) ((*(rh)->cl_ops->cl_destroy)(rh)) 2481839Swollman#define clnt_destroy(rh) ((*(rh)->cl_ops->cl_destroy)(rh)) 2491839Swollman 2501839Swollman 2511839Swollman/* 25213771Smpp * RPCTEST is a test program which is accessible on every rpc 2531839Swollman * transport/port. It is used for testing, performance evaluation, 2541839Swollman * and network administration. 2551839Swollman */ 2561839Swollman 2571839Swollman#define RPCTEST_PROGRAM ((u_long)1) 2581839Swollman#define RPCTEST_VERSION ((u_long)1) 2591839Swollman#define RPCTEST_NULL_PROC ((u_long)2) 2601839Swollman#define RPCTEST_NULL_BATCH_PROC ((u_long)3) 2611839Swollman 2621839Swollman/* 2631839Swollman * By convention, procedure 0 takes null arguments and returns them 2641839Swollman */ 2651839Swollman 2661839Swollman#define NULLPROC ((u_long)0) 2671839Swollman 2681839Swollman/* 2691839Swollman * Below are the client handle creation routines for the various 2708858Srgrimes * implementations of client side rpc. They can return NULL if a 2711839Swollman * creation failure occurs. 2721839Swollman */ 2731839Swollman 2741839Swollman/* 2751839Swollman * Memory based rpc (for speed check and testing) 2761839Swollman * CLIENT * 2771839Swollman * clntraw_create(prog, vers) 2781839Swollman * u_long prog; 2791839Swollman * u_long vers; 2801839Swollman */ 2811903Swollman__BEGIN_DECLS 2821903Swollmanextern CLIENT *clntraw_create __P((u_long, u_long)); 2831903Swollman__END_DECLS 2841839Swollman 2851839Swollman 2861839Swollman/* 28726211Swpaul * Generic client creation routine. Supported protocols are "udp", "tcp" 28826211Swpaul * and "unix". 2891903Swollman * CLIENT * 2901903Swollman * clnt_create(host, prog, vers, prot); 2911903Swollman * char *host; -- hostname 2921903Swollman * u_long prog; -- program number 2931903Swollman * u_long vers; -- version number 2941903Swollman * char *prot; -- protocol 2951839Swollman */ 2961903Swollman__BEGIN_DECLS 2971903Swollmanextern CLIENT *clnt_create __P((char *, u_long, u_long, char *)); 2981903Swollman__END_DECLS 2991839Swollman 3001839Swollman 3011839Swollman/* 3021839Swollman * TCP based rpc 3031839Swollman * CLIENT * 3041839Swollman * clnttcp_create(raddr, prog, vers, sockp, sendsz, recvsz) 3051839Swollman * struct sockaddr_in *raddr; 3061839Swollman * u_long prog; 3071839Swollman * u_long version; 3081839Swollman * register int *sockp; 3091839Swollman * u_int sendsz; 3101839Swollman * u_int recvsz; 3111839Swollman */ 3121903Swollman__BEGIN_DECLS 3131903Swollmanextern CLIENT *clnttcp_create __P((struct sockaddr_in *, 3141903Swollman u_long, 3151903Swollman u_long, 3161903Swollman int *, 3171903Swollman u_int, 3181903Swollman u_int)); 3191903Swollman__END_DECLS 3201839Swollman 3211903Swollman 3221839Swollman/* 3231839Swollman * UDP based rpc. 3241839Swollman * CLIENT * 3251839Swollman * clntudp_create(raddr, program, version, wait, sockp) 3261839Swollman * struct sockaddr_in *raddr; 3271839Swollman * u_long program; 3281839Swollman * u_long version; 3291839Swollman * struct timeval wait; 3301839Swollman * int *sockp; 3311839Swollman * 3321839Swollman * Same as above, but you specify max packet sizes. 3331839Swollman * CLIENT * 3341839Swollman * clntudp_bufcreate(raddr, program, version, wait, sockp, sendsz, recvsz) 3351839Swollman * struct sockaddr_in *raddr; 3361839Swollman * u_long program; 3371839Swollman * u_long version; 3381839Swollman * struct timeval wait; 3391839Swollman * int *sockp; 3401839Swollman * u_int sendsz; 3411839Swollman * u_int recvsz; 3421839Swollman */ 3431903Swollman__BEGIN_DECLS 3441903Swollmanextern CLIENT *clntudp_create __P((struct sockaddr_in *, 3451903Swollman u_long, 3461903Swollman u_long, 3471903Swollman struct timeval, 3481903Swollman int *)); 3491903Swollmanextern CLIENT *clntudp_bufcreate __P((struct sockaddr_in *, 3501903Swollman u_long, 3511903Swollman u_long, 3521903Swollman struct timeval, 3531903Swollman int *, 3541903Swollman u_int, 3551903Swollman u_int)); 3561903Swollman__END_DECLS 3571839Swollman 3581903Swollman 3591839Swollman/* 36026211Swpaul * AF_UNIX based rpc 36126211Swpaul * CLIENT * 36226211Swpaul * clntunix_create(raddr, prog, vers, sockp, sendsz, recvsz) 36326211Swpaul * struct sockaddr_un *raddr; 36426211Swpaul * u_long prog; 36526211Swpaul * u_long version; 36626211Swpaul * register int *sockp; 36726211Swpaul * u_int sendsz; 36826211Swpaul * u_int recvsz; 36926211Swpaul */ 37026211Swpaul__BEGIN_DECLS 37126211Swpaulextern CLIENT *clntunix_create __P((struct sockaddr_un *, 37226211Swpaul u_long, 37326211Swpaul u_long, 37426211Swpaul int *, 37526211Swpaul u_int, 37626211Swpaul u_int)); 37726211Swpaul__END_DECLS 37826211Swpaul 37926211Swpaul 38026211Swpaul/* 3811839Swollman * Print why creation failed 3821839Swollman */ 3831903Swollman__BEGIN_DECLS 3841903Swollmanextern void clnt_pcreateerror __P((char *)); /* stderr */ 3851903Swollmanextern char *clnt_spcreateerror __P((char *)); /* string */ 3861903Swollman__END_DECLS 3871839Swollman 3881839Swollman/* 3891839Swollman * Like clnt_perror(), but is more verbose in its output 3908858Srgrimes */ 3911903Swollman__BEGIN_DECLS 3921903Swollmanextern void clnt_perrno __P((enum clnt_stat)); /* stderr */ 3931903Swollmanextern char *clnt_sperrno __P((enum clnt_stat)); /* string */ 3941903Swollman__END_DECLS 3951839Swollman 3961839Swollman/* 3971839Swollman * Print an English error message, given the client error code 3981839Swollman */ 3991903Swollman__BEGIN_DECLS 4001903Swollmanextern void clnt_perror __P((CLIENT *, char *)); /* stderr */ 4011903Swollmanextern char *clnt_sperror __P((CLIENT *, char *)); /* string */ 4021903Swollman__END_DECLS 4031839Swollman 4041903Swollman 4058858Srgrimes/* 4061839Swollman * If a creation fails, the following allows the user to figure out why. 4071839Swollman */ 4081839Swollmanstruct rpc_createerr { 4091839Swollman enum clnt_stat cf_stat; 4101839Swollman struct rpc_err cf_error; /* useful when cf_stat == RPC_PMAPFAILURE */ 4111839Swollman}; 4121839Swollman 4131839Swollmanextern struct rpc_createerr rpc_createerr; 4141839Swollman 4151839Swollman 4161839Swollman#define UDPMSGSIZE 8800 /* rpc imposed limit on udp msg size */ 4171839Swollman#define RPCSMALLMSGSIZE 400 /* a more reasonable packet size */ 4181839Swollman 4191903Swollman#endif /* !_RPC_CLNT_H */ 420