From 7010548c1bc767c7f10b993262fd9c4b695e34cf Mon Sep 17 00:00:00 2001 From: Tim Woodall Date: Thu, 21 Jul 2005 17:45:09 +0000 Subject: [PATCH] correct byte order conversions for size_t == 8 bytes This commit was SVN r6577. --- orte/mca/oob/tcp/oob_tcp.h | 66 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 3 deletions(-) diff --git a/orte/mca/oob/tcp/oob_tcp.h b/orte/mca/oob/tcp/oob_tcp.h index 2aeede342f..b91590b356 100644 --- a/orte/mca/oob/tcp/oob_tcp.h +++ b/orte/mca/oob/tcp/oob_tcp.h @@ -59,15 +59,65 @@ int mca_oob_tcp_init(void); */ int mca_oob_tcp_fini(void); +#if SIZEOF_SIZE_T == 8 +/* + * Convert a 64 bit value to network byte order. + */ +static inline uint64_t hton64(uint64_t val) +{ + union { uint64_t ll; + uint32_t l[2]; + } w, r; + + /* platform already in network byte order? */ + if(htonl(1) == 1L) + return val; + w.ll = val; + r.l[0] = htonl(w.l[1]); + r.l[1] = htonl(w.l[0]); + return r.ll; +} + +/* + * Convert a 64 bit value from network to host byte order. + */ + +static inline uint64_t ntoh64(uint64_t val) +{ + union { uint64_t ll; + uint32_t l[2]; + } w, r; + + /* platform already in network byte order? */ + if(htonl(1) == 1L) + return val; + w.ll = val; + r.l[0] = ntohl(w.l[1]); + r.l[1] = ntohl(w.l[0]); + return r.ll; +} + +/** + * Convert process name from host to network byte order. + * + * @param name + */ +#define OMPI_PROCESS_NAME_HTON(n) \ + n.cellid = hton64(n.cellid); \ + n.jobid = hton64(n.jobid); \ + n.vpid = hton64(n.vpid); + /** * Convert process name from network to host byte order. * * @param name */ #define OMPI_PROCESS_NAME_NTOH(n) \ - n.cellid = ntohl(n.cellid); \ - n.jobid = ntohl(n.jobid); \ - n.vpid = ntohl(n.vpid); + n.cellid = ntoh64(n.cellid); \ + n.jobid = ntoh64(n.jobid); \ + n.vpid = ntoh64(n.vpid); + +#else /** * Convert process name from host to network byte order. @@ -79,6 +129,16 @@ int mca_oob_tcp_fini(void); n.jobid = htonl(n.jobid); \ n.vpid = htonl(n.vpid); +/** + * Convert process name from network to host byte order. + * + * @param name + */ +#define OMPI_PROCESS_NAME_HTON(n) \ + n.cellid = ntohl(n.cellid); \ + n.jobid = ntohl(n.jobid); \ + n.vpid = ntohl(n.vpid); +#endif /** * Compare two process names for equality.