138414Smckusick /* 238414Smckusick * Copyright (c) 1989 The Regents of the University of California. 338414Smckusick * All rights reserved. 438414Smckusick * 538414Smckusick * This code is derived from software contributed to Berkeley by 638414Smckusick * Rick Macklem at The University of Guelph. 738414Smckusick * 844515Sbostic * %sccs.include.redist.c% 938414Smckusick * 10*52196Smckusick * @(#)xdr_subs.h 7.4 (Berkeley) 01/14/92 1138414Smckusick */ 1238414Smckusick 1338414Smckusick /* 1438414Smckusick * Macros used for conversion to/from xdr representation by nfs... 1538414Smckusick * These use the MACHINE DEPENDENT routines ntohl, htonl 1639748Smckusick * As defined by "XDR: External Data Representation Standard" RFC1014 1738414Smckusick */ 18*52196Smckusick #if BYTE_ORDER == LITTLE_ENDIAN 1938414Smckusick #define fxdr_unsigned(t, v) ((t)ntohl((long)(v))) 20*52196Smckusick #define fxdr_time(f, t) { \ 21*52196Smckusick ((struct timeval *)(t))->tv_sec = \ 22*52196Smckusick ntohl(((struct timeval *)(f))->tv_sec); \ 23*52196Smckusick ((struct timeval *)(t))->tv_usec = \ 24*52196Smckusick ntohl(((struct timeval *)(f))->tv_usec); \ 25*52196Smckusick } 2638414Smckusick 27*52196Smckusick /* 28*52196Smckusick * To handle quad conversions, define a struct of two longs and use 29*52196Smckusick * ntohl and htonl. Maybe someday there should be ntohq and htonq? 30*52196Smckusick */ 31*52196Smckusick union _hq { 32*52196Smckusick quad_t hq; 33*52196Smckusick struct { 34*52196Smckusick long val[2]; 35*52196Smckusick } lq; 36*52196Smckusick }; 37*52196Smckusick #define fxdr_hyper(f, t) { \ 38*52196Smckusick ((union _hq *)(t))->lq.val[1] = ntohl(((union _hq *)(f))->lq.val[0]); \ 39*52196Smckusick ((union _hq *)(t))->lq.val[0] = ntohl(((union _hq *)(f))->lq.val[1]); \ 40*52196Smckusick } 41*52196Smckusick #define txdr_hyper(f, t) { \ 42*52196Smckusick ((union _hq *)(t))->lq.val[0] = htonl(((union _hq *)(f))->lq.val[1]); \ 43*52196Smckusick ((union _hq *)(t))->lq.val[1] = htonl(((union _hq *)(f))->lq.val[0]); \ 44*52196Smckusick } 45*52196Smckusick 4638414Smckusick #define txdr_unsigned(v) (htonl((long)(v))) 47*52196Smckusick #define txdr_time(f, t) { \ 48*52196Smckusick ((struct timeval *)(t))->tv_sec = \ 49*52196Smckusick htonl(((struct timeval *)(f))->tv_sec); \ 50*52196Smckusick ((struct timeval *)(t))->tv_usec = \ 51*52196Smckusick htonl(((struct timeval *)(f))->tv_usec); \ 52*52196Smckusick } 53*52196Smckusick #else /* BIG_ENDIAN */ 54*52196Smckusick #define fxdr_unsigned(t, v) ((t)(v)) 55*52196Smckusick #define fxdr_time(f, t) \ 56*52196Smckusick *((struct timeval *)(t)) = *((struct timeval *)(f)) 57*52196Smckusick #define fxdr_hyper(f, t) \ 58*52196Smckusick *((quad_t *)(t)) = *((quad_t *)(f)) 5938414Smckusick 60*52196Smckusick #define txdr_unsigned(v) ((long)(v)) 61*52196Smckusick #define txdr_time(f, t) \ 62*52196Smckusick *((struct timeval *)(t)) = *((struct timeval *)(f)) 63*52196Smckusick #define txdr_hyper(f, t) \ 64*52196Smckusick *((quad_t *)(t)) = *((quad_t *)(f)) 65*52196Smckusick #endif /* ENDIAN */ 66