#if defined(LIBC_SCCS) && !defined(lint)
/*static char *sccsid = "from: @(#)svc_udp.c 1.24 87/08/11 Copyr 1984 Sun Micro";*/
/*static char *sccsid = "from: @(#)svc_udp.c 2.2 88/07/29 4.0 RPCSRC";*/
-static char *rcsid = "$Id: svc_udp.c,v 1.3 2002/02/19 20:36:25 epeyton Exp $";
+static char *rcsid = "$Id: svc_udp.c,v 1.5 2004/10/13 00:24:07 jkh Exp $";
#endif
/*
#include <stdio.h>
#include <stdlib.h>
+#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <rpc/rpc.h>
#include <sys/socket.h>
+#include <sys/param.h>
#include <errno.h>
extern int bindresvport();
*/
struct svcudp_data {
u_int su_iosz; /* byte size of send.recv buffer */
+#ifdef __LP64__
+ uint32_t su_xid; /* transaction id */
+#else
u_long su_xid; /* transaction id */
+#endif
XDR su_xdrs; /* XDR handle */
char su_verfbody[MAX_AUTH_BYTES]; /* verifier body */
char * su_cache; /* cached data, NULL if no cache */
register SVCXPRT *xprt;
register struct svcudp_data *su;
struct sockaddr_in addr;
- int len = sizeof(struct sockaddr_in);
+ unsigned int len = sizeof(struct sockaddr_in);
if (sock == RPC_ANYSOCK) {
if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
}
su = (struct svcudp_data *)mem_alloc(sizeof(*su));
if (su == NULL) {
+ mem_free(xprt, sizeof(SVCXPRT));
(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) {
+ mem_free(xprt, sizeof(SVCXPRT));
+ mem_free(su, sizeof(*su));
(void)fprintf(stderr, "svcudp_create: out of memory\n");
return (NULL);
}
return (XPRT_IDLE);
}
+static int cache_get();
+static void cache_set();
+
static bool_t
svcudp_recv(xprt, msg)
register SVCXPRT *xprt;
register XDR *xdrs = &(su->su_xdrs);
register int rlen;
char *reply;
+#ifdef __LP64__
+ uint32_t replylen;
+#else
u_long replylen;
- static int cache_get();
+#endif
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));
+ rlen = recvfrom(xprt->xp_sock, rpc_buffer(xprt), (int) su->su_iosz, 0, (struct sockaddr *)&(xprt->xp_raddr), (unsigned int *)&(xprt->xp_addrlen));
if (rlen == -1 && errno == EINTR)
goto again;
+#ifdef __LP64__
+ if (rlen < 4*sizeof(uint32_t))
+ return (FALSE);
+#else
if (rlen < 4*sizeof(u_long))
return (FALSE);
+#endif
xdrs->x_op = XDR_DECODE;
XDR_SETPOS(xdrs, 0);
if (! xdr_callmsg(xdrs, msg))
register XDR *xdrs = &(su->su_xdrs);
register int slen;
register bool_t stat = FALSE;
- static void cache_set();
xdrs->x_op = XDR_ENCODE;
XDR_SETPOS(xdrs, 0);
== slen) {
stat = TRUE;
if (su->su_cache && slen >= 0) {
+#ifdef __LP64__
+ cache_set(xprt, (uint32_t) slen);
+#else
cache_set(xprt, (u_long) slen);
+#endif
}
}
}
caddr_t args_ptr;
{
- return ((*xdr_args)(&(su_data(xprt)->su_xdrs), args_ptr));
+ return ((*xdr_args)(&(su_data(xprt)->su_xdrs), args_ptr, 0));
}
static bool_t
register XDR *xdrs = &(su_data(xprt)->su_xdrs);
xdrs->x_op = XDR_FREE;
- return ((*xdr_args)(xdrs, args_ptr));
+ return ((*xdr_args)(xdrs, args_ptr, 0));
}
static void
/*
* Index into cache is xid, proc, vers, prog and address
*/
+#ifdef __LP64__
+ uint32_t cache_xid;
+ uint32_t cache_proc;
+ uint32_t cache_vers;
+ uint32_t cache_prog;
+#else
u_long cache_xid;
u_long cache_proc;
u_long cache_vers;
u_long cache_prog;
+#endif
struct sockaddr_in cache_addr;
/*
* The cached reply and length
*/
char * cache_reply;
+#ifdef __LP64__
+ uint32_t cache_replylen;
+#else
u_long cache_replylen;
+#endif
/*
* Next node on the list, if there is a collision
*/
* The entire cache
*/
struct udp_cache {
+#ifdef __LP64__
+ uint32_t uc_size; /* size of cache */
+#else
u_long uc_size; /* size of cache */
+#endif
cache_ptr *uc_entries; /* hash table of entries in cache */
cache_ptr *uc_fifo; /* fifo list of entries in cache */
+#ifdef __LP64__
+ uint32_t uc_nextvictim; /* points to next victim in fifo list */
+ uint32_t uc_prog; /* saved program number */
+ uint32_t uc_vers; /* saved version number */
+ uint32_t uc_proc; /* saved procedure number */
+#else
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 */
+#endif
struct sockaddr_in uc_addr; /* saved caller's address */
};
int
svcudp_enablecache(transp, size)
SVCXPRT *transp;
+#ifdef __LP64__
+ uint32_t size;
+#else
u_long size;
+#endif
{
struct svcudp_data *su = su_data(transp);
struct udp_cache *uc;
uc->uc_nextvictim = 0;
uc->uc_entries = ALLOC(cache_ptr, size * SPARSENESS);
if (uc->uc_entries == NULL) {
+ mem_free(uc, sizeof(*uc));
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) {
+ mem_free(uc->uc_entries, sizeof(struct udp_cache)*size * SPARSENESS);
+ mem_free(uc, sizeof(struct udp_cache));
CACHE_PERROR("enablecache: could not allocate cache fifo");
return(0);
}
static void
cache_set(xprt, replylen)
SVCXPRT *xprt;
- u_long replylen;
+#ifdef __LP64__
+ uint32_t replylen;
+#else
+ u_long replylen;
+#endif
{
register cache_ptr victim;
register cache_ptr *vicp;
}
newbuf = mem_alloc(su->su_iosz);
if (newbuf == NULL) {
+ mem_free(victim, sizeof(*victim));
CACHE_PERROR("cache_set: could not allocate new rpc_buffer");
return;
}
SVCXPRT *xprt;
struct rpc_msg *msg;
char **replyp;
+#ifdef __LP64__
+ uint32_t *replylenp;
+#else
u_long *replylenp;
+#endif
{
u_int loc;
register cache_ptr ent;