#define _RPC_AUTH_H 1
#include <features.h>
+#include <rpc/xdr.h>
__BEGIN_DECLS
char c[8];
};
typedef union des_block des_block;
-extern bool_t xdr_des_block();
+extern bool_t xdr_des_block __P ((XDR *__xdrs, des_block *__blkp));
/*
* Authentication info. Opaque to client.
/*
* Auth handle, interface to client side authenticators.
*/
-typedef struct {
- struct opaque_auth ah_cred;
- struct opaque_auth ah_verf;
- union des_block ah_key;
- struct auth_ops {
- void (*ah_nextverf)();
- int (*ah_marshal)(); /* nextverf & serialize */
- int (*ah_validate)(); /* validate verifier */
- int (*ah_refresh)(); /* refresh credentials */
- void (*ah_destroy)(); /* destroy this structure */
- } *ah_ops;
- caddr_t ah_private;
-} AUTH;
+typedef struct AUTH AUTH;
+struct AUTH {
+ struct opaque_auth ah_cred;
+ struct opaque_auth ah_verf;
+ union des_block ah_key;
+ struct auth_ops {
+ void (*ah_nextverf) __P ((AUTH *));
+ int (*ah_marshal) __P ((AUTH *, XDR *)); /* nextverf & serialize */
+ int (*ah_validate) __P ((AUTH *, struct opaque_auth *));
+ /* validate verifier */
+ int (*ah_refresh) __P ((AUTH *)); /* refresh credentials */
+ void (*ah_destroy) __P ((AUTH *)); /* destroy this structure */
+ } *ah_ops;
+ caddr_t ah_private;
+};
/*
__gid_t *__aup_gids));
extern AUTH *authunix_create_default __P ((void));
extern AUTH *authnone_create __P ((void));
-extern AUTH *authdes_create();
+extern AUTH *authdes_create __P ((char *__servername, u_int __window,
+ struct sockaddr *__syncaddr,
+ des_block *__ckey));
#define AUTH_NONE 0 /* no authentication */
#define AUTH_NULL 0 /* backward compatibility */
-#define AUTH_UNIX 1 /* unix style (uid, gids) */
#define AUTH_SYS 1 /* unix style (uid, gids) */
+#define AUTH_UNIX AUTH_SYS
#define AUTH_SHORT 2 /* short hand unix style */
#define AUTH_DES 3 /* des style (encrypted timestamps) */
+#define AUTH_KERB 4 /* kerberos style */
__END_DECLS
RPC_PROCUNAVAIL=10, /* procedure unavailable */
RPC_CANTDECODEARGS=11, /* decode arguments error */
RPC_SYSTEMERROR=12, /* generic "other problem" */
-
+ RPC_NOBROADCAST = 21, /* Broadcasting not supported */
/*
* callrpc & clnt_create errors
*/
RPC_UNKNOWNHOST=13, /* unknown host name */
RPC_UNKNOWNPROTO=17, /* unknown protocol */
+ RPC_UNKNOWNADDR = 19, /* Remote address unknown */
/*
- * _ create errors
+ * rpcbind errors
*/
- RPC_PMAPFAILURE=14, /* the pmapper failed in its call */
+ RPC_RPCBFAILURE=14, /* portmapper failed in its call */
+#define RPC_PMAPFAILURE RPC_RPCBFAILURE
RPC_PROGNOTREGISTERED=15, /* remote program is not registered */
+ RPC_N2AXLATEFAILURE = 22, /* Name to addr translation failed */
/*
* unspecified error
*/
- RPC_FAILED=16
+ RPC_FAILED=16,
+ RPC_INTR=18,
+ RPC_TLIERROR=20,
+ RPC_UDERROR=23,
+ /*
+ * asynchronous errors
+ */
+ RPC_INPROGRESS = 24,
+ RPC_STALERACHANDLE = 25
};
* Error info.
*/
struct rpc_err {
- enum clnt_stat re_status;
- union {
- int RE_errno; /* related system error */
- enum auth_stat RE_why; /* why the auth error occurred */
- struct {
- u_long low; /* lowest verion supported */
- u_long high; /* highest verion supported */
- } RE_vers;
- struct { /* maybe meaningful if RPC_FAILED */
- long s1;
- long s2;
- } RE_lb; /* life boot & debugging only */
- } ru;
+ enum clnt_stat re_status;
+ union {
+ int RE_errno; /* related system error */
+ enum auth_stat RE_why; /* why the auth error occurred */
+ struct {
+ u_long low; /* lowest verion supported */
+ u_long high; /* highest verion supported */
+ } RE_vers;
+ struct { /* maybe meaningful if RPC_FAILED */
+ long s1;
+ long s2;
+ } RE_lb; /* life boot & debugging only */
+ } ru;
#define re_errno ru.RE_errno
#define re_why ru.RE_why
#define re_vers ru.RE_vers
* Created by individual implementations, see e.g. rpc_udp.c.
* Client is responsible for initializing auth, see e.g. auth_none.c.
*/
-typedef struct {
- AUTH *cl_auth; /* authenticator */
- struct clnt_ops {
- enum clnt_stat (*cl_call)(); /* call remote procedure */
- void (*cl_abort)(); /* abort a call */
- void (*cl_geterr)(); /* get specific error code */
- bool_t (*cl_freeres)(); /* frees results */
- void (*cl_destroy)();/* destroy this structure */
- bool_t (*cl_control)();/* the ioctl() of rpc */
- } *cl_ops;
- caddr_t cl_private; /* private stuff */
-} CLIENT;
+typedef struct CLIENT CLIENT;
+struct CLIENT {
+ AUTH *cl_auth; /* authenticator */
+ struct clnt_ops {
+ enum clnt_stat (*cl_call) __P ((CLIENT *, u_long, xdrproc_t,
+ caddr_t, xdrproc_t,
+ caddr_t, struct timeval));
+ /* call remote procedure */
+ void (*cl_abort) __P ((void)); /* abort a call */
+ void (*cl_geterr) __P ((CLIENT *, struct rpc_err *));
+ /* get specific error code */
+ bool_t (*cl_freeres) __P ((CLIENT *, xdrproc_t, caddr_t));
+ /* frees results */
+ void (*cl_destroy) __P ((CLIENT *)); /* destroy this structure */
+ bool_t (*cl_control) __P ((CLIENT *, int, char *));
+ /* the ioctl() of rpc */
+ } *cl_ops;
+ caddr_t cl_private; /* private stuff */
+};
/*
#define clnt_control(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
/*
- * control operations that apply to both udp and tcp transports
+ * control operations that apply to all transports
*/
-#define CLSET_TIMEOUT 1 /* set timeout (timeval) */
-#define CLGET_TIMEOUT 2 /* get timeout (timeval) */
-#define CLGET_SERVER_ADDR 3 /* get server's address (sockaddr) */
+#define CLSET_TIMEOUT 1 /* set timeout (timeval) */
+#define CLGET_TIMEOUT 2 /* get timeout (timeval) */
+#define CLGET_SERVER_ADDR 3 /* get server's address (sockaddr) */
+#define CLGET_FD 6 /* get connections file descriptor */
+#define CLGET_SVC_ADDR 7 /* get server's address (netbuf) */
+#define CLSET_FD_CLOSE 8 /* close fd while clnt_destroy */
+#define CLSET_FD_NCLOSE 9 /* Do not close fd while clnt_destroy*/
+#define CLGET_XID 10 /* Get xid */
+#define CLSET_XID 11 /* Set xid */
+#define CLGET_VERS 12 /* Get version number */
+#define CLSET_VERS 13 /* Set version number */
+#define CLGET_PROG 14 /* Get program number */
+#define CLSET_PROG 15 /* Set program number */
+#define CLSET_SVC_ADDR 16 /* get server's address (netbuf) */
+#define CLSET_PUSH_TIMOD 17 /* push timod if not already present */
+#define CLSET_POP_TIMOD 18 /* pop timod */
/*
- * udp only control operations
+ * Connectionless only control operations
*/
-#define CLSET_RETRY_TIMEOUT 4 /* set retry timeout (timeval) */
-#define CLGET_RETRY_TIMEOUT 5 /* get retry timeout (timeval) */
+#define CLSET_RETRY_TIMEOUT 4 /* set retry timeout (timeval) */
+#define CLGET_RETRY_TIMEOUT 5 /* get retry timeout (timeval) */
/*
* void
* u_long prog;
* u_long vers;
*/
-extern CLIENT *clntraw_create __P ((u_long __prog, u_long __vers));
+extern CLIENT *clntraw_create __P ((__const u_long __prog,
+ __const u_long __vers));
/*
* CLIENT *
* clnt_create(host, prog, vers, prot)
* char *host; -- hostname
- * u_int prog; -- program number
- * u_int vers; -- version number
+ * u_long prog; -- program number
+ * u_ong vers; -- version number
* char *prot; -- protocol
*/
-extern CLIENT *clnt_create __P ((char *__host, u_int __prog, u_int __vers,
- char *__prot));
+extern CLIENT *clnt_create __P ((__const char *__host, __const u_long __prog,
+ __const u_long __vers, __const char *__prot));
/*
int *__sockp, u_int __sendsz,
u_int __recvsz));
+extern int callrpc __P ((__const char *__host, __const u_long __prognum,
+ __const u_long __versnum, __const u_long __procnum,
+ __const xdrproc_t __inproc, __const char *__in,
+ __const xdrproc_t __outproc, char *__out));
+extern int _rpc_dtablesize __P ((void));
+
/*
* Print why creation failed
*/
-extern void clnt_pcreateerror __P ((char *__msg)); /* stderr */
-extern char *clnt_spcreateerror __P ((char *__msg)); /* string */
+extern void clnt_pcreateerror __P ((__const char *__msg)); /* stderr */
+extern char *clnt_spcreateerror __P ((__const char *__msg)); /* string */
/*
* Like clnt_perror(), but is more verbose in its output
/*
* Print an English error message, given the client error code
*/
-extern void clnt_perror __P ((CLIENT *__clnt, char *__msg)); /* stderr */
-extern char *clnt_sperror __P ((CLIENT *__clnt, char *__msg)); /* string */
+extern void clnt_perror __P ((CLIENT *__clnt, __const char *__msg));
+ /* stderr */
+extern char *clnt_sperror __P ((CLIENT *__clnt, __const char *__msg));
+ /* string */
/*
* If a creation fails, the following allows the user to figure out why.
*/
extern char *clnt_sperrno __P ((enum clnt_stat __num)); /* string */
-
+extern int getrpcport __P ((__const char * __host, u_long __prognum,
+ u_long __versnum, u_int proto));
#define UDPMSGSIZE 8800 /* rpc imposed limit on udp msg size */
#define RPCSMALLMSGSIZE 400 /* a more reasonable packet size */
__BEGIN_DECLS
-typedef bool_t (*resultproc_t)();
+typedef bool_t (*resultproc_t) __P ((caddr_t resp, struct sockaddr_in *raddr));
/*
* Usage:
* address if the responder to the broadcast.
*/
-extern bool_t pmap_set __P ((u_long __program, u_long __version,
+extern bool_t pmap_set __P ((__const u_long __program, __const u_long __vers,
int __protocol, u_short __port));
-
-extern bool_t pmap_unset __P ((u_long __program, u_long __version));
-
+extern bool_t pmap_unset __P ((__const u_long __program, __const u_long __vers));
extern struct pmaplist *pmap_getmaps __P ((struct sockaddr_in *__address));
-
extern enum clnt_stat pmap_rmtcall __P ((struct sockaddr_in *__addr,
- u_long __prog, u_long __vers,
- u_long __proc, xdrproc_t __xdrargs,
+ __const u_long __prog,
+ __const u_long __vers,
+ __const u_long __proc,
+ xdrproc_t __xdrargs,
caddr_t __argsp, xdrproc_t __xdrres,
caddr_t __resp, struct timeval __tout,
u_long *__port_ptr));
-
-extern enum clnt_stat clnt_broadcast __P ((u_long __prog, u_long __vers,
- u_long __proc, xdrproc_t __xargs,
+extern enum clnt_stat clnt_broadcast __P ((__const u_long __prog,
+ __const u_long __vers,
+ __const u_long __proc,
+ xdrproc_t __xargs,
caddr_t __argsp,
xdrproc_t __xresults,
caddr_t __resultsp,
resultproc_t __eachresult));
-
extern u_short pmap_getport __P ((struct sockaddr_in *__address,
- u_long __program, u_long __version,
+ __const u_long __program,
+ __const u_long __version,
u_int __protocol));
__END_DECLS
#ifndef __SVC_HEADER__
#define __SVC_HEADER__
+#include <features.h>
+#include <rpc/rpc_msg.h>
+
__BEGIN_DECLS
/*
/*
* Server side transport handle
*/
-typedef struct {
- int xp_sock;
- u_short xp_port; /* associated port number */
- struct xp_ops {
- bool_t (*xp_recv)(); /* receive incoming requests */
- enum xprt_stat (*xp_stat)(); /* get transport status */
- bool_t (*xp_getargs)(); /* get arguments */
- bool_t (*xp_reply)(); /* send reply */
- bool_t (*xp_freeargs)();/* free mem allocated for args */
- void (*xp_destroy)(); /* destroy this struct */
- } *xp_ops;
- int xp_addrlen; /* length of remote address */
- struct sockaddr_in xp_raddr; /* remote address */
- struct opaque_auth xp_verf; /* raw response verifier */
- caddr_t xp_p1; /* private */
- caddr_t xp_p2; /* private */
-} SVCXPRT;
+typedef struct SVCXPRT SVCXPRT;
+struct SVCXPRT {
+ int xp_sock;
+ u_short xp_port; /* associated port number */
+ const struct xp_ops {
+ bool_t (*xp_recv) __P ((SVCXPRT *__xprt, struct rpc_msg *__msg));
+ /* receive incoming requests */
+ enum xprt_stat (*xp_stat) __P ((SVCXPRT *__xprt));
+ /* get transport status */
+ bool_t (*xp_getargs) __P ((SVCXPRT *__xprt, xdrproc_t __xdr_args,
+ caddr_t args_ptr)); /* get arguments */
+ bool_t (*xp_reply) __P ((SVCXPRT *__xprt, struct rpc_msg *__msg));
+ /* send reply */
+ bool_t (*xp_freeargs) __P ((SVCXPRT *__xprt, xdrproc_t __xdr_args,
+ caddr_t args_ptr));
+ /* free mem allocated for args */
+ void (*xp_destroy) __P ((SVCXPRT *__xprt));
+ /* destroy this struct */
+ } *xp_ops;
+ int xp_addrlen; /* length of remote address */
+ struct sockaddr_in xp_raddr; /* remote address */
+ struct opaque_auth xp_verf; /* raw response verifier */
+ caddr_t xp_p1; /* private */
+ caddr_t xp_p2; /* private */
+};
/*
* Approved way of getting address of caller
* u_long prog;
* u_long vers;
* void (*dispatch)();
- * int protocol; like TCP or UDP, zero means do not register
+ * u_long protocol; like TCP or UDP, zero means do not register
*/
extern bool_t svc_register __P ((SVCXPRT *__xprt, u_long __prog,
- u_long __vers, void (*__dispatch) (),
- int __protocol));
+ u_long __vers, void (*__dispatch)
+ __P ((struct svc_req *, SVCXPRT *)),
+ u_long __protocol));
/*
* Service un-registration
* a small program implemented by the svc_rpc implementation itself;
* also see clnt.h for protocol numbers.
*/
-extern void rpctest_service();
-
extern void svc_getreq __P ((int __rdfds));
extern void svc_getreqset __P ((fd_set *readfds));
-extern void svc_run __P ((void)) __attribute__ ((noreturn));
+extern void svc_run __P ((void)); /* __attribute__ ((noreturn)) */
/*
* Socket to use on svcxxx_create call to get default socket
#define _RPC_SVC_AUTH_H 1
#include <features.h>
+#include <rpc/svc.h>
__BEGIN_DECLS
#ifndef __TYPES_RPC_HEADER__
#define __TYPES_RPC_HEADER__
-#define bool_t int
-#define enum_t int
-#define FALSE (0)
-#define TRUE (1)
-#define __dontcare__ -1
+typedef int bool_t;
+typedef int enum_t;
+
+#define __dontcare__ -1
+
+#ifndef FALSE
+# define FALSE (0)
+#endif
+
+#ifndef TRUE
+# define TRUE (1)
+#endif
+
#ifndef NULL
-# define NULL 0
+# define NULL 0
#endif
#include <stdlib.h> /* For malloc decl. */
*
* Each data type provides a single procedure which takes two arguments:
*
- * bool_t
- * xdrproc(xdrs, argresp)
- * XDR *xdrs;
- * <type> *argresp;
+ * bool_t
+ * xdrproc(xdrs, argresp)
+ * XDR *xdrs;
+ * <type> *argresp;
*
* xdrs is an instance of a XDR handle, to which or from which the data
* type is to be converted. argresp is a pointer to the structure to be
* XDR_FREE can be used to release the space allocated by an XDR_DECODE
* request.
*/
-enum xdr_op {
- XDR_ENCODE=0,
- XDR_DECODE=1,
- XDR_FREE=2
-};
+enum xdr_op
+ {
+ XDR_ENCODE = 0,
+ XDR_DECODE = 1,
+ XDR_FREE = 2
+ };
/*
* This is the number of bytes per unit of external data.
* an operations vector for the particular implementation (e.g. see xdr_mem.c),
* and two private fields for the use of the particular implementation.
*/
-typedef struct {
- enum xdr_op x_op; /* operation; fast additional param */
- struct xdr_ops {
- bool_t (*x_getlong)(); /* get a long from underlying stream */
- bool_t (*x_putlong)(); /* put a long to " */
- bool_t (*x_getbytes)();/* get some bytes from " */
- bool_t (*x_putbytes)();/* put some bytes to " */
- u_int (*x_getpostn)();/* returns bytes off from beginning */
- bool_t (*x_setpostn)();/* lets you reposition the stream */
- long * (*x_inline)(); /* buf quick ptr to buffered data */
- void (*x_destroy)(); /* free privates of this xdr_stream */
- } *x_ops;
- caddr_t x_public; /* users' data */
- caddr_t x_private; /* pointer to private data */
- caddr_t x_base; /* private used for position info */
- int x_handy; /* extra private word */
-} XDR;
+typedef struct XDR XDR;
+struct XDR
+ {
+ enum xdr_op x_op; /* operation; fast additional param */
+ const struct xdr_ops
+ {
+ bool_t (*x_getlong) __P ((XDR * __xdrs, long *__lp));
+ /* get a long from underlying stream */
+ bool_t (*x_putlong) __P ((XDR * __xdrs, long *__lp));
+ /* put a long to " */
+ bool_t (*x_getbytes) __P ((XDR * __xdrs, caddr_t __addr, u_int __len));
+ /* get some bytes from " */
+ bool_t (*x_putbytes) __P ((XDR * __xdrs, __const caddr_t __addr,
+ u_int __len));
+ /* put some bytes to " */
+ u_int (*x_getpostn) __P ((XDR * __xdrs));
+ /* returns bytes off from beginning */
+ bool_t (*x_setpostn) __P ((XDR * __xdrs, u_int pos));
+ /* lets you reposition the stream */
+ long *(*x_inline) __P ((XDR * __xdrs, int len));
+ /* buf quick ptr to buffered data */
+ void (*x_destroy) __P ((XDR * __xdrs));
+ /* free privates of this xdr_stream */
+ }
+ *x_ops;
+ caddr_t x_public; /* users' data */
+ caddr_t x_private; /* pointer to private data */
+ caddr_t x_base; /* private used for position info */
+ int x_handy; /* extra private word */
+ };
/*
* A xdrproc_t exists for each data type which is to be encoded or decoded.
* The opaque pointer generally points to a structure of the data type
* to be decoded. If this pointer is 0, then the type routines should
* allocate dynamic storage of the appropriate size and return it.
- * bool_t (*xdrproc_t)(XDR *, caddr_t *);
+ * bool_t (*xdrproc_t)(XDR *, caddr_t *);
*/
-typedef bool_t (*xdrproc_t) __P ((XDR *, void *, ...));
+typedef
+bool_t (*xdrproc_t) __P ((XDR *, void *,...));
/*
* Operations defined on a XDR handle
*
- * XDR *xdrs;
- * long *longp;
- * caddr_t addr;
- * u_int len;
- * u_int pos;
+ * XDR *xdrs;
+ * long *longp;
+ * caddr_t addr;
+ * u_int len;
+ * u_int pos;
*/
#define XDR_GETLONG(xdrs, longp) \
(*(xdrs)->x_ops->x_getlong)(xdrs, longp)
* If there is no match and no default routine it is an error.
*/
#define NULL_xdrproc_t ((xdrproc_t)0)
-struct xdr_discrim {
- int value;
- xdrproc_t proc;
+struct xdr_discrim
+{
+ int value;
+ xdrproc_t proc;
};
/*
* data from the underlying buffer, and will fail to operate
* properly if the data is not aligned. The standard way to use these
* is to say:
- * if ((buf = XDR_INLINE(xdrs, count)) == NULL)
- * return (FALSE);
- * <<< macro calls >>>
+ * if ((buf = XDR_INLINE(xdrs, count)) == NULL)
+ * return (FALSE);
+ * <<< macro calls >>>
* where ``count'' is the number of bytes of data occupied
* by the primitive data types.
*
/*
* These are the "generic" xdr routines.
*/
-extern bool_t xdr_void ();
-extern bool_t xdr_int __P ((XDR *__xdrs, int *__ip));
-extern bool_t xdr_u_int __P ((XDR *__xdrs, u_int *__up));
-extern bool_t xdr_long __P ((XDR *__xdrs, long *__lp));
-extern bool_t xdr_u_long __P ((XDR *__xdrs, u_long *__ulp));
-extern bool_t xdr_short __P ((XDR *__xdrs, short *__sp));
-extern bool_t xdr_u_short __P ((XDR *__xdrs, u_short *__usp));
-extern bool_t xdr_bool __P ((XDR *__xdrs, bool_t *__bp));
-extern bool_t xdr_enum __P ((XDR *__xdrs, enum_t *__ep));
-extern bool_t xdr_array __P ((XDR *_xdrs, caddr_t *__addrp, u_int *__sizep,
- u_int __maxsize, u_int __elsize,
- xdrproc_t __elproc));
-extern bool_t xdr_bytes __P ((XDR *__xdrs, char **__cpp, u_int *__sizep,
- u_int __maxsize));
-extern bool_t xdr_opaque __P ((XDR *__xdrs, caddr_t __cp, u_int __cnt));
-extern bool_t xdr_string __P ((XDR *__xdrs, char **__cpp, u_int __maxsize));
-extern bool_t xdr_union __P ((XDR *__xdrs, enum_t *__dscmp, char *__unp,
- struct xdr_discrim *__choices,
- xdrproc_t dfault));
-extern bool_t xdr_char __P ((XDR *__xdrs, char *__cp));
-extern bool_t xdr_u_char __P ((XDR *__xdrs, u_char *__cp));
-extern bool_t xdr_vector __P ((XDR *__xdrs, char *__basep, u_int __nelem,
- u_int __elemsize, xdrproc_t __xdr_elem));
-extern bool_t xdr_float __P ((XDR *__xdrs, float *__fp));
-extern bool_t xdr_double __P ((XDR *__xdrs, double *__dp));
-extern bool_t xdr_reference __P ((XDR *__xdrs, caddr_t *__pp, u_int __size,
- xdrproc_t __proc));
-extern bool_t xdr_pointer __P ((XDR *__xdrs, char **__objpp,
- u_int __obj_size, xdrproc_t __xdr_obj));
-extern bool_t xdr_wrapstring __P ((XDR *__xdrs, char **__cpp));
+extern bool_t xdr_void __P ((void));
+extern bool_t xdr_int __P ((XDR * __xdrs, int *__ip));
+extern bool_t xdr_u_int __P ((XDR * __xdrs, u_int * __up));
+extern bool_t xdr_long __P ((XDR * __xdrs, long *__lp));
+extern bool_t xdr_u_long __P ((XDR * __xdrs, u_long * __ulp));
+extern bool_t xdr_short __P ((XDR * __xdrs, short *__sp));
+extern bool_t xdr_u_short __P ((XDR * __xdrs, u_short * __usp));
+extern bool_t xdr_bool __P ((XDR * __xdrs, bool_t * __bp));
+extern bool_t xdr_enum __P ((XDR * __xdrs, enum_t * __ep));
+extern bool_t xdr_array __P ((XDR * _xdrs, caddr_t * __addrp, u_int * __sizep,
+ u_int __maxsize, u_int __elsize,
+ xdrproc_t __elproc));
+extern bool_t xdr_bytes __P ((XDR * __xdrs, char **__cpp, u_int * __sizep,
+ u_int __maxsize));
+extern bool_t xdr_opaque __P ((XDR * __xdrs, caddr_t __cp, u_int __cnt));
+extern bool_t xdr_string __P ((XDR * __xdrs, char **__cpp, u_int __maxsize));
+extern bool_t xdr_union __P ((XDR * __xdrs, enum_t * __dscmp, char *__unp,
+ __const struct xdr_discrim * __choices,
+ xdrproc_t dfault));
+extern bool_t xdr_char __P ((XDR * __xdrs, char *__cp));
+extern bool_t xdr_u_char __P ((XDR * __xdrs, u_char * __cp));
+extern bool_t xdr_vector __P ((XDR * __xdrs, char *__basep, u_int __nelem,
+ u_int __elemsize, xdrproc_t __xdr_elem));
+extern bool_t xdr_float __P ((XDR * __xdrs, float *__fp));
+extern bool_t xdr_double __P ((XDR * __xdrs, double *__dp));
+extern bool_t xdr_reference __P ((XDR * __xdrs, caddr_t * __pp, u_int __size,
+ xdrproc_t __proc));
+extern bool_t xdr_pointer __P ((XDR * __xdrs, char **__objpp,
+ u_int __obj_size, xdrproc_t __xdr_obj));
+extern bool_t xdr_wrapstring __P ((XDR * __xdrs, char **__cpp));
/*
* Common opaque bytes objects used by many rpc protocols;
* declared here due to commonality.
*/
#define MAX_NETOBJ_SZ 1024
-struct netobj {
- u_int n_len;
- char *n_bytes;
+struct netobj
+{
+ u_int n_len;
+ char *n_bytes;
};
typedef struct netobj netobj;
-extern bool_t xdr_netobj __P ((XDR *__xdrs, struct netobj *__np));
+extern bool_t xdr_netobj __P ((XDR * __xdrs, struct netobj * __np));
/*
* These are the public routines for the various implementations of
*/
/* XDR using memory buffers */
-extern void xdrmem_create __P ((XDR *__xdrs, caddr_t __addr, u_int __size,
- enum xdr_op __op));
+extern void xdrmem_create __P ((XDR * __xdrs, caddr_t __addr, u_int __size,
+ enum xdr_op __op));
/* XDR using stdio library */
-extern void xdrstdio_create __P ((XDR *__xdrs, FILE *__file,
- enum xdr_op __op));
+extern void xdrstdio_create __P ((XDR * __xdrs, FILE * __file,
+ enum xdr_op __op));
/* XDR pseudo records for tcp */
-extern void xdrrec_create __P ((XDR *__xdrs, u_int __sendsize,
- u_int __recvsize, caddr_t __tcp_handle,
- int (*__readit) (), int (*__writeit) ()));
+extern void xdrrec_create __P ((XDR * __xdrs, u_int __sendsize,
+ u_int __recvsize, caddr_t __tcp_handle,
+ int (*__readit) (char *, char *, int),
+ int (*__writeit) (char *, char *, int)));
/* make end of xdr record */
-extern bool_t xdrrec_endofrecord __P ((XDR *__xdrs, bool_t __sendnow));
+extern bool_t xdrrec_endofrecord __P ((XDR * __xdrs, bool_t __sendnow));
/* move to beginning of next record */
-extern bool_t xdrrec_skiprecord __P ((XDR *__xdrs));
+extern bool_t xdrrec_skiprecord __P ((XDR * __xdrs));
/* true if no more input */
-extern bool_t xdrrec_eof __P ((XDR *__xdrs));
+extern bool_t xdrrec_eof __P ((XDR * __xdrs));
/* free memory buffers for xdr */
extern void xdr_free __P ((xdrproc_t __proc, char *__objp));
*/
#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
#include <rpc/rpc.h>
#include <sys/socket.h>
#include <errno.h>
#define rpc_buffer(xprt) ((xprt)->xp_p1)
#ifndef MAX
-# define MAX(a, b) ((a > b) ? a : b)
+#define MAX(a, b) ((a > b) ? a : b)
#endif
-static bool_t svcudp_recv();
-static bool_t svcudp_reply();
-static enum xprt_stat svcudp_stat();
-static bool_t svcudp_getargs();
-static bool_t svcudp_freeargs();
-static void svcudp_destroy();
-
-static struct xp_ops svcudp_op = {
- svcudp_recv,
- svcudp_stat,
- svcudp_getargs,
- svcudp_reply,
- svcudp_freeargs,
- svcudp_destroy
+static bool_t svcudp_recv (SVCXPRT *, struct rpc_msg *);
+static bool_t svcudp_reply (SVCXPRT *, struct rpc_msg *);
+static enum xprt_stat svcudp_stat (SVCXPRT *);
+static bool_t svcudp_getargs (SVCXPRT *, xdrproc_t, caddr_t);
+static bool_t svcudp_freeargs (SVCXPRT *, xdrproc_t, caddr_t);
+static void svcudp_destroy (SVCXPRT *);
+
+static const struct xp_ops svcudp_op =
+{
+ svcudp_recv,
+ svcudp_stat,
+ svcudp_getargs,
+ svcudp_reply,
+ svcudp_freeargs,
+ svcudp_destroy
};
-#ifndef errno
-extern int errno;
-#endif
+static int cache_get (SVCXPRT *, struct rpc_msg *, char **replyp,
+ u_long *replylenp);
+static void cache_set (SVCXPRT *xprt, u_long replylen);
/*
* kept in xprt->xp_p2
*/
-struct svcudp_data {
- u_int su_iosz; /* byte size of send.recv buffer */
- u_long su_xid; /* transaction id */
- XDR su_xdrs; /* XDR handle */
- char su_verfbody[MAX_AUTH_BYTES]; /* verifier body */
- char * su_cache; /* cached data, NULL if no cache */
-};
+struct svcudp_data
+ {
+ u_int su_iosz; /* byte size of send.recv buffer */
+ u_long su_xid; /* transaction id */
+ XDR su_xdrs; /* XDR handle */
+ char su_verfbody[MAX_AUTH_BYTES]; /* verifier body */
+ char *su_cache; /* cached data, NULL if no cache */
+ };
#define su_data(xprt) ((struct svcudp_data *)(xprt->xp_p2))
/*
* Usage:
- * xprt = svcudp_create(sock);
+ * xprt = svcudp_create(sock);
*
* If sock<0 then a socket is created, else sock is used.
* If the socket, sock is not bound to a port then svcudp_create
* The routines returns NULL if a problem occurred.
*/
SVCXPRT *
-svcudp_bufcreate(sock, sendsz, recvsz)
- register int sock;
- u_int sendsz, recvsz;
+svcudp_bufcreate (sock, sendsz, recvsz)
+ int sock;
+ u_int sendsz, recvsz;
{
- bool_t madesock = FALSE;
- register SVCXPRT *xprt;
- register struct svcudp_data *su;
- struct sockaddr_in addr;
- int len = sizeof(struct sockaddr_in);
-
- if (sock == RPC_ANYSOCK) {
- if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
- perror(_("svcudp_create: socket creation problem"));
- return ((SVCXPRT *)NULL);
- }
- madesock = TRUE;
- }
- bzero((char *)&addr, sizeof (addr));
- addr.sin_family = AF_INET;
- if (bindresvport(sock, &addr)) {
- addr.sin_port = 0;
- (void)bind(sock, (struct sockaddr *)&addr, len);
+ bool_t madesock = FALSE;
+ SVCXPRT *xprt;
+ struct svcudp_data *su;
+ struct sockaddr_in addr;
+ int len = sizeof (struct sockaddr_in);
+
+ if (sock == RPC_ANYSOCK)
+ {
+ if ((sock = socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
+ {
+ perror (_("svcudp_create: socket creation problem"));
+ return (SVCXPRT *) NULL;
}
- if (getsockname(sock, (struct sockaddr *)&addr, &len) != 0) {
- perror(_("svcudp_create - cannot getsockname"));
- if (madesock)
- (void)close(sock);
- return ((SVCXPRT *)NULL);
- }
- xprt = (SVCXPRT *)mem_alloc(sizeof(SVCXPRT));
- if (xprt == NULL) {
- (void)fprintf(stderr, "svcudp_create: out of memory\n");
- return (NULL);
- }
- su = (struct svcudp_data *)mem_alloc(sizeof(*su));
- if (su == NULL) {
- (void)fprintf(stderr, "svcudp_create: out of memory\n");
- return (NULL);
- }
- su->su_iosz = ((MAX(sendsz, recvsz) + 3) / 4) * 4;
- if ((rpc_buffer(xprt) = mem_alloc(su->su_iosz)) == NULL) {
- (void)fprintf(stderr, "svcudp_create: out of memory\n");
- return (NULL);
- }
- xdrmem_create(
- &(su->su_xdrs), rpc_buffer(xprt), su->su_iosz, XDR_DECODE);
- su->su_cache = NULL;
- xprt->xp_p2 = (caddr_t)su;
- xprt->xp_verf.oa_base = su->su_verfbody;
- xprt->xp_ops = &svcudp_op;
- xprt->xp_port = ntohs(addr.sin_port);
- xprt->xp_sock = sock;
- xprt_register(xprt);
- return (xprt);
+ madesock = TRUE;
+ }
+ bzero ((char *) &addr, sizeof (addr));
+ addr.sin_family = AF_INET;
+ if (bindresvport (sock, &addr))
+ {
+ addr.sin_port = 0;
+ (void) bind (sock, (struct sockaddr *) &addr, len);
+ }
+ if (getsockname (sock, (struct sockaddr *) &addr, &len) != 0)
+ {
+ perror (_("svcudp_create - cannot getsockname"));
+ if (madesock)
+ (void) close (sock);
+ return (SVCXPRT *) NULL;
+ }
+ xprt = (SVCXPRT *) mem_alloc (sizeof (SVCXPRT));
+ if (xprt == NULL)
+ {
+ (void) fputs (_("svcudp_create: out of memory\n"), stderr);
+ return NULL;
+ }
+ su = (struct svcudp_data *) mem_alloc (sizeof (*su));
+ if (su == NULL)
+ {
+ (void) fputs (_("svcudp_create: out of memory\n"), stderr);
+ return NULL;
+ }
+ su->su_iosz = ((MAX (sendsz, recvsz) + 3) / 4) * 4;
+ if ((rpc_buffer (xprt) = mem_alloc (su->su_iosz)) == NULL)
+ {
+ (void) fputs (_("svcudp_create: out of memory\n"), stderr);
+ return NULL;
+ }
+ xdrmem_create (&(su->su_xdrs), rpc_buffer (xprt), su->su_iosz, XDR_DECODE);
+ su->su_cache = NULL;
+ xprt->xp_p2 = (caddr_t) su;
+ xprt->xp_verf.oa_base = su->su_verfbody;
+ xprt->xp_ops = &svcudp_op;
+ xprt->xp_port = ntohs (addr.sin_port);
+ xprt->xp_sock = sock;
+ xprt_register (xprt);
+ return xprt;
}
SVCXPRT *
-svcudp_create(sock)
- int sock;
+svcudp_create (sock)
+ int sock;
{
- return(svcudp_bufcreate(sock, UDPMSGSIZE, UDPMSGSIZE));
+ return svcudp_bufcreate (sock, UDPMSGSIZE, UDPMSGSIZE);
}
static enum xprt_stat
-svcudp_stat(xprt)
- SVCXPRT *xprt;
+svcudp_stat (xprt)
+ SVCXPRT *xprt;
{
- return (XPRT_IDLE);
+ return XPRT_IDLE;
}
static bool_t
-svcudp_recv(xprt, msg)
- register SVCXPRT *xprt;
- struct rpc_msg *msg;
+svcudp_recv (xprt, msg)
+ SVCXPRT *xprt;
+ struct rpc_msg *msg;
{
- register struct svcudp_data *su = su_data(xprt);
- register XDR *xdrs = &(su->su_xdrs);
- register int rlen;
- char *reply;
- u_long replylen;
-
- again:
- xprt->xp_addrlen = sizeof(struct sockaddr_in);
- rlen = recvfrom(xprt->xp_sock, rpc_buffer(xprt), (int) su->su_iosz,
- 0, (struct sockaddr *)&(xprt->xp_raddr), &(xprt->xp_addrlen));
- if (rlen == -1 && errno == EINTR)
- goto again;
- if (rlen < 16) /* < 4 32-bit ints? */
- return (FALSE);
- xdrs->x_op = XDR_DECODE;
- XDR_SETPOS(xdrs, 0);
- if (! xdr_callmsg(xdrs, msg))
- return (FALSE);
- su->su_xid = msg->rm_xid;
- if (su->su_cache != NULL) {
- if (cache_get(xprt, msg, &reply, &replylen)) {
- (void) sendto(xprt->xp_sock, reply, (int) replylen, 0,
- (struct sockaddr *) &xprt->xp_raddr, xprt->xp_addrlen);
- return (TRUE);
- }
+ struct svcudp_data *su = su_data (xprt);
+ XDR *xdrs = &(su->su_xdrs);
+ int rlen;
+ char *reply;
+ u_long replylen;
+
+again:
+ xprt->xp_addrlen = sizeof (struct sockaddr_in);
+ rlen = recvfrom (xprt->xp_sock, rpc_buffer (xprt), (int) su->su_iosz, 0,
+ (struct sockaddr *) &(xprt->xp_raddr), &(xprt->xp_addrlen));
+ if (rlen == -1 && errno == EINTR)
+ goto again;
+ if (rlen < 16) /* < 4 32-bit ints? */
+ return FALSE;
+ xdrs->x_op = XDR_DECODE;
+ XDR_SETPOS (xdrs, 0);
+ if (!xdr_callmsg (xdrs, msg))
+ return FALSE;
+ su->su_xid = msg->rm_xid;
+ if (su->su_cache != NULL)
+ {
+ if (cache_get (xprt, msg, &reply, &replylen))
+ {
+ (void) sendto (xprt->xp_sock, reply, (int) replylen, 0,
+ (struct sockaddr *) &xprt->xp_raddr, xprt->xp_addrlen);
+ return TRUE;
}
- return (TRUE);
+ }
+ return TRUE;
}
static bool_t
-svcudp_reply(xprt, msg)
- register SVCXPRT *xprt;
- struct rpc_msg *msg;
+svcudp_reply (xprt, msg)
+ SVCXPRT *xprt;
+ struct rpc_msg *msg;
{
- register struct svcudp_data *su = su_data(xprt);
- register XDR *xdrs = &(su->su_xdrs);
- register int slen;
- register bool_t stat = FALSE;
-
- xdrs->x_op = XDR_ENCODE;
- XDR_SETPOS(xdrs, 0);
- msg->rm_xid = su->su_xid;
- if (xdr_replymsg(xdrs, msg)) {
- slen = (int)XDR_GETPOS(xdrs);
- if (sendto(xprt->xp_sock, rpc_buffer(xprt), slen, 0,
- (struct sockaddr *)&(xprt->xp_raddr), xprt->xp_addrlen)
- == slen) {
- stat = TRUE;
- if (su->su_cache && slen >= 0) {
- cache_set(xprt, (u_long) slen);
- }
- }
+ struct svcudp_data *su = su_data (xprt);
+ XDR *xdrs = &(su->su_xdrs);
+ int slen;
+ bool_t stat = FALSE;
+
+ xdrs->x_op = XDR_ENCODE;
+ XDR_SETPOS (xdrs, 0);
+ msg->rm_xid = su->su_xid;
+ if (xdr_replymsg (xdrs, msg))
+ {
+ slen = (int) XDR_GETPOS (xdrs);
+ if (sendto (xprt->xp_sock, rpc_buffer (xprt), slen, 0,
+ (struct sockaddr *) &(xprt->xp_raddr), xprt->xp_addrlen)
+ == slen)
+ {
+ stat = TRUE;
+ if (su->su_cache && slen >= 0)
+ {
+ cache_set (xprt, (u_long) slen);
+ }
}
- return (stat);
+ }
+ return stat;
}
static bool_t
-svcudp_getargs(xprt, xdr_args, args_ptr)
- SVCXPRT *xprt;
- xdrproc_t xdr_args;
- caddr_t args_ptr;
+svcudp_getargs (xprt, xdr_args, args_ptr)
+ SVCXPRT *xprt;
+ xdrproc_t xdr_args;
+ caddr_t args_ptr;
{
- return ((*xdr_args)(&(su_data(xprt)->su_xdrs), args_ptr));
+ return (*xdr_args) (&(su_data (xprt)->su_xdrs), args_ptr);
}
static bool_t
-svcudp_freeargs(xprt, xdr_args, args_ptr)
- SVCXPRT *xprt;
- xdrproc_t xdr_args;
- caddr_t args_ptr;
+svcudp_freeargs (xprt, xdr_args, args_ptr)
+ SVCXPRT *xprt;
+ xdrproc_t xdr_args;
+ caddr_t args_ptr;
{
- register XDR *xdrs = &(su_data(xprt)->su_xdrs);
+ XDR *xdrs = &(su_data (xprt)->su_xdrs);
- xdrs->x_op = XDR_FREE;
- return ((*xdr_args)(xdrs, args_ptr));
+ xdrs->x_op = XDR_FREE;
+ return (*xdr_args) (xdrs, args_ptr);
}
static void
-svcudp_destroy(xprt)
- register SVCXPRT *xprt;
+svcudp_destroy (xprt)
+ SVCXPRT *xprt;
{
- register struct svcudp_data *su = su_data(xprt);
-
- xprt_unregister(xprt);
- (void)close(xprt->xp_sock);
- XDR_DESTROY(&(su->su_xdrs));
- mem_free(rpc_buffer(xprt), su->su_iosz);
- mem_free((caddr_t)su, sizeof(struct svcudp_data));
- mem_free((caddr_t)xprt, sizeof(SVCXPRT));
+ struct svcudp_data *su = su_data (xprt);
+
+ xprt_unregister (xprt);
+ (void) close (xprt->xp_sock);
+ XDR_DESTROY (&(su->su_xdrs));
+ mem_free (rpc_buffer (xprt), su->su_iosz);
+ mem_free ((caddr_t) su, sizeof (struct svcudp_data));
+ mem_free ((caddr_t) xprt, sizeof (SVCXPRT));
}
* Buffers are sent again if retransmissions are detected.
*/
-#define SPARSENESS 4 /* 75% sparse */
+#define SPARSENESS 4 /* 75% sparse */
#define CACHE_PERROR(msg) \
(void) fprintf(stderr,"%s\n", msg)
* An entry in the cache
*/
typedef struct cache_node *cache_ptr;
-struct cache_node {
- /*
- * Index into cache is xid, proc, vers, prog and address
- */
- u_long cache_xid;
- u_long cache_proc;
- u_long cache_vers;
- u_long cache_prog;
- struct sockaddr_in cache_addr;
- /*
- * The cached reply and length
- */
- char * cache_reply;
- u_long cache_replylen;
- /*
- * Next node on the list, if there is a collision
- */
- cache_ptr cache_next;
-};
+struct cache_node
+ {
+ /*
+ * Index into cache is xid, proc, vers, prog and address
+ */
+ u_long cache_xid;
+ u_long cache_proc;
+ u_long cache_vers;
+ u_long cache_prog;
+ struct sockaddr_in cache_addr;
+ /*
+ * The cached reply and length
+ */
+ char *cache_reply;
+ u_long cache_replylen;
+ /*
+ * Next node on the list, if there is a collision
+ */
+ cache_ptr cache_next;
+ };
/*
* The entire cache
*/
-struct udp_cache {
- u_long uc_size; /* size of cache */
- cache_ptr *uc_entries; /* hash table of entries in cache */
- cache_ptr *uc_fifo; /* fifo list of entries in cache */
- u_long uc_nextvictim; /* points to next victim in fifo list */
- u_long uc_prog; /* saved program number */
- u_long uc_vers; /* saved version number */
- u_long uc_proc; /* saved procedure number */
- struct sockaddr_in uc_addr; /* saved caller's address */
-};
+struct udp_cache
+ {
+ u_long uc_size; /* size of cache */
+ cache_ptr *uc_entries; /* hash table of entries in cache */
+ cache_ptr *uc_fifo; /* fifo list of entries in cache */
+ u_long uc_nextvictim; /* points to next victim in fifo list */
+ u_long uc_prog; /* saved program number */
+ u_long uc_vers; /* saved version number */
+ u_long uc_proc; /* saved procedure number */
+ struct sockaddr_in uc_addr; /* saved caller's address */
+ };
/*
* Enable use of the cache.
* Note: there is no disable.
*/
-svcudp_enablecache(transp, size)
- SVCXPRT *transp;
- u_long size;
+int
+svcudp_enablecache (SVCXPRT *transp, u_long size)
{
- struct svcudp_data *su = su_data(transp);
- struct udp_cache *uc;
-
- if (su->su_cache != NULL) {
- CACHE_PERROR(_("enablecache: cache already enabled"));
- return(0);
- }
- uc = ALLOC(struct udp_cache, 1);
- if (uc == NULL) {
- CACHE_PERROR(_("enablecache: could not allocate cache"));
- return(0);
- }
- uc->uc_size = size;
- uc->uc_nextvictim = 0;
- uc->uc_entries = ALLOC(cache_ptr, size * SPARSENESS);
- if (uc->uc_entries == NULL) {
- CACHE_PERROR(_("enablecache: could not allocate cache data"));
- return(0);
- }
- BZERO(uc->uc_entries, cache_ptr, size * SPARSENESS);
- uc->uc_fifo = ALLOC(cache_ptr, size);
- if (uc->uc_fifo == NULL) {
- CACHE_PERROR(_("enablecache: could not allocate cache fifo"));
- return(0);
- }
- BZERO(uc->uc_fifo, cache_ptr, size);
- su->su_cache = (char *) uc;
- return(1);
+ struct svcudp_data *su = su_data (transp);
+ struct udp_cache *uc;
+
+ if (su->su_cache != NULL)
+ {
+ CACHE_PERROR (_("enablecache: cache already enabled"));
+ return 0;
+ }
+ uc = ALLOC (struct udp_cache, 1);
+ if (uc == NULL)
+ {
+ CACHE_PERROR (_("enablecache: could not allocate cache"));
+ return 0;
+ }
+ uc->uc_size = size;
+ uc->uc_nextvictim = 0;
+ uc->uc_entries = ALLOC (cache_ptr, size * SPARSENESS);
+ if (uc->uc_entries == NULL)
+ {
+ CACHE_PERROR (_("enablecache: could not allocate cache data"));
+ return 0;
+ }
+ BZERO (uc->uc_entries, cache_ptr, size * SPARSENESS);
+ uc->uc_fifo = ALLOC (cache_ptr, size);
+ if (uc->uc_fifo == NULL)
+ {
+ CACHE_PERROR (_("enablecache: could not allocate cache fifo"));
+ return 0;
+ }
+ BZERO (uc->uc_fifo, cache_ptr, size);
+ su->su_cache = (char *) uc;
+ return 1;
}
/*
* Set an entry in the cache
*/
-static
-cache_set(xprt, replylen)
- SVCXPRT *xprt;
- u_long replylen;
+static void
+cache_set (SVCXPRT *xprt, u_long replylen)
{
- register cache_ptr victim;
- register cache_ptr *vicp;
- register struct svcudp_data *su = su_data(xprt);
- struct udp_cache *uc = (struct udp_cache *) su->su_cache;
- u_int loc;
- char *newbuf;
-
- /*
- * Find space for the new entry, either by
- * reusing an old entry, or by mallocing a new one
- */
- victim = uc->uc_fifo[uc->uc_nextvictim];
- if (victim != NULL) {
- loc = CACHE_LOC(xprt, victim->cache_xid);
- for (vicp = &uc->uc_entries[loc];
- *vicp != NULL && *vicp != victim;
- vicp = &(*vicp)->cache_next)
- ;
- if (*vicp == NULL) {
- CACHE_PERROR(_("cache_set: victim not found"));
- return;
- }
- *vicp = victim->cache_next; /* remote from cache */
- newbuf = victim->cache_reply;
- } else {
- victim = ALLOC(struct cache_node, 1);
- if (victim == NULL) {
- CACHE_PERROR("cache_set: victim alloc failed");
- return;
- }
- newbuf = mem_alloc(su->su_iosz);
- if (newbuf == NULL) {
- CACHE_PERROR("cache_set: could not allocate new rpc_buffer");
- return;
- }
+ cache_ptr victim;
+ cache_ptr *vicp;
+ struct svcudp_data *su = su_data (xprt);
+ struct udp_cache *uc = (struct udp_cache *) su->su_cache;
+ u_int loc;
+ char *newbuf;
+
+ /*
+ * Find space for the new entry, either by
+ * reusing an old entry, or by mallocing a new one
+ */
+ victim = uc->uc_fifo[uc->uc_nextvictim];
+ if (victim != NULL)
+ {
+ loc = CACHE_LOC (xprt, victim->cache_xid);
+ for (vicp = &uc->uc_entries[loc];
+ *vicp != NULL && *vicp != victim;
+ vicp = &(*vicp)->cache_next)
+ ;
+ if (*vicp == NULL)
+ {
+ CACHE_PERROR (_("cache_set: victim not found"));
+ return;
}
-
- /*
- * Store it away
- */
- victim->cache_replylen = replylen;
- victim->cache_reply = rpc_buffer(xprt);
- rpc_buffer(xprt) = newbuf;
- xdrmem_create(&(su->su_xdrs), rpc_buffer(xprt), su->su_iosz, XDR_ENCODE);
- victim->cache_xid = su->su_xid;
- victim->cache_proc = uc->uc_proc;
- victim->cache_vers = uc->uc_vers;
- victim->cache_prog = uc->uc_prog;
- victim->cache_addr = uc->uc_addr;
- loc = CACHE_LOC(xprt, victim->cache_xid);
- victim->cache_next = uc->uc_entries[loc];
- uc->uc_entries[loc] = victim;
- uc->uc_fifo[uc->uc_nextvictim++] = victim;
- uc->uc_nextvictim %= uc->uc_size;
+ *vicp = victim->cache_next; /* remote from cache */
+ newbuf = victim->cache_reply;
+ }
+ else
+ {
+ victim = ALLOC (struct cache_node, 1);
+ if (victim == NULL)
+ {
+ CACHE_PERROR (_("cache_set: victim alloc failed"));
+ return;
+ }
+ newbuf = mem_alloc (su->su_iosz);
+ if (newbuf == NULL)
+ {
+ CACHE_PERROR (_("cache_set: could not allocate new rpc_buffer"));
+ return;
+ }
+ }
+
+ /*
+ * Store it away
+ */
+ victim->cache_replylen = replylen;
+ victim->cache_reply = rpc_buffer (xprt);
+ rpc_buffer (xprt) = newbuf;
+ xdrmem_create (&(su->su_xdrs), rpc_buffer (xprt), su->su_iosz, XDR_ENCODE);
+ victim->cache_xid = su->su_xid;
+ victim->cache_proc = uc->uc_proc;
+ victim->cache_vers = uc->uc_vers;
+ victim->cache_prog = uc->uc_prog;
+ victim->cache_addr = uc->uc_addr;
+ loc = CACHE_LOC (xprt, victim->cache_xid);
+ victim->cache_next = uc->uc_entries[loc];
+ uc->uc_entries[loc] = victim;
+ uc->uc_fifo[uc->uc_nextvictim++] = victim;
+ uc->uc_nextvictim %= uc->uc_size;
}
/*
* Try to get an entry from the cache
* return 1 if found, 0 if not found
*/
-static
-cache_get(xprt, msg, replyp, replylenp)
- SVCXPRT *xprt;
- struct rpc_msg *msg;
- char **replyp;
- u_long *replylenp;
+static int
+cache_get (xprt, msg, replyp, replylenp)
+ SVCXPRT *xprt;
+ struct rpc_msg *msg;
+ char **replyp;
+ u_long *replylenp;
{
- u_int loc;
- register cache_ptr ent;
- register struct svcudp_data *su = su_data(xprt);
- register struct udp_cache *uc = (struct udp_cache *) su->su_cache;
-
-# define EQADDR(a1, a2) (bcmp((char*)&a1, (char*)&a2, sizeof(a1)) == 0)
-
- loc = CACHE_LOC(xprt, su->su_xid);
- for (ent = uc->uc_entries[loc]; ent != NULL; ent = ent->cache_next) {
- if (ent->cache_xid == su->su_xid &&
- ent->cache_proc == uc->uc_proc &&
- ent->cache_vers == uc->uc_vers &&
- ent->cache_prog == uc->uc_prog &&
- EQADDR(ent->cache_addr, uc->uc_addr)) {
- *replyp = ent->cache_reply;
- *replylenp = ent->cache_replylen;
- return(1);
- }
+ u_int loc;
+ cache_ptr ent;
+ struct svcudp_data *su = su_data (xprt);
+ struct udp_cache *uc = (struct udp_cache *) su->su_cache;
+
+#define EQADDR(a1, a2) (bcmp((char*)&a1, (char*)&a2, sizeof(a1)) == 0)
+
+ loc = CACHE_LOC (xprt, su->su_xid);
+ for (ent = uc->uc_entries[loc]; ent != NULL; ent = ent->cache_next)
+ {
+ if (ent->cache_xid == su->su_xid &&
+ ent->cache_proc == uc->uc_proc &&
+ ent->cache_vers == uc->uc_vers &&
+ ent->cache_prog == uc->uc_prog &&
+ EQADDR (ent->cache_addr, uc->uc_addr))
+ {
+ *replyp = ent->cache_reply;
+ *replylenp = ent->cache_replylen;
+ return 1;
}
- /*
- * Failed to find entry
- * Remember a few things so we can do a set later
- */
- uc->uc_proc = msg->rm_call.cb_proc;
- uc->uc_vers = msg->rm_call.cb_vers;
- uc->uc_prog = msg->rm_call.cb_prog;
- uc->uc_addr = xprt->xp_raddr;
- return(0);
+ }
+ /*
+ * Failed to find entry
+ * Remember a few things so we can do a set later
+ */
+ uc->uc_proc = msg->rm_call.cb_proc;
+ uc->uc_vers = msg->rm_call.cb_vers;
+ uc->uc_prog = msg->rm_call.cb_prog;
+ uc->uc_addr = xprt->xp_raddr;
+ return 0;
}
/*
* for unit alignment
*/
-static char xdr_zero[BYTES_PER_XDR_UNIT] = { 0, 0, 0, 0 };
+static const char xdr_zero[BYTES_PER_XDR_UNIT] =
+{0, 0, 0, 0};
/*
* Free a data structure using XDR
* Not a filter, but a convenient utility nonetheless
*/
void
-xdr_free(proc, objp)
- xdrproc_t proc;
- char *objp;
+xdr_free (proc, objp)
+ xdrproc_t proc;
+ char *objp;
{
- XDR x;
+ XDR x;
- x.x_op = XDR_FREE;
- (*proc)(&x, objp);
+ x.x_op = XDR_FREE;
+ (*proc) (&x, objp);
}
/*
* XDR nothing
*/
bool_t
-xdr_void(/* xdrs, addr */)
- /* XDR *xdrs; */
- /* caddr_t addr; */
+xdr_void (void)
{
-
- return (TRUE);
+ return TRUE;
}
/*
* XDR integers
*/
bool_t
-xdr_int(xdrs, ip)
- XDR *xdrs;
- int *ip;
+xdr_int (xdrs, ip)
+ XDR *xdrs;
+ int *ip;
{
#ifdef lint
- (void) (xdr_short(xdrs, (short *)ip));
- return (xdr_long(xdrs, (long *)ip));
+ (void) (xdr_short (xdrs, (short *) ip));
+ return (xdr_long (xdrs, (long *) ip));
#else
-# if INT_MAX < LONG_MAX
- long l;
-
- switch (xdrs->x_op) {
- case XDR_ENCODE:
- l = (long) *ip;
- return XDR_PUTLONG(xdrs, &l);
-
- case XDR_DECODE:
- if (!XDR_GETLONG(xdrs, &l)) {
- return FALSE;
- }
- *ip = (int) l;
- case XDR_FREE:
- return TRUE;
+#if INT_MAX < LONG_MAX
+ long l;
+
+ switch (xdrs->x_op)
+ {
+ case XDR_ENCODE:
+ l = (long) *ip;
+ return XDR_PUTLONG (xdrs, &l);
+
+ case XDR_DECODE:
+ if (!XDR_GETLONG (xdrs, &l))
+ {
+ return FALSE;
}
- return FALSE;
-# elif INT_MAX == LONG_MAX
- return xdr_long(xdrs, (long *)ip);
-# elif INT_MAX == SHRT_MAX
- return xdr_short(xdrs, (short *)ip);
-# else
-# error unexpected integer sizes in_xdr_int()
-# endif
+ *ip = (int) l;
+ case XDR_FREE:
+ return TRUE;
+ }
+ return FALSE;
+#elif INT_MAX == LONG_MAX
+ return xdr_long (xdrs, (long *) ip);
+#elif INT_MAX == SHRT_MAX
+ return xdr_short (xdrs, (short *) ip);
+#else
+#error unexpected integer sizes in_xdr_int()
+#endif
#endif
}
* XDR unsigned integers
*/
bool_t
-xdr_u_int(xdrs, up)
- XDR *xdrs;
- u_int *up;
+xdr_u_int (xdrs, up)
+ XDR *xdrs;
+ u_int *up;
{
#ifdef lint
- (void) (xdr_short(xdrs, (short *)up));
- return (xdr_u_long(xdrs, (u_long *)up));
+ (void) (xdr_short (xdrs, (short *) up));
+ return (xdr_u_long (xdrs, (u_long *) up));
#else
-# if UINT_MAX < ULONG_MAX
- u_long l;
-
- switch (xdrs->x_op) {
- case XDR_ENCODE:
- l = (u_long) *up;
- return XDR_PUTLONG(xdrs, &l);
-
- case XDR_DECODE:
- if (!XDR_GETLONG(xdrs, &l)) {
- return FALSE;
- }
- *up = (u_int) l;
- case XDR_FREE:
- return TRUE;
+#if UINT_MAX < ULONG_MAX
+ u_long l;
+
+ switch (xdrs->x_op)
+ {
+ case XDR_ENCODE:
+ l = (u_long) * up;
+ return XDR_PUTLONG (xdrs, &l);
+
+ case XDR_DECODE:
+ if (!XDR_GETLONG (xdrs, &l))
+ {
+ return FALSE;
}
- return FALSE;
-# elif UINT_MAX == ULONG_MAX
- return xdr_u_long(xdrs, (u_long *)up);
-# elif UINT_MAX == USHRT_MAX
- return xdr_short(xdrs, (short *)up);
-# else
-# error unexpected integer sizes in_xdr_u_int()
-# endif
+ *up = (u_int) l;
+ case XDR_FREE:
+ return TRUE;
+ }
+ return FALSE;
+#elif UINT_MAX == ULONG_MAX
+ return xdr_u_long (xdrs, (u_long *) up);
+#elif UINT_MAX == USHRT_MAX
+ return xdr_short (xdrs, (short *) up);
+#else
+#error unexpected integer sizes in_xdr_u_int()
+#endif
#endif
}
* same as xdr_u_long - open coded to save a proc call!
*/
bool_t
-xdr_long(xdrs, lp)
- register XDR *xdrs;
- long *lp;
+xdr_long (xdrs, lp)
+ XDR *xdrs;
+ long *lp;
{
- if (xdrs->x_op == XDR_ENCODE)
- return (XDR_PUTLONG(xdrs, lp));
+ if (xdrs->x_op == XDR_ENCODE)
+ return XDR_PUTLONG (xdrs, lp);
- if (xdrs->x_op == XDR_DECODE)
- return (XDR_GETLONG(xdrs, lp));
+ if (xdrs->x_op == XDR_DECODE)
+ return XDR_GETLONG (xdrs, lp);
- if (xdrs->x_op == XDR_FREE)
- return (TRUE);
+ if (xdrs->x_op == XDR_FREE)
+ return TRUE;
- return (FALSE);
+ return FALSE;
}
/*
* same as xdr_long - open coded to save a proc call!
*/
bool_t
-xdr_u_long(xdrs, ulp)
- register XDR *xdrs;
- u_long *ulp;
+xdr_u_long (xdrs, ulp)
+ XDR *xdrs;
+ u_long *ulp;
{
- switch (xdrs->x_op) {
- case XDR_DECODE:
- return XDR_GETLONG(xdrs, (long *)ulp);
-
- case XDR_ENCODE:
- return XDR_PUTLONG(xdrs, (long *)ulp);
-
- case XDR_FREE:
- return TRUE;
- }
- return FALSE;
+ switch (xdrs->x_op)
+ {
+ case XDR_DECODE:
+ return XDR_GETLONG (xdrs, (long *) ulp);
+
+ case XDR_ENCODE:
+ return XDR_PUTLONG (xdrs, (long *) ulp);
+
+ case XDR_FREE:
+ return TRUE;
+ }
+ return FALSE;
}
/*
* XDR short integers
*/
bool_t
-xdr_short(xdrs, sp)
- register XDR *xdrs;
- short *sp;
+xdr_short (xdrs, sp)
+ XDR *xdrs;
+ short *sp;
{
- long l;
-
- switch (xdrs->x_op) {
- case XDR_ENCODE:
- l = (long) *sp;
- return XDR_PUTLONG(xdrs, &l);
-
- case XDR_DECODE:
- if (!XDR_GETLONG(xdrs, &l)) {
- return FALSE;
- }
- *sp = (short) l;
- return TRUE;
-
- case XDR_FREE:
- return TRUE;
+ long l;
+
+ switch (xdrs->x_op)
+ {
+ case XDR_ENCODE:
+ l = (long) *sp;
+ return XDR_PUTLONG (xdrs, &l);
+
+ case XDR_DECODE:
+ if (!XDR_GETLONG (xdrs, &l))
+ {
+ return FALSE;
}
- return FALSE;
+ *sp = (short) l;
+ return TRUE;
+
+ case XDR_FREE:
+ return TRUE;
+ }
+ return FALSE;
}
/*
* XDR unsigned short integers
*/
bool_t
-xdr_u_short(xdrs, usp)
- register XDR *xdrs;
- u_short *usp;
+xdr_u_short (xdrs, usp)
+ XDR *xdrs;
+ u_short *usp;
{
- u_long l;
-
- switch (xdrs->x_op) {
- case XDR_ENCODE:
- l = (u_long) *usp;
- return XDR_PUTLONG(xdrs, &l);
-
- case XDR_DECODE:
- if (!XDR_GETLONG(xdrs, &l)) {
- return FALSE;
- }
- *usp = (u_short) l;
- return TRUE;
-
- case XDR_FREE:
- return TRUE;
+ u_long l;
+
+ switch (xdrs->x_op)
+ {
+ case XDR_ENCODE:
+ l = (u_long) * usp;
+ return XDR_PUTLONG (xdrs, &l);
+
+ case XDR_DECODE:
+ if (!XDR_GETLONG (xdrs, &l))
+ {
+ return FALSE;
}
- return FALSE;
+ *usp = (u_short) l;
+ return TRUE;
+
+ case XDR_FREE:
+ return TRUE;
+ }
+ return FALSE;
}
* XDR a char
*/
bool_t
-xdr_char(xdrs, cp)
- XDR *xdrs;
- char *cp;
+xdr_char (xdrs, cp)
+ XDR *xdrs;
+ char *cp;
{
- int i;
-
- i = (*cp);
- if (!xdr_int(xdrs, &i)) {
- return FALSE;
- }
- *cp = i;
- return TRUE;
+ int i;
+
+ i = (*cp);
+ if (!xdr_int (xdrs, &i))
+ {
+ return FALSE;
+ }
+ *cp = i;
+ return TRUE;
}
/*
* XDR an unsigned char
*/
bool_t
-xdr_u_char(xdrs, cp)
- XDR *xdrs;
- u_char *cp;
+xdr_u_char (xdrs, cp)
+ XDR *xdrs;
+ u_char *cp;
{
- u_int u;
-
- u = (*cp);
- if (!xdr_u_int(xdrs, &u)) {
- return FALSE;
- }
- *cp = u;
- return TRUE;
+ u_int u;
+
+ u = (*cp);
+ if (!xdr_u_int (xdrs, &u))
+ {
+ return FALSE;
+ }
+ *cp = u;
+ return TRUE;
}
/*
* XDR booleans
*/
bool_t
-xdr_bool(xdrs, bp)
- register XDR *xdrs;
- bool_t *bp;
+xdr_bool (xdrs, bp)
+ XDR *xdrs;
+ bool_t *bp;
{
- long lb;
-
- switch (xdrs->x_op) {
- case XDR_ENCODE:
- lb = *bp ? XDR_TRUE : XDR_FALSE;
- return XDR_PUTLONG(xdrs, &lb);
-
- case XDR_DECODE:
- if (!XDR_GETLONG(xdrs, &lb)) {
- return FALSE;
- }
- *bp = (lb == XDR_FALSE) ? FALSE : TRUE;
- return TRUE;
-
- case XDR_FREE:
- return TRUE;
+ long lb;
+
+ switch (xdrs->x_op)
+ {
+ case XDR_ENCODE:
+ lb = *bp ? XDR_TRUE : XDR_FALSE;
+ return XDR_PUTLONG (xdrs, &lb);
+
+ case XDR_DECODE:
+ if (!XDR_GETLONG (xdrs, &lb))
+ {
+ return FALSE;
}
- return FALSE;
+ *bp = (lb == XDR_FALSE) ? FALSE : TRUE;
+ return TRUE;
+
+ case XDR_FREE:
+ return TRUE;
+ }
+ return FALSE;
}
/*
* XDR enumerations
*/
bool_t
-xdr_enum(xdrs, ep)
- XDR *xdrs;
- enum_t *ep;
+xdr_enum (xdrs, ep)
+ XDR *xdrs;
+ enum_t *ep;
{
#ifndef lint
- enum sizecheck { SIZEVAL }; /* used to find the size of an enum */
-
- /*
- * enums are treated as ints
- */
- if (sizeof (enum sizecheck) == 4) {
-# if INT_MAX < LONG_MAX
- long l;
-
- switch (xdrs->x_op) {
- case XDR_ENCODE:
- l = *ep;
- return XDR_PUTLONG(xdrs, &l);
-
- case XDR_DECODE:
- if (!XDR_GETLONG(xdrs, &l)) {
- return FALSE;
- }
- *ep = l;
- case XDR_FREE:
- return TRUE;
-
- }
- return FALSE;
-# else
- return (xdr_long(xdrs, (long *)ep));
-# endif
- } else if (sizeof (enum sizecheck) == sizeof (short)) {
- return xdr_short(xdrs, (short *)ep);
- } else {
- return FALSE;
+ enum sizecheck
+ {
+ SIZEVAL
+ }; /* used to find the size of an enum */
+
+ /*
+ * enums are treated as ints
+ */
+ if (sizeof (enum sizecheck) == 4)
+ {
+#if INT_MAX < LONG_MAX
+ long l;
+
+ switch (xdrs->x_op)
+ {
+ case XDR_ENCODE:
+ l = *ep;
+ return XDR_PUTLONG (xdrs, &l);
+
+ case XDR_DECODE:
+ if (!XDR_GETLONG (xdrs, &l))
+ {
+ return FALSE;
+ }
+ *ep = l;
+ case XDR_FREE:
+ return TRUE;
+
}
+ return FALSE;
+#else
+ return xdr_long (xdrs, (long *) ep);
+#endif
+ }
+ else if (sizeof (enum sizecheck) == sizeof (short))
+ {
+ return xdr_short (xdrs, (short *) ep);
+ }
+ else
+ {
+ return FALSE;
+ }
#else /* lint */
- (void) (xdr_short(xdrs, (short *)ep));
- return (xdr_long(xdrs, (long *)ep));
+ (void) (xdr_short (xdrs, (short *) ep));
+ return xdr_long (xdrs, (long *) ep);
#endif /* lint */
}
* cp points to the opaque object and cnt gives the byte length.
*/
bool_t
-xdr_opaque(xdrs, cp, cnt)
- register XDR *xdrs;
- caddr_t cp;
- register u_int cnt;
+xdr_opaque (xdrs, cp, cnt)
+ XDR *xdrs;
+ caddr_t cp;
+ u_int cnt;
{
- register u_int rndup;
- static crud[BYTES_PER_XDR_UNIT];
-
- /*
- * if no data we are done
- */
- if (cnt == 0)
- return TRUE;
-
- /*
- * round byte count to full xdr units
- */
- rndup = cnt % BYTES_PER_XDR_UNIT;
- if (rndup > 0)
- rndup = BYTES_PER_XDR_UNIT - rndup;
-
- switch (xdrs->x_op) {
- case XDR_DECODE:
- if (!XDR_GETBYTES(xdrs, cp, cnt)) {
- return FALSE;
- }
- if (rndup == 0)
- return TRUE;
- return XDR_GETBYTES(xdrs, crud, rndup);
-
- case XDR_ENCODE:
- if (!XDR_PUTBYTES(xdrs, cp, cnt)) {
- return FALSE;
- }
- if (rndup == 0)
- return TRUE;
- return XDR_PUTBYTES(xdrs, xdr_zero, rndup);
-
- case XDR_FREE:
- return TRUE;
+ u_int rndup;
+ static char crud[BYTES_PER_XDR_UNIT];
+
+ /*
+ * if no data we are done
+ */
+ if (cnt == 0)
+ return TRUE;
+
+ /*
+ * round byte count to full xdr units
+ */
+ rndup = cnt % BYTES_PER_XDR_UNIT;
+ if (rndup > 0)
+ rndup = BYTES_PER_XDR_UNIT - rndup;
+
+ switch (xdrs->x_op)
+ {
+ case XDR_DECODE:
+ if (!XDR_GETBYTES (xdrs, cp, cnt))
+ {
+ return FALSE;
}
- return FALSE;
+ if (rndup == 0)
+ return TRUE;
+ return XDR_GETBYTES (xdrs, (caddr_t)crud, rndup);
+
+ case XDR_ENCODE:
+ if (!XDR_PUTBYTES (xdrs, cp, cnt))
+ {
+ return FALSE;
+ }
+ if (rndup == 0)
+ return TRUE;
+ return XDR_PUTBYTES (xdrs, xdr_zero, rndup);
+
+ case XDR_FREE:
+ return TRUE;
+ }
+ return FALSE;
}
/*
* If *cpp is NULL maxsize bytes are allocated
*/
bool_t
-xdr_bytes(xdrs, cpp, sizep, maxsize)
- register XDR *xdrs;
- char **cpp;
- register u_int *sizep;
- u_int maxsize;
+xdr_bytes (xdrs, cpp, sizep, maxsize)
+ XDR *xdrs;
+ char **cpp;
+ u_int *sizep;
+ u_int maxsize;
{
- register char *sp = *cpp; /* sp is the actual string pointer */
- register u_int nodesize;
-
- /*
- * first deal with the length since xdr bytes are counted
- */
- if (! xdr_u_int(xdrs, sizep)) {
- return FALSE;
+ char *sp = *cpp; /* sp is the actual string pointer */
+ u_int nodesize;
+
+ /*
+ * first deal with the length since xdr bytes are counted
+ */
+ if (!xdr_u_int (xdrs, sizep))
+ {
+ return FALSE;
+ }
+ nodesize = *sizep;
+ if ((nodesize > maxsize) && (xdrs->x_op != XDR_FREE))
+ {
+ return FALSE;
+ }
+
+ /*
+ * now deal with the actual bytes
+ */
+ switch (xdrs->x_op)
+ {
+ case XDR_DECODE:
+ if (nodesize == 0)
+ {
+ return TRUE;
+ }
+ if (sp == NULL)
+ {
+ *cpp = sp = (char *) mem_alloc (nodesize);
}
- nodesize = *sizep;
- if ((nodesize > maxsize) && (xdrs->x_op != XDR_FREE)) {
- return FALSE;
+ if (sp == NULL)
+ {
+ (void) fprintf (stderr, "xdr_bytes: out of memory\n");
+ return FALSE;
}
+ /* fall into ... */
- /*
- * now deal with the actual bytes
- */
- switch (xdrs->x_op) {
- case XDR_DECODE:
- if (nodesize == 0) {
- return TRUE;
- }
- if (sp == NULL) {
- *cpp = sp = (char *)mem_alloc(nodesize);
- }
- if (sp == NULL) {
- (void) fprintf(stderr, "xdr_bytes: out of memory\n");
- return FALSE;
- }
- /* fall into ... */
-
- case XDR_ENCODE:
- return xdr_opaque(xdrs, sp, nodesize);
-
- case XDR_FREE:
- if (sp != NULL) {
- mem_free(sp, nodesize);
- *cpp = NULL;
- }
- return TRUE;
+ case XDR_ENCODE:
+ return xdr_opaque (xdrs, sp, nodesize);
+
+ case XDR_FREE:
+ if (sp != NULL)
+ {
+ mem_free (sp, nodesize);
+ *cpp = NULL;
}
- return FALSE;
+ return TRUE;
+ }
+ return FALSE;
}
/*
* Implemented here due to commonality of the object.
*/
bool_t
-xdr_netobj(xdrs, np)
- XDR *xdrs;
- struct netobj *np;
+xdr_netobj (xdrs, np)
+ XDR *xdrs;
+ struct netobj *np;
{
- return xdr_bytes(xdrs, &np->n_bytes, &np->n_len, MAX_NETOBJ_SZ);
+ return xdr_bytes (xdrs, &np->n_bytes, &np->n_len, MAX_NETOBJ_SZ);
}
/*
* If there is no specific or default routine an error is returned.
*/
bool_t
-xdr_union(xdrs, dscmp, unp, choices, dfault)
- register XDR *xdrs;
- enum_t *dscmp; /* enum to decide which arm to work on */
- char *unp; /* the union itself */
- struct xdr_discrim *choices; /* [value, xdr proc] for each arm */
- xdrproc_t dfault; /* default xdr routine */
+xdr_union (xdrs, dscmp, unp, choices, dfault)
+ XDR *xdrs;
+ enum_t *dscmp; /* enum to decide which arm to work on */
+ char *unp; /* the union itself */
+ const struct xdr_discrim *choices; /* [value, xdr proc] for each arm */
+ xdrproc_t dfault; /* default xdr routine */
{
- register enum_t dscm;
-
- /*
- * we deal with the discriminator; it's an enum
- */
- if (! xdr_enum(xdrs, dscmp)) {
- return FALSE;
- }
- dscm = *dscmp;
-
- /*
- * search choices for a value that matches the discriminator.
- * if we find one, execute the xdr routine for that value.
- */
- for (; choices->proc != NULL_xdrproc_t; choices++) {
- if (choices->value == dscm)
- return (*(choices->proc))(xdrs, unp, LASTUNSIGNED);
- }
-
- /*
- * no match - execute the default xdr routine if there is one
- */
- return ((dfault == NULL_xdrproc_t) ? FALSE :
- (*dfault)(xdrs, unp, LASTUNSIGNED));
+ enum_t dscm;
+
+ /*
+ * we deal with the discriminator; it's an enum
+ */
+ if (!xdr_enum (xdrs, dscmp))
+ {
+ return FALSE;
+ }
+ dscm = *dscmp;
+
+ /*
+ * search choices for a value that matches the discriminator.
+ * if we find one, execute the xdr routine for that value.
+ */
+ for (; choices->proc != NULL_xdrproc_t; choices++)
+ {
+ if (choices->value == dscm)
+ return (*(choices->proc)) (xdrs, unp, LASTUNSIGNED);
+ }
+
+ /*
+ * no match - execute the default xdr routine if there is one
+ */
+ return ((dfault == NULL_xdrproc_t) ? FALSE :
+ (*dfault) (xdrs, unp, LASTUNSIGNED));
}
* of the string as specified by a protocol.
*/
bool_t
-xdr_string(xdrs, cpp, maxsize)
- register XDR *xdrs;
- char **cpp;
- u_int maxsize;
+xdr_string (xdrs, cpp, maxsize)
+ XDR *xdrs;
+ char **cpp;
+ u_int maxsize;
{
- register char *sp = *cpp; /* sp is the actual string pointer */
- u_int size;
- u_int nodesize;
-
- /*
- * first deal with the length since xdr strings are counted-strings
- */
- switch (xdrs->x_op) {
- case XDR_FREE:
- if (sp == NULL) {
- return TRUE; /* already free */
- }
- /* fall through... */
- case XDR_ENCODE:
- if (sp == NULL)
- return FALSE;
- size = strlen(sp);
- break;
+ char *sp = *cpp; /* sp is the actual string pointer */
+ u_int size;
+ u_int nodesize;
+
+ /*
+ * first deal with the length since xdr strings are counted-strings
+ */
+ switch (xdrs->x_op)
+ {
+ case XDR_FREE:
+ if (sp == NULL)
+ {
+ return TRUE; /* already free */
}
- if (! xdr_u_int(xdrs, &size)) {
- return FALSE;
- }
- if (size > maxsize) {
- return FALSE;
+ /* fall through... */
+ case XDR_ENCODE:
+ if (sp == NULL)
+ return FALSE;
+ size = strlen (sp);
+ break;
+ case XDR_DECODE:
+ break;
+ }
+ if (!xdr_u_int (xdrs, &size))
+ {
+ return FALSE;
+ }
+ if (size > maxsize)
+ {
+ return FALSE;
+ }
+ nodesize = size + 1;
+
+ /*
+ * now deal with the actual bytes
+ */
+ switch (xdrs->x_op)
+ {
+ case XDR_DECODE:
+ if (nodesize == 0)
+ {
+ return TRUE;
}
- nodesize = size + 1;
-
- /*
- * now deal with the actual bytes
- */
- switch (xdrs->x_op) {
- case XDR_DECODE:
- if (nodesize == 0) {
- return TRUE;
- }
- if (sp == NULL)
- *cpp = sp = (char *)mem_alloc(nodesize);
- if (sp == NULL) {
- (void) fprintf(stderr, "xdr_string: out of memory\n");
- return FALSE;
- }
- sp[size] = 0;
- /* fall into ... */
-
- case XDR_ENCODE:
- return xdr_opaque(xdrs, sp, size);
-
- case XDR_FREE:
- mem_free(sp, nodesize);
- *cpp = NULL;
- return TRUE;
+ if (sp == NULL)
+ *cpp = sp = (char *) mem_alloc (nodesize);
+ if (sp == NULL)
+ {
+ (void) fprintf (stderr, "xdr_string: out of memory\n");
+ return FALSE;
}
- return FALSE;
+ sp[size] = 0;
+ /* fall into ... */
+
+ case XDR_ENCODE:
+ return xdr_opaque (xdrs, sp, size);
+
+ case XDR_FREE:
+ mem_free (sp, nodesize);
+ *cpp = NULL;
+ return TRUE;
+ }
+ return FALSE;
}
/*
* routines like clnt_call
*/
bool_t
-xdr_wrapstring(xdrs, cpp)
- XDR *xdrs;
- char **cpp;
+xdr_wrapstring (xdrs, cpp)
+ XDR *xdrs;
+ char **cpp;
{
- if (xdr_string(xdrs, cpp, LASTUNSIGNED)) {
- return TRUE;
- }
- return FALSE;
+ if (xdr_string (xdrs, cpp, LASTUNSIGNED))
+ {
+ return TRUE;
+ }
+ return FALSE;
}
*/
#include <stdio.h>
-
+#include <string.h>
#include <rpc/types.h>
#include <rpc/xdr.h>
* xdr procedure to call to handle each element of the array.
*/
bool_t
-xdr_array(xdrs, addrp, sizep, maxsize, elsize, elproc)
- register XDR *xdrs;
- caddr_t *addrp; /* array pointer */
- u_int *sizep; /* number of elements */
- u_int maxsize; /* max numberof elements */
- u_int elsize; /* size in bytes of each element */
- xdrproc_t elproc; /* xdr routine to handle each element */
+xdr_array (xdrs, addrp, sizep, maxsize, elsize, elproc)
+ XDR *xdrs;
+ caddr_t *addrp; /* array pointer */
+ u_int *sizep; /* number of elements */
+ u_int maxsize; /* max numberof elements */
+ u_int elsize; /* size in bytes of each element */
+ xdrproc_t elproc; /* xdr routine to handle each element */
{
- register u_int i;
- register caddr_t target = *addrp;
- register u_int c; /* the actual element count */
- register bool_t stat = TRUE;
- register u_int nodesize;
+ u_int i;
+ caddr_t target = *addrp;
+ u_int c; /* the actual element count */
+ bool_t stat = TRUE;
+ u_int nodesize;
- /* like strings, arrays are really counted arrays */
- if (! xdr_u_int(xdrs, sizep)) {
- return (FALSE);
- }
- c = *sizep;
- if ((c > maxsize) && (xdrs->x_op != XDR_FREE)) {
- return (FALSE);
- }
- nodesize = c * elsize;
+ /* like strings, arrays are really counted arrays */
+ if (!xdr_u_int (xdrs, sizep))
+ {
+ return FALSE;
+ }
+ c = *sizep;
+ if ((c > maxsize) && (xdrs->x_op != XDR_FREE))
+ {
+ return FALSE;
+ }
+ nodesize = c * elsize;
- /*
- * if we are deserializing, we may need to allocate an array.
- * We also save time by checking for a null array if we are freeing.
- */
+ /*
+ * if we are deserializing, we may need to allocate an array.
+ * We also save time by checking for a null array if we are freeing.
+ */
+ if (target == NULL)
+ switch (xdrs->x_op)
+ {
+ case XDR_DECODE:
+ if (c == 0)
+ return TRUE;
+ *addrp = target = mem_alloc (nodesize);
if (target == NULL)
- switch (xdrs->x_op) {
- case XDR_DECODE:
- if (c == 0)
- return (TRUE);
- *addrp = target = mem_alloc(nodesize);
- if (target == NULL) {
- (void) fprintf(stderr,
- "xdr_array: out of memory\n");
- return (FALSE);
- }
- bzero(target, nodesize);
- break;
+ {
+ (void) fprintf (stderr,
+ "xdr_array: out of memory\n");
+ return FALSE;
+ }
+ bzero (target, nodesize);
+ break;
- case XDR_FREE:
- return (TRUE);
- }
+ case XDR_FREE:
+ return TRUE;
+ default:
+ break;
+ }
- /*
- * now we xdr each element of array
- */
- for (i = 0; (i < c) && stat; i++) {
- stat = (*elproc)(xdrs, target, LASTUNSIGNED);
- target += elsize;
- }
+ /*
+ * now we xdr each element of array
+ */
+ for (i = 0; (i < c) && stat; i++)
+ {
+ stat = (*elproc) (xdrs, target, LASTUNSIGNED);
+ target += elsize;
+ }
- /*
- * the array may need freeing
- */
- if (xdrs->x_op == XDR_FREE) {
- mem_free(*addrp, nodesize);
- *addrp = NULL;
- }
- return (stat);
+ /*
+ * the array may need freeing
+ */
+ if (xdrs->x_op == XDR_FREE)
+ {
+ mem_free (*addrp, nodesize);
+ *addrp = NULL;
+ }
+ return stat;
}
/*
* > xdr_elem: routine to XDR each element
*/
bool_t
-xdr_vector(xdrs, basep, nelem, elemsize, xdr_elem)
- register XDR *xdrs;
- register char *basep;
- register u_int nelem;
- register u_int elemsize;
- register xdrproc_t xdr_elem;
+xdr_vector (xdrs, basep, nelem, elemsize, xdr_elem)
+ XDR *xdrs;
+ char *basep;
+ u_int nelem;
+ u_int elemsize;
+ xdrproc_t xdr_elem;
{
- register u_int i;
- register char *elptr;
+ u_int i;
+ char *elptr;
- elptr = basep;
- for (i = 0; i < nelem; i++) {
- if (! (*xdr_elem)(xdrs, elptr, LASTUNSIGNED)) {
- return(FALSE);
- }
- elptr += elemsize;
+ elptr = basep;
+ for (i = 0; i < nelem; i++)
+ {
+ if (!(*xdr_elem) (xdrs, elptr, LASTUNSIGNED))
+ {
+ return FALSE;
}
- return(TRUE);
+ elptr += elemsize;
+ }
+ return TRUE;
}
* may copy or modify Sun RPC without charge, but are not authorized
* to license or distribute it to anyone else except as part of a product or
* program developed by the user.
- *
+ *
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
- *
+ *
* Sun RPC is provided with no support and without any obligation on the
* part of Sun Microsystems, Inc. to assist in its use, correction,
* modification or enhancement.
- *
+ *
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
* OR ANY PART THEREOF.
- *
+ *
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
* or profits or other special, indirect and consequential damages, even if
* Sun has been advised of the possibility of such damages.
- *
+ *
* Sun Microsystems, Inc.
* 2550 Garcia Avenue
* Mountain View, California 94043
*/
-#include <rpc/types.h>
-#include <rpc/xdr.h>
-#include <netinet/in.h>
-
-static bool_t xdrmem_getlong();
-static bool_t xdrmem_putlong();
-static bool_t xdrmem_getbytes();
-static bool_t xdrmem_putbytes();
-static u_int xdrmem_getpos();
-static bool_t xdrmem_setpos();
-static long * xdrmem_inline();
-static void xdrmem_destroy();
-
-static struct xdr_ops xdrmem_ops = {
- xdrmem_getlong,
- xdrmem_putlong,
- xdrmem_getbytes,
- xdrmem_putbytes,
- xdrmem_getpos,
- xdrmem_setpos,
- xdrmem_inline,
- xdrmem_destroy
+#include <string.h>
+#include <rpc/rpc.h>
+
+static bool_t xdrmem_getlong (XDR *, long *);
+static bool_t xdrmem_putlong (XDR *, long *);
+static bool_t xdrmem_getbytes (XDR *, caddr_t, u_int);
+static bool_t xdrmem_putbytes (XDR *, caddr_t, u_int);
+static u_int xdrmem_getpos (XDR *);
+static bool_t xdrmem_setpos (XDR *, u_int);
+static long *xdrmem_inline (XDR *, int);
+static void xdrmem_destroy (XDR *);
+
+static const struct xdr_ops xdrmem_ops =
+{
+ xdrmem_getlong,
+ xdrmem_putlong,
+ xdrmem_getbytes,
+ xdrmem_putbytes,
+ xdrmem_getpos,
+ xdrmem_setpos,
+ xdrmem_inline,
+ xdrmem_destroy
};
/*
* The procedure xdrmem_create initializes a stream descriptor for a
- * memory buffer.
+ * memory buffer.
*/
void
-xdrmem_create(xdrs, addr, size, op)
- register XDR *xdrs;
- caddr_t addr;
- u_int size;
- enum xdr_op op;
+xdrmem_create (xdrs, addr, size, op)
+ XDR *xdrs;
+ caddr_t addr;
+ u_int size;
+ enum xdr_op op;
{
- xdrs->x_op = op;
- xdrs->x_ops = &xdrmem_ops;
- xdrs->x_private = xdrs->x_base = addr;
- xdrs->x_handy = size;
+ xdrs->x_op = op;
+ xdrs->x_ops = &xdrmem_ops;
+ xdrs->x_private = xdrs->x_base = addr;
+ xdrs->x_handy = size;
}
static void
-xdrmem_destroy(/*xdrs*/)
- /*XDR *xdrs;*/
+xdrmem_destroy (XDR *xdrs)
{
}
static bool_t
-xdrmem_getlong(xdrs, lp)
- register XDR *xdrs;
- long *lp;
+xdrmem_getlong (xdrs, lp)
+ XDR *xdrs;
+ long *lp;
{
- if ((xdrs->x_handy -= 4) < 0)
- return (FALSE);
- *lp = (int32_t) ntohl((*((int32_t *)(xdrs->x_private))));
- xdrs->x_private += 4;
- return (TRUE);
+ if ((xdrs->x_handy -= 4) < 0)
+ return FALSE;
+ *lp = (int32_t) ntohl ((*((int32_t *) (xdrs->x_private))));
+ xdrs->x_private += 4;
+ return TRUE;
}
static bool_t
-xdrmem_putlong(xdrs, lp)
- register XDR *xdrs;
- long *lp;
+xdrmem_putlong (xdrs, lp)
+ XDR *xdrs;
+ long *lp;
{
- if ((xdrs->x_handy -= 4) < 0)
- return (FALSE);
- *(int32_t *)xdrs->x_private = htonl(*lp);
- xdrs->x_private += 4;
- return (TRUE);
+ if ((xdrs->x_handy -= 4) < 0)
+ return FALSE;
+ *(int32_t *) xdrs->x_private = htonl (*lp);
+ xdrs->x_private += 4;
+ return TRUE;
}
static bool_t
-xdrmem_getbytes(xdrs, addr, len)
- register XDR *xdrs;
- caddr_t addr;
- register u_int len;
+xdrmem_getbytes (xdrs, addr, len)
+ XDR *xdrs;
+ caddr_t addr;
+ u_int len;
{
- if ((xdrs->x_handy -= len) < 0)
- return (FALSE);
- bcopy(xdrs->x_private, addr, len);
- xdrs->x_private += len;
- return (TRUE);
+ if ((xdrs->x_handy -= len) < 0)
+ return FALSE;
+ bcopy (xdrs->x_private, addr, len);
+ xdrs->x_private += len;
+ return TRUE;
}
static bool_t
-xdrmem_putbytes(xdrs, addr, len)
- register XDR *xdrs;
- caddr_t addr;
- register u_int len;
+xdrmem_putbytes (xdrs, addr, len)
+ XDR *xdrs;
+ caddr_t addr;
+ u_int len;
{
- if ((xdrs->x_handy -= len) < 0)
- return (FALSE);
- bcopy(addr, xdrs->x_private, len);
- xdrs->x_private += len;
- return (TRUE);
+ if ((xdrs->x_handy -= len) < 0)
+ return FALSE;
+ bcopy (addr, xdrs->x_private, len);
+ xdrs->x_private += len;
+ return TRUE;
}
static u_int
-xdrmem_getpos(xdrs)
- register XDR *xdrs;
+xdrmem_getpos (xdrs)
+ XDR *xdrs;
{
- return ((u_long)xdrs->x_private - (u_long)xdrs->x_base);
+ return (u_long) xdrs->x_private - (u_long) xdrs->x_base;
}
static bool_t
-xdrmem_setpos(xdrs, pos)
- register XDR *xdrs;
- u_int pos;
+xdrmem_setpos (xdrs, pos)
+ XDR *xdrs;
+ u_int pos;
{
- register caddr_t newaddr = xdrs->x_base + pos;
- register caddr_t lastaddr = xdrs->x_private + xdrs->x_handy;
-
- if ((long)newaddr > (long)lastaddr)
- return (FALSE);
- xdrs->x_private = newaddr;
- xdrs->x_handy = (long)lastaddr - (long)newaddr;
- return (TRUE);
+ caddr_t newaddr = xdrs->x_base + pos;
+ caddr_t lastaddr = xdrs->x_private + xdrs->x_handy;
+
+ if ((long) newaddr > (long) lastaddr)
+ return FALSE;
+ xdrs->x_private = newaddr;
+ xdrs->x_handy = (long) lastaddr - (long) newaddr;
+ return TRUE;
}
static long *
-xdrmem_inline(xdrs, len)
- register XDR *xdrs;
- int len;
+xdrmem_inline (xdrs, len)
+ XDR *xdrs;
+ int len;
{
- long *buf = 0;
-
- if (xdrs->x_handy >= len) {
- xdrs->x_handy -= len;
- buf = (long *) xdrs->x_private;
- xdrs->x_private += len;
- }
- return (buf);
+ long *buf = 0;
+
+ if (xdrs->x_handy >= len)
+ {
+ xdrs->x_handy -= len;
+ buf = (long *) xdrs->x_private;
+ xdrs->x_private += len;
+ }
+ return buf;
}
*/
#include <stdio.h>
-#include <rpc/types.h>
-#include <rpc/xdr.h>
-#include <netinet/in.h>
-
-extern long lseek();
-
-static u_int fix_buf_size();
-
-static bool_t xdrrec_getlong();
-static bool_t xdrrec_putlong();
-static bool_t xdrrec_getbytes();
-static bool_t xdrrec_putbytes();
-static u_int xdrrec_getpos();
-static bool_t xdrrec_setpos();
-static long * xdrrec_inline();
-static void xdrrec_destroy();
-
-static struct xdr_ops xdrrec_ops = {
- xdrrec_getlong,
- xdrrec_putlong,
- xdrrec_getbytes,
- xdrrec_putbytes,
- xdrrec_getpos,
- xdrrec_setpos,
- xdrrec_inline,
- xdrrec_destroy
+#include <string.h>
+#include <unistd.h>
+#include <rpc/rpc.h>
+
+static bool_t xdrrec_getlong (XDR *, long *);
+static bool_t xdrrec_putlong (XDR *, long *);
+static bool_t xdrrec_getbytes (XDR *, caddr_t, u_int);
+static bool_t xdrrec_putbytes (XDR *, caddr_t, u_int);
+static u_int xdrrec_getpos (XDR *);
+static bool_t xdrrec_setpos (XDR *, u_int);
+static long *xdrrec_inline (XDR *, int);
+static void xdrrec_destroy (XDR *);
+
+static const struct xdr_ops xdrrec_ops =
+{
+ xdrrec_getlong,
+ xdrrec_putlong,
+ xdrrec_getbytes,
+ xdrrec_putbytes,
+ xdrrec_getpos,
+ xdrrec_setpos,
+ xdrrec_inline,
+ xdrrec_destroy
};
/*
#define LAST_FRAG (1UL << 31)
-typedef struct rec_strm {
- caddr_t tcp_handle;
- caddr_t the_buffer;
- /*
- * out-going bits
- */
- int (*writeit)();
- caddr_t out_base; /* output buffer (points to frag header) */
- caddr_t out_finger; /* next output position */
- caddr_t out_boundry; /* data cannot up to this address */
- u_int32_t *frag_header; /* beginning of curren fragment */
- bool_t frag_sent; /* true if buffer sent in middle of record */
- /*
- * in-coming bits
- */
- int (*readit)();
- u_long in_size; /* fixed size of the input buffer */
- caddr_t in_base;
- caddr_t in_finger; /* location of next byte to be had */
- caddr_t in_boundry; /* can read up to this location */
- long fbtbc; /* fragment bytes to be consumed */
- bool_t last_frag;
- u_int sendsize;
- u_int recvsize;
-} RECSTREAM;
-
+typedef struct rec_strm
+ {
+ caddr_t tcp_handle;
+ caddr_t the_buffer;
+ /*
+ * out-going bits
+ */
+ int (*writeit) (char *, char *, int);
+ caddr_t out_base; /* output buffer (points to frag header) */
+ caddr_t out_finger; /* next output position */
+ caddr_t out_boundry; /* data cannot up to this address */
+ u_int32_t *frag_header; /* beginning of curren fragment */
+ bool_t frag_sent; /* true if buffer sent in middle of record */
+ /*
+ * in-coming bits
+ */
+ int (*readit) (char *, char *, int);
+ u_long in_size; /* fixed size of the input buffer */
+ caddr_t in_base;
+ caddr_t in_finger; /* location of next byte to be had */
+ caddr_t in_boundry; /* can read up to this location */
+ long fbtbc; /* fragment bytes to be consumed */
+ bool_t last_frag;
+ u_int sendsize;
+ u_int recvsize;
+ }
+RECSTREAM;
+
+static u_int fix_buf_size (u_int);
+static bool_t skip_input_bytes (RECSTREAM *, long);
+static bool_t flush_out (RECSTREAM *, bool_t);
+static bool_t set_input_fragment (RECSTREAM *);
+static bool_t get_input_bytes (RECSTREAM *, caddr_t, int);
/*
* Create an xdr handle for xdrrec
* calls expect that they take an opaque handle rather than an fd.
*/
void
-xdrrec_create(xdrs, sendsize, recvsize, tcp_handle, readit, writeit)
- register XDR *xdrs;
- register u_int sendsize;
- register u_int recvsize;
- caddr_t tcp_handle;
- int (*readit)(); /* like read, but pass it a tcp_handle, not sock */
- int (*writeit)(); /* like write, but pass it a tcp_handle, not sock */
+xdrrec_create (XDR *xdrs, u_int sendsize,
+ u_int recvsize, caddr_t tcp_handle,
+ int (*readit) (char *, char *, int),
+ int (*writeit) (char *, char *, int))
{
- register RECSTREAM *rstrm =
- (RECSTREAM *)mem_alloc(sizeof(RECSTREAM));
-
- if (rstrm == NULL) {
- (void)fprintf(stderr, "xdrrec_create: out of memory\n");
- /*
- * This is bad. Should rework xdrrec_create to
- * return a handle, and in this case return NULL
- */
- return;
- }
- /*
- * adjust sizes and allocate buffer quad byte aligned
- */
- rstrm->sendsize = sendsize = fix_buf_size(sendsize);
- rstrm->recvsize = recvsize = fix_buf_size(recvsize);
- rstrm->the_buffer = mem_alloc(sendsize + recvsize + BYTES_PER_XDR_UNIT);
- if (rstrm->the_buffer == NULL) {
- (void)fprintf(stderr, "xdrrec_create: out of memory\n");
- return;
- }
- for (rstrm->out_base = rstrm->the_buffer;
- (u_int)rstrm->out_base % BYTES_PER_XDR_UNIT != 0;
- rstrm->out_base++);
- rstrm->in_base = rstrm->out_base + sendsize;
- /*
- * now the rest ...
- */
- xdrs->x_ops = &xdrrec_ops;
- xdrs->x_private = (caddr_t)rstrm;
- rstrm->tcp_handle = tcp_handle;
- rstrm->readit = readit;
- rstrm->writeit = writeit;
- rstrm->out_finger = rstrm->out_boundry = rstrm->out_base;
- rstrm->frag_header = (u_int32_t *)rstrm->out_base;
- rstrm->out_finger += 4;
- rstrm->out_boundry += sendsize;
- rstrm->frag_sent = FALSE;
- rstrm->in_size = recvsize;
- rstrm->in_boundry = rstrm->in_base;
- rstrm->in_finger = (rstrm->in_boundry += recvsize);
- rstrm->fbtbc = 0;
- rstrm->last_frag = TRUE;
+ RECSTREAM *rstrm =
+ (RECSTREAM *) mem_alloc (sizeof (RECSTREAM));
+
+ if (rstrm == NULL)
+ {
+ (void) fputs (_("xdrrec_create: out of memory\n"), stderr);
+ /*
+ * This is bad. Should rework xdrrec_create to
+ * return a handle, and in this case return NULL
+ */
+ return;
+ }
+ /*
+ * adjust sizes and allocate buffer quad byte aligned
+ */
+ rstrm->sendsize = sendsize = fix_buf_size (sendsize);
+ rstrm->recvsize = recvsize = fix_buf_size (recvsize);
+ rstrm->the_buffer = mem_alloc (sendsize + recvsize + BYTES_PER_XDR_UNIT);
+ if (rstrm->the_buffer == NULL)
+ {
+ (void) fputs (_("xdrrec_create: out of memory\n"), stderr);
+ return;
+ }
+ for (rstrm->out_base = rstrm->the_buffer;
+ (u_int) rstrm->out_base % BYTES_PER_XDR_UNIT != 0;
+ rstrm->out_base++);
+ rstrm->in_base = rstrm->out_base + sendsize;
+ /*
+ * now the rest ...
+ */
+ xdrs->x_ops = &xdrrec_ops;
+ xdrs->x_private = (caddr_t) rstrm;
+ rstrm->tcp_handle = tcp_handle;
+ rstrm->readit = readit;
+ rstrm->writeit = writeit;
+ rstrm->out_finger = rstrm->out_boundry = rstrm->out_base;
+ rstrm->frag_header = (u_int32_t *) rstrm->out_base;
+ rstrm->out_finger += 4;
+ rstrm->out_boundry += sendsize;
+ rstrm->frag_sent = FALSE;
+ rstrm->in_size = recvsize;
+ rstrm->in_boundry = rstrm->in_base;
+ rstrm->in_finger = (rstrm->in_boundry += recvsize);
+ rstrm->fbtbc = 0;
+ rstrm->last_frag = TRUE;
}
*/
static bool_t
-xdrrec_getlong(xdrs, lp)
- XDR *xdrs;
- long *lp;
+xdrrec_getlong (xdrs, lp)
+ XDR *xdrs;
+ long *lp;
{
- register RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
- register int32_t *buflp = (int32_t *) rstrm->in_finger;
- int32_t mylong;
-
- /* first try the inline, fast case */
- if (rstrm->fbtbc >= BYTES_PER_XDR_UNIT &&
- rstrm->in_boundry - (char *) buflp >= BYTES_PER_XDR_UNIT)
- {
- *lp = (int32_t) ntohl(*buflp);
- rstrm->fbtbc -= BYTES_PER_XDR_UNIT;
- rstrm->in_finger += BYTES_PER_XDR_UNIT;
- } else {
- if (! xdrrec_getbytes(xdrs, (caddr_t) &mylong,
- BYTES_PER_XDR_UNIT))
- return FALSE;
- *lp = (int32_t) ntohl(mylong);
- }
- return TRUE;
+ RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
+ int32_t *buflp = (int32_t *) rstrm->in_finger;
+ int32_t mylong;
+
+ /* first try the inline, fast case */
+ if (rstrm->fbtbc >= BYTES_PER_XDR_UNIT &&
+ rstrm->in_boundry - (char *) buflp >= BYTES_PER_XDR_UNIT)
+ {
+ *lp = (int32_t) ntohl (*buflp);
+ rstrm->fbtbc -= BYTES_PER_XDR_UNIT;
+ rstrm->in_finger += BYTES_PER_XDR_UNIT;
+ }
+ else
+ {
+ if (!xdrrec_getbytes (xdrs, (caddr_t) & mylong,
+ BYTES_PER_XDR_UNIT))
+ return FALSE;
+ *lp = (int32_t) ntohl (mylong);
+ }
+ return TRUE;
}
static bool_t
-xdrrec_putlong(xdrs, lp)
- XDR *xdrs;
- long *lp;
+xdrrec_putlong (xdrs, lp)
+ XDR *xdrs;
+ long *lp;
{
- register RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
- register int32_t *dest_lp = (int32_t *) rstrm->out_finger;
-
- if ((rstrm->out_finger += BYTES_PER_XDR_UNIT) > rstrm->out_boundry) {
- /*
- * this case should almost never happen so the code is
- * inefficient
- */
- rstrm->out_finger -= BYTES_PER_XDR_UNIT;
- rstrm->frag_sent = TRUE;
- if (! flush_out(rstrm, FALSE))
- return FALSE;
- dest_lp = (int32_t *) rstrm->out_finger;
- rstrm->out_finger += BYTES_PER_XDR_UNIT;
- }
- *dest_lp = htonl(*lp);
- return TRUE;
+ RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
+ int32_t *dest_lp = (int32_t *) rstrm->out_finger;
+
+ if ((rstrm->out_finger += BYTES_PER_XDR_UNIT) > rstrm->out_boundry)
+ {
+ /*
+ * this case should almost never happen so the code is
+ * inefficient
+ */
+ rstrm->out_finger -= BYTES_PER_XDR_UNIT;
+ rstrm->frag_sent = TRUE;
+ if (!flush_out (rstrm, FALSE))
+ return FALSE;
+ dest_lp = (int32_t *) rstrm->out_finger;
+ rstrm->out_finger += BYTES_PER_XDR_UNIT;
+ }
+ *dest_lp = htonl (*lp);
+ return TRUE;
}
-static bool_t /* must manage buffers, fragments, and records */
-xdrrec_getbytes(xdrs, addr, len)
- XDR *xdrs;
- register caddr_t addr;
- register u_int len;
+static bool_t /* must manage buffers, fragments, and records */
+xdrrec_getbytes (xdrs, addr, len)
+ XDR *xdrs;
+ caddr_t addr;
+ u_int len;
{
- register RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
- register int current;
-
- while (len > 0) {
- current = rstrm->fbtbc;
- if (current == 0) {
- if (rstrm->last_frag)
- return FALSE;
- if (! set_input_fragment(rstrm))
- return FALSE;
- continue;
- }
- current = (len < current) ? len : current;
- if (! get_input_bytes(rstrm, addr, current))
- return FALSE;
- addr += current;
- rstrm->fbtbc -= current;
- len -= current;
+ RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
+ u_int current;
+
+ while (len > 0)
+ {
+ current = rstrm->fbtbc;
+ if (current == 0)
+ {
+ if (rstrm->last_frag)
+ return FALSE;
+ if (!set_input_fragment (rstrm))
+ return FALSE;
+ continue;
}
- return TRUE;
+ current = (len < current) ? len : current;
+ if (!get_input_bytes (rstrm, addr, current))
+ return FALSE;
+ addr += current;
+ rstrm->fbtbc -= current;
+ len -= current;
+ }
+ return TRUE;
}
static bool_t
-xdrrec_putbytes(xdrs, addr, len)
- XDR *xdrs;
- register caddr_t addr;
- register u_int len;
+xdrrec_putbytes (xdrs, addr, len)
+ XDR *xdrs;
+ caddr_t addr;
+ u_int len;
{
- register RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
- register int current;
-
- while (len > 0) {
- current = rstrm->out_boundry - rstrm->out_finger;
- current = (len < current) ? len : current;
- bcopy(addr, rstrm->out_finger, current);
- rstrm->out_finger += current;
- addr += current;
- len -= current;
- if (rstrm->out_finger == rstrm->out_boundry) {
- rstrm->frag_sent = TRUE;
- if (! flush_out(rstrm, FALSE))
- return FALSE;
- }
+ RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
+ u_int current;
+
+ while (len > 0)
+ {
+ current = rstrm->out_boundry - rstrm->out_finger;
+ current = (len < current) ? len : current;
+ bcopy (addr, rstrm->out_finger, current);
+ rstrm->out_finger += current;
+ addr += current;
+ len -= current;
+ if (rstrm->out_finger == rstrm->out_boundry)
+ {
+ rstrm->frag_sent = TRUE;
+ if (!flush_out (rstrm, FALSE))
+ return FALSE;
}
- return TRUE;
+ }
+ return TRUE;
}
static u_int
-xdrrec_getpos(xdrs)
- register XDR *xdrs;
+xdrrec_getpos (XDR *xdrs)
{
- register RECSTREAM *rstrm = (RECSTREAM *)xdrs->x_private;
- register long pos;
-
- pos = lseek((int)rstrm->tcp_handle, (long) 0, 1);
- if (pos != -1)
- switch (xdrs->x_op) {
-
- case XDR_ENCODE:
- pos += rstrm->out_finger - rstrm->out_base;
- break;
-
- case XDR_DECODE:
- pos -= rstrm->in_boundry - rstrm->in_finger;
- break;
-
- default:
- pos = (u_int) -1;
- break;
- }
- return ((u_int) pos);
+ RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
+ long pos;
+
+ pos = lseek ((int) rstrm->tcp_handle, (long) 0, 1);
+ if (pos != -1)
+ switch (xdrs->x_op)
+ {
+
+ case XDR_ENCODE:
+ pos += rstrm->out_finger - rstrm->out_base;
+ break;
+
+ case XDR_DECODE:
+ pos -= rstrm->in_boundry - rstrm->in_finger;
+ break;
+
+ default:
+ pos = (u_int) - 1;
+ break;
+ }
+ return (u_int) pos;
}
static bool_t
-xdrrec_setpos(xdrs, pos)
- register XDR *xdrs;
- u_int pos;
+xdrrec_setpos (xdrs, pos)
+ XDR *xdrs;
+ u_int pos;
{
- register RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
- u_int currpos = xdrrec_getpos(xdrs);
- int delta = currpos - pos;
- caddr_t newpos;
-
- if ((int)currpos != -1)
- switch (xdrs->x_op) {
-
- case XDR_ENCODE:
- newpos = rstrm->out_finger - delta;
- if (newpos > (caddr_t) rstrm->frag_header &&
- newpos < rstrm->out_boundry)
- {
- rstrm->out_finger = newpos;
- return TRUE;
- }
- break;
-
- case XDR_DECODE:
- newpos = rstrm->in_finger - delta;
- if ((delta < (int)(rstrm->fbtbc)) &&
- (newpos <= rstrm->in_boundry) &&
- (newpos >= rstrm->in_base)) {
- rstrm->in_finger = newpos;
- rstrm->fbtbc -= delta;
- return TRUE;
- }
- break;
- }
- return FALSE;
+ RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
+ u_int currpos = xdrrec_getpos (xdrs);
+ int delta = currpos - pos;
+ caddr_t newpos;
+
+ if ((int) currpos != -1)
+ switch (xdrs->x_op)
+ {
+
+ case XDR_ENCODE:
+ newpos = rstrm->out_finger - delta;
+ if (newpos > (caddr_t) rstrm->frag_header &&
+ newpos < rstrm->out_boundry)
+ {
+ rstrm->out_finger = newpos;
+ return TRUE;
+ }
+ break;
+
+ case XDR_DECODE:
+ newpos = rstrm->in_finger - delta;
+ if ((delta < (int) (rstrm->fbtbc)) &&
+ (newpos <= rstrm->in_boundry) &&
+ (newpos >= rstrm->in_base))
+ {
+ rstrm->in_finger = newpos;
+ rstrm->fbtbc -= delta;
+ return TRUE;
+ }
+ break;
+
+ default:
+ break;
+ }
+ return FALSE;
}
static long *
-xdrrec_inline(xdrs, len)
- register XDR *xdrs;
- int len;
+xdrrec_inline (XDR *xdrs, int len)
{
- register RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
- long * buf = NULL;
-
- switch (xdrs->x_op) {
-
- case XDR_ENCODE:
- if ((rstrm->out_finger + len) <= rstrm->out_boundry) {
- buf = (long *) rstrm->out_finger;
- rstrm->out_finger += len;
- }
- break;
-
- case XDR_DECODE:
- if ((len <= rstrm->fbtbc) &&
- ((rstrm->in_finger + len) <= rstrm->in_boundry)) {
- buf = (long *) rstrm->in_finger;
- rstrm->fbtbc -= len;
- rstrm->in_finger += len;
- }
- break;
+ RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
+ long *buf = NULL;
+
+ switch (xdrs->x_op)
+ {
+
+ case XDR_ENCODE:
+ if ((rstrm->out_finger + len) <= rstrm->out_boundry)
+ {
+ buf = (long *) rstrm->out_finger;
+ rstrm->out_finger += len;
+ }
+ break;
+
+ case XDR_DECODE:
+ if ((len <= rstrm->fbtbc) &&
+ ((rstrm->in_finger + len) <= rstrm->in_boundry))
+ {
+ buf = (long *) rstrm->in_finger;
+ rstrm->fbtbc -= len;
+ rstrm->in_finger += len;
}
- return buf;
+ break;
+
+ default:
+ break;
+ }
+ return buf;
}
static void
-xdrrec_destroy(xdrs)
- register XDR *xdrs;
+xdrrec_destroy (xdrs)
+ XDR *xdrs;
{
- register RECSTREAM *rstrm = (RECSTREAM *)xdrs->x_private;
+ RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
- mem_free(rstrm->the_buffer,
- rstrm->sendsize + rstrm->recvsize + BYTES_PER_XDR_UNIT);
- mem_free((caddr_t)rstrm, sizeof(RECSTREAM));
+ mem_free (rstrm->the_buffer,
+ rstrm->sendsize + rstrm->recvsize + BYTES_PER_XDR_UNIT);
+ mem_free ((caddr_t) rstrm, sizeof (RECSTREAM));
}
* this procedure to guarantee proper record alignment.
*/
bool_t
-xdrrec_skiprecord(xdrs)
- XDR *xdrs;
+xdrrec_skiprecord (xdrs)
+ XDR *xdrs;
{
- register RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
-
- while (rstrm->fbtbc > 0 || (! rstrm->last_frag)) {
- if (! skip_input_bytes(rstrm, rstrm->fbtbc))
- return FALSE;
- rstrm->fbtbc = 0;
- if ((! rstrm->last_frag) && (! set_input_fragment(rstrm)))
- return FALSE;
- }
- rstrm->last_frag = FALSE;
- return TRUE;
+ RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
+
+ while (rstrm->fbtbc > 0 || (!rstrm->last_frag))
+ {
+ if (!skip_input_bytes (rstrm, rstrm->fbtbc))
+ return FALSE;
+ rstrm->fbtbc = 0;
+ if ((!rstrm->last_frag) && (!set_input_fragment (rstrm)))
+ return FALSE;
+ }
+ rstrm->last_frag = FALSE;
+ return TRUE;
}
/*
* after consuming the rest of the current record.
*/
bool_t
-xdrrec_eof(xdrs)
- XDR *xdrs;
+xdrrec_eof (xdrs)
+ XDR *xdrs;
{
- register RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
-
- while (rstrm->fbtbc > 0 || (! rstrm->last_frag)) {
- if (! skip_input_bytes(rstrm, rstrm->fbtbc))
- return TRUE;
- rstrm->fbtbc = 0;
- if ((! rstrm->last_frag) && (! set_input_fragment(rstrm)))
- return TRUE;
- }
- if (rstrm->in_finger == rstrm->in_boundry)
- return TRUE;
- return FALSE;
+ RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
+
+ while (rstrm->fbtbc > 0 || (!rstrm->last_frag))
+ {
+ if (!skip_input_bytes (rstrm, rstrm->fbtbc))
+ return TRUE;
+ rstrm->fbtbc = 0;
+ if ((!rstrm->last_frag) && (!set_input_fragment (rstrm)))
+ return TRUE;
+ }
+ if (rstrm->in_finger == rstrm->in_boundry)
+ return TRUE;
+ return FALSE;
}
/*
* pipelined procedure calls.) TRUE => immediate flush to tcp connection.
*/
bool_t
-xdrrec_endofrecord(xdrs, sendnow)
- XDR *xdrs;
- bool_t sendnow;
+xdrrec_endofrecord (xdrs, sendnow)
+ XDR *xdrs;
+ bool_t sendnow;
{
- register RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
- register u_long len; /* fragment length */
-
- if (sendnow || rstrm->frag_sent
- || rstrm->out_finger + BYTES_PER_XDR_UNIT >= rstrm->out_boundry)
- {
- rstrm->frag_sent = FALSE;
- return flush_out(rstrm, TRUE);
- }
- len = (rstrm->out_finger - (char *) rstrm->frag_header
- - BYTES_PER_XDR_UNIT);
- *rstrm->frag_header = htonl((u_long)len | LAST_FRAG);
- rstrm->frag_header = (u_int32_t *) rstrm->out_finger;
- rstrm->out_finger += BYTES_PER_XDR_UNIT;
- return TRUE;
+ RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
+ u_long len; /* fragment length */
+
+ if (sendnow || rstrm->frag_sent
+ || rstrm->out_finger + BYTES_PER_XDR_UNIT >= rstrm->out_boundry)
+ {
+ rstrm->frag_sent = FALSE;
+ return flush_out (rstrm, TRUE);
+ }
+ len = (rstrm->out_finger - (char *) rstrm->frag_header
+ - BYTES_PER_XDR_UNIT);
+ *rstrm->frag_header = htonl ((u_long) len | LAST_FRAG);
+ rstrm->frag_header = (u_int32_t *) rstrm->out_finger;
+ rstrm->out_finger += BYTES_PER_XDR_UNIT;
+ return TRUE;
}
* Internal useful routines
*/
static bool_t
-flush_out(rstrm, eor)
- register RECSTREAM *rstrm;
- bool_t eor;
+flush_out (RECSTREAM *rstrm, bool_t eor)
{
- register u_long eormask = (eor == TRUE) ? LAST_FRAG : 0;
- register u_long len = (rstrm->out_finger
- - (char *) rstrm->frag_header
- - BYTES_PER_XDR_UNIT);
-
- *rstrm->frag_header = htonl(len | eormask);
- len = rstrm->out_finger - rstrm->out_base;
- if ((*(rstrm->writeit))(rstrm->tcp_handle, rstrm->out_base, (int)len)
- != (int)len)
- return FALSE;
- rstrm->frag_header = (u_int32_t *) rstrm->out_base;
- rstrm->out_finger = (caddr_t) rstrm->out_base + BYTES_PER_XDR_UNIT;
- return TRUE;
+ u_long eormask = (eor == TRUE) ? LAST_FRAG : 0;
+ u_long len = (rstrm->out_finger - (char *) rstrm->frag_header
+ - BYTES_PER_XDR_UNIT);
+
+ *rstrm->frag_header = htonl (len | eormask);
+ len = rstrm->out_finger - rstrm->out_base;
+ if ((*(rstrm->writeit)) (rstrm->tcp_handle, rstrm->out_base, (int) len)
+ != (int) len)
+ return FALSE;
+ rstrm->frag_header = (u_int32_t *) rstrm->out_base;
+ rstrm->out_finger = (caddr_t) rstrm->out_base + BYTES_PER_XDR_UNIT;
+ return TRUE;
}
-static bool_t /* knows nothing about records! Only about input buffers */
-fill_input_buf(rstrm)
- register RECSTREAM *rstrm;
+static bool_t /* knows nothing about records! Only about input buffers */
+fill_input_buf (RECSTREAM *rstrm)
{
- register caddr_t where;
- u_int i;
- register int len;
-
- where = rstrm->in_base;
- i = (u_int)rstrm->in_boundry % BYTES_PER_XDR_UNIT;
- where += i;
- len = rstrm->in_size - i;
- if ((len = (*(rstrm->readit))(rstrm->tcp_handle, where, len)) == -1)
- return FALSE;
- rstrm->in_finger = where;
- where += len;
- rstrm->in_boundry = where;
- return TRUE;
+ caddr_t where;
+ u_int i;
+ int len;
+
+ where = rstrm->in_base;
+ i = (u_int) rstrm->in_boundry % BYTES_PER_XDR_UNIT;
+ where += i;
+ len = rstrm->in_size - i;
+ if ((len = (*(rstrm->readit)) (rstrm->tcp_handle, where, len)) == -1)
+ return FALSE;
+ rstrm->in_finger = where;
+ where += len;
+ rstrm->in_boundry = where;
+ return TRUE;
}
-static bool_t /* knows nothing about records! Only about input buffers */
-get_input_bytes(rstrm, addr, len)
- register RECSTREAM *rstrm;
- register caddr_t addr;
- register int len;
+static bool_t /* knows nothing about records! Only about input buffers */
+get_input_bytes (RECSTREAM *rstrm, caddr_t addr, int len)
{
- register int current;
-
- while (len > 0) {
- current = rstrm->in_boundry - rstrm->in_finger;
- if (current == 0) {
- if (! fill_input_buf(rstrm))
- return FALSE;
- continue;
- }
- current = (len < current) ? len : current;
- bcopy(rstrm->in_finger, addr, current);
- rstrm->in_finger += current;
- addr += current;
- len -= current;
+ int current;
+
+ while (len > 0)
+ {
+ current = rstrm->in_boundry - rstrm->in_finger;
+ if (current == 0)
+ {
+ if (!fill_input_buf (rstrm))
+ return FALSE;
+ continue;
}
- return TRUE;
+ current = (len < current) ? len : current;
+ bcopy (rstrm->in_finger, addr, current);
+ rstrm->in_finger += current;
+ addr += current;
+ len -= current;
+ }
+ return TRUE;
}
-static bool_t /* next two bytes of the input stream are treated as a header */
-set_input_fragment(rstrm)
- register RECSTREAM *rstrm;
+static bool_t /* next two bytes of the input stream are treated as a header */
+set_input_fragment (RECSTREAM *rstrm)
{
- u_long header;
-
- if (! get_input_bytes(rstrm, (caddr_t)&header, BYTES_PER_XDR_UNIT))
- return FALSE;
- header = ntohl(header);
- rstrm->last_frag = ((header & LAST_FRAG) == 0) ? FALSE : TRUE;
- rstrm->fbtbc = header & ~LAST_FRAG;
- return TRUE;
+ u_long header;
+
+ if (!get_input_bytes (rstrm, (caddr_t) & header, BYTES_PER_XDR_UNIT))
+ return FALSE;
+ header = ntohl (header);
+ rstrm->last_frag = ((header & LAST_FRAG) == 0) ? FALSE : TRUE;
+ rstrm->fbtbc = header & ~LAST_FRAG;
+ return TRUE;
}
-static bool_t /* consumes input bytes; knows nothing about records! */
-skip_input_bytes(rstrm, cnt)
- register RECSTREAM *rstrm;
- long cnt;
+static bool_t /* consumes input bytes; knows nothing about records! */
+skip_input_bytes (RECSTREAM *rstrm, long cnt)
{
- register int current;
-
- while (cnt > 0) {
- current = rstrm->in_boundry - rstrm->in_finger;
- if (current == 0) {
- if (! fill_input_buf(rstrm))
- return FALSE;
- continue;
- }
- current = (cnt < current) ? cnt : current;
- rstrm->in_finger += current;
- cnt -= current;
+ int current;
+
+ while (cnt > 0)
+ {
+ current = rstrm->in_boundry - rstrm->in_finger;
+ if (current == 0)
+ {
+ if (!fill_input_buf (rstrm))
+ return FALSE;
+ continue;
}
- return TRUE;
+ current = (cnt < current) ? cnt : current;
+ rstrm->in_finger += current;
+ cnt -= current;
+ }
+ return TRUE;
}
static u_int
-fix_buf_size(s)
- register u_int s;
+fix_buf_size (u_int s)
{
-
- if (s < 100)
- s = 4000;
- return RNDUP(s);
+ if (s < 100)
+ s = 4000;
+ return RNDUP (s);
}
*/
#include <stdio.h>
+#include <string.h>
#include <rpc/types.h>
#include <rpc/xdr.h>
* proc is the routine to handle the referenced structure.
*/
bool_t
-xdr_reference(xdrs, pp, size, proc)
- register XDR *xdrs;
- caddr_t *pp; /* the pointer to work on */
- u_int size; /* size of the object pointed to */
- xdrproc_t proc; /* xdr routine to handle the object */
+xdr_reference (xdrs, pp, size, proc)
+ XDR *xdrs;
+ caddr_t *pp; /* the pointer to work on */
+ u_int size; /* size of the object pointed to */
+ xdrproc_t proc; /* xdr routine to handle the object */
{
- register caddr_t loc = *pp;
- register bool_t stat;
+ caddr_t loc = *pp;
+ bool_t stat;
- if (loc == NULL)
- switch (xdrs->x_op) {
- case XDR_FREE:
- return (TRUE);
+ if (loc == NULL)
+ switch (xdrs->x_op)
+ {
+ case XDR_FREE:
+ return TRUE;
- case XDR_DECODE:
- *pp = loc = (caddr_t) mem_alloc(size);
- if (loc == NULL) {
- (void) fprintf(stderr,
- "xdr_reference: out of memory\n");
- return (FALSE);
- }
- bzero(loc, (int)size);
- break;
- }
+ case XDR_DECODE:
+ *pp = loc = (caddr_t) mem_alloc (size);
+ if (loc == NULL)
+ {
+ (void) fputs (_("xdr_reference: out of memory\n"), stderr);
+ return FALSE;
+ }
+ bzero (loc, (int) size);
+ break;
+ default:
+ break;
+ }
- stat = (*proc)(xdrs, loc, LASTUNSIGNED);
+ stat = (*proc) (xdrs, loc, LASTUNSIGNED);
- if (xdrs->x_op == XDR_FREE) {
- mem_free(loc, size);
- *pp = NULL;
- }
- return (stat);
+ if (xdrs->x_op == XDR_FREE)
+ {
+ mem_free (loc, size);
+ *pp = NULL;
+ }
+ return stat;
}
*
*/
bool_t
-xdr_pointer(xdrs,objpp,obj_size,xdr_obj)
- register XDR *xdrs;
- char **objpp;
- u_int obj_size;
- xdrproc_t xdr_obj;
+xdr_pointer (xdrs, objpp, obj_size, xdr_obj)
+ XDR *xdrs;
+ char **objpp;
+ u_int obj_size;
+ xdrproc_t xdr_obj;
{
- bool_t more_data;
+ bool_t more_data;
- more_data = (*objpp != NULL);
- if (! xdr_bool(xdrs,&more_data)) {
- return (FALSE);
- }
- if (! more_data) {
- *objpp = NULL;
- return (TRUE);
- }
- return (xdr_reference(xdrs,objpp,obj_size,xdr_obj));
+ more_data = (*objpp != NULL);
+ if (!xdr_bool (xdrs, &more_data))
+ {
+ return FALSE;
+ }
+ if (!more_data)
+ {
+ *objpp = NULL;
+ return TRUE;
+ }
+ return xdr_reference (xdrs, objpp, obj_size, xdr_obj);
}
#include <stdio.h>
#include <rpc/xdr.h>
-static bool_t xdrstdio_getlong();
-static bool_t xdrstdio_putlong();
-static bool_t xdrstdio_getbytes();
-static bool_t xdrstdio_putbytes();
-static u_int xdrstdio_getpos();
-static bool_t xdrstdio_setpos();
-static long * xdrstdio_inline();
-static void xdrstdio_destroy();
+static bool_t xdrstdio_getlong (XDR *, long *);
+static bool_t xdrstdio_putlong (XDR *, long *);
+static bool_t xdrstdio_getbytes (XDR *, caddr_t, u_int);
+static bool_t xdrstdio_putbytes (XDR *, caddr_t, u_int);
+static u_int xdrstdio_getpos (XDR *);
+static bool_t xdrstdio_setpos (XDR *, u_int);
+static long *xdrstdio_inline (XDR *, int);
+static void xdrstdio_destroy (XDR *);
/*
* Ops vector for stdio type XDR
*/
-static struct xdr_ops xdrstdio_ops = {
- xdrstdio_getlong, /* deserialize a long int */
- xdrstdio_putlong, /* serialize a long int */
- xdrstdio_getbytes, /* deserialize counted bytes */
- xdrstdio_putbytes, /* serialize counted bytes */
- xdrstdio_getpos, /* get offset in the stream */
- xdrstdio_setpos, /* set offset in the stream */
- xdrstdio_inline, /* prime stream for inline macros */
- xdrstdio_destroy /* destroy stream */
+static const struct xdr_ops xdrstdio_ops =
+{
+ xdrstdio_getlong, /* deserialize a long int */
+ xdrstdio_putlong, /* serialize a long int */
+ xdrstdio_getbytes, /* deserialize counted bytes */
+ xdrstdio_putbytes, /* serialize counted bytes */
+ xdrstdio_getpos, /* get offset in the stream */
+ xdrstdio_setpos, /* set offset in the stream */
+ xdrstdio_inline, /* prime stream for inline macros */
+ xdrstdio_destroy /* destroy stream */
};
/*
* Operation flag is set to op.
*/
void
-xdrstdio_create(xdrs, file, op)
- register XDR *xdrs;
- FILE *file;
- enum xdr_op op;
+xdrstdio_create (xdrs, file, op)
+ XDR *xdrs;
+ FILE *file;
+ enum xdr_op op;
{
- xdrs->x_op = op;
- xdrs->x_ops = &xdrstdio_ops;
- xdrs->x_private = (caddr_t)file;
- xdrs->x_handy = 0;
- xdrs->x_base = 0;
+ xdrs->x_op = op;
+ xdrs->x_ops = &xdrstdio_ops;
+ xdrs->x_private = (caddr_t) file;
+ xdrs->x_handy = 0;
+ xdrs->x_base = 0;
}
/*
* Cleans up the xdr stream handle xdrs previously set up by xdrstdio_create.
*/
static void
-xdrstdio_destroy(xdrs)
- register XDR *xdrs;
+xdrstdio_destroy (xdrs)
+ XDR *xdrs;
{
- (void)fflush((FILE *)xdrs->x_private);
- /* xx should we close the file ?? */
+ (void) fflush ((FILE *) xdrs->x_private);
+ /* xx should we close the file ?? */
};
static bool_t
-xdrstdio_getlong(xdrs, lp)
- XDR *xdrs;
- register long *lp;
+xdrstdio_getlong (xdrs, lp)
+ XDR *xdrs;
+ long *lp;
{
- int32_t mycopy;
+ int32_t mycopy;
- if (fread((caddr_t)&mycopy, 4, 1, (FILE *)xdrs->x_private) != 1)
- return (FALSE);
- *lp = (int32_t) ntohl(mycopy);
- return (TRUE);
+ if (fread ((caddr_t) & mycopy, 4, 1, (FILE *) xdrs->x_private) != 1)
+ return FALSE;
+ *lp = (int32_t) ntohl (mycopy);
+ return TRUE;
}
static bool_t
-xdrstdio_putlong(xdrs, lp)
- XDR *xdrs;
- long *lp;
+xdrstdio_putlong (XDR *xdrs, long *lp)
{
- int32_t mycopy = htonl(*lp);
- lp = &mycopy;
- if (fwrite((caddr_t)lp, 4, 1, (FILE *)xdrs->x_private) != 1)
- return (FALSE);
- return (TRUE);
+ long mycopy = htonl (*lp);
+ lp = &mycopy;
+ if (fwrite ((caddr_t) lp, 4, 1, (FILE *) xdrs->x_private) != 1)
+ return FALSE;
+ return TRUE;
}
static bool_t
-xdrstdio_getbytes(xdrs, addr, len)
- XDR *xdrs;
- caddr_t addr;
- u_int len;
+xdrstdio_getbytes (xdrs, addr, len)
+ XDR *xdrs;
+ caddr_t addr;
+ u_int len;
{
- if ((len != 0) && (fread(addr, (int)len, 1, (FILE *)xdrs->x_private) != 1))
- return (FALSE);
- return (TRUE);
+ if ((len != 0) && (fread (addr, (int) len, 1, (FILE *) xdrs->x_private) != 1))
+ return FALSE;
+ return TRUE;
}
static bool_t
-xdrstdio_putbytes(xdrs, addr, len)
- XDR *xdrs;
- caddr_t addr;
- u_int len;
+xdrstdio_putbytes (XDR *xdrs, caddr_t addr, u_int len)
{
-
- if ((len != 0) && (fwrite(addr, (int)len, 1, (FILE *)xdrs->x_private) != 1))
- return (FALSE);
- return (TRUE);
+ if ((len != 0) && (fwrite (addr, (int) len, 1, (FILE *) xdrs->x_private) != 1))
+ return FALSE;
+ return TRUE;
}
static u_int
-xdrstdio_getpos(xdrs)
- XDR *xdrs;
+xdrstdio_getpos (XDR *xdrs)
{
-
- return ((u_int) ftell((FILE *)xdrs->x_private));
+ return (u_int) ftell ((FILE *) xdrs->x_private);
}
static bool_t
-xdrstdio_setpos(xdrs, pos)
- XDR *xdrs;
- u_int pos;
+xdrstdio_setpos (XDR *xdrs, u_int pos)
{
-
- return ((fseek((FILE *)xdrs->x_private, (long)pos, 0) < 0) ?
- FALSE : TRUE);
+ return fseek ((FILE *) xdrs->x_private, (long) pos, 0) < 0 ? FALSE : TRUE;
}
static long *
-xdrstdio_inline(xdrs, len)
- XDR *xdrs;
- u_int len;
+xdrstdio_inline (XDR *xdrs, int len)
{
- /*
- * Must do some work to implement this: must insure
- * enough data in the underlying stdio buffer,
- * that the buffer is aligned so that we can indirect through a
- * long *, and stuff this pointer in xdrs->x_buf. Doing
- * a fread or fwrite to a scratch buffer would defeat
- * most of the gains to be had here and require storage
- * management on this buffer, so we don't do this.
- */
- return (NULL);
+ /*
+ * Must do some work to implement this: must insure
+ * enough data in the underlying stdio buffer,
+ * that the buffer is aligned so that we can indirect through a
+ * long *, and stuff this pointer in xdrs->x_buf. Doing
+ * a fread or fwrite to a scratch buffer would defeat
+ * most of the gains to be had here and require storage
+ * management on this buffer, so we don't do this.
+ */
+ return NULL;
}