X-Git-Url: https://git.saurik.com/apple/libinfo.git/blobdiff_plain/c29f2fccbf0d388644e29ea3e98c38a343688bd2..d90e699ca2566289cddc68cd0862d05780b54551:/rpc.subproj/svc_udp.c?ds=sidebyside diff --git a/rpc.subproj/svc_udp.c b/rpc.subproj/svc_udp.c index 5f836b4..ac83afc 100644 --- a/rpc.subproj/svc_udp.c +++ b/rpc.subproj/svc_udp.c @@ -66,6 +66,7 @@ static char *rcsid = "$Id: svc_udp.c,v 1.5 2004/10/13 00:24:07 jkh Exp $"; #include #include +#include #include #include #include @@ -100,7 +101,11 @@ extern int errno; */ 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 */ @@ -129,7 +134,7 @@ svcudp_bufcreate(sock, sendsz, recvsz) 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) { @@ -157,11 +162,14 @@ svcudp_bufcreate(sock, sendsz, recvsz) } 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); } @@ -205,16 +213,24 @@ svcudp_recv(xprt, msg) register XDR *xdrs = &(su->su_xdrs); register int rlen; char *reply; +#ifdef __LP64__ + uint32_t replylen; +#else u_long replylen; +#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)) @@ -250,7 +266,11 @@ svcudp_reply(xprt, msg) == 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 } } } @@ -264,7 +284,7 @@ svcudp_getargs(xprt, xdr_args, args_ptr) 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 @@ -276,7 +296,7 @@ svcudp_freeargs(xprt, xdr_args, args_ptr) 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 @@ -321,16 +341,27 @@ struct cache_node { /* * 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 */ @@ -343,13 +374,24 @@ struct cache_node { * 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 */ }; @@ -368,7 +410,11 @@ struct udp_cache { 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; @@ -386,12 +432,15 @@ svcudp_enablecache(transp, size) 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); } @@ -407,7 +456,11 @@ svcudp_enablecache(transp, size) 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; @@ -441,6 +494,7 @@ cache_set(xprt, replylen) } 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; } @@ -474,7 +528,11 @@ cache_get(xprt, msg, replyp, replylenp) 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;