From 3a628268d7abd1ff797edc1b76da13def62cb338 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 30 Jan 2012 22:10:33 +0000 Subject: [PATCH] -fix endian test --- src/include/gnunet_common.h | 9 +++++++++ src/include/gnunet_tun_lib.h | 12 ++++++------ src/util/common_endian.c | 8 ++++---- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h index 04847ee5b..d934c109e 100644 --- a/src/include/gnunet_common.h +++ b/src/include/gnunet_common.h @@ -66,6 +66,15 @@ #define GNUNET_MAX(a,b) (((a) > (b)) ? (a) : (b)) +/* some systems use one underscore only... */ +#ifndef __BYTE_ORDER +#ifdef _BYTE_ORDER +#define __BYTE_ORDER _BYTE_ORDER +#define __LITTLE_ENDIAN _LITTLE_ENDIAN +#define __BIG_ENDIAN _BIG_ENDIAN +#endif +#endif + /** * Endian operations */ diff --git a/src/include/gnunet_tun_lib.h b/src/include/gnunet_tun_lib.h index 33938354b..dac11d6a8 100644 --- a/src/include/gnunet_tun_lib.h +++ b/src/include/gnunet_tun_lib.h @@ -70,10 +70,10 @@ struct GNUNET_TUN_Layer2PacketHeader */ struct GNUNET_TUN_IPv4Header { -#if __BYTE_ORDER == __LITTLE_ENDIAN || _BYTE_ORDER == _LITTLE_ENDIAN +#if __BYTE_ORDER == __LITTLE_ENDIAN unsigned int header_length:4 GNUNET_PACKED; unsigned int version:4 GNUNET_PACKED; -#elif __BYTE_ORDER == __BIG_ENDIAN || _BYTE_ORDER == _BIG_ENDIAN +#elif __BYTE_ORDER == __BIG_ENDIAN unsigned int version:4 GNUNET_PACKED; unsigned int header_length:4 GNUNET_PACKED; #else @@ -127,12 +127,12 @@ struct GNUNET_TUN_IPv4Header */ struct GNUNET_TUN_IPv6Header { -#if __BYTE_ORDER == __LITTLE_ENDIAN || _BYTE_ORDER == _LITTLE_ENDIAN +#if __BYTE_ORDER == __LITTLE_ENDIAN unsigned int traffic_class_h:4 GNUNET_PACKED; unsigned int version:4 GNUNET_PACKED; unsigned int traffic_class_l:4 GNUNET_PACKED; unsigned int flow_label:20 GNUNET_PACKED; -#elif __BYTE_ORDER == __BIG_ENDIAN || _BYTE_ORDER == _BIG_ENDIAN +#elif __BYTE_ORDER == __BIG_ENDIAN unsigned int version:4 GNUNET_PACKED; unsigned int traffic_class:8 GNUNET_PACKED; unsigned int flow_label:20 GNUNET_PACKED; @@ -183,7 +183,7 @@ struct GNUNET_TUN_TcpHeader * Acknowledgement number. */ uint32_t ack GNUNET_PACKED; -#if __BYTE_ORDER == __LITTLE_ENDIAN || _BYTE_ORDER == _LITTLE_ENDIAN +#if __BYTE_ORDER == __LITTLE_ENDIAN /** * Reserved. Must be zero. */ @@ -192,7 +192,7 @@ struct GNUNET_TUN_TcpHeader * Number of 32-bit words in TCP header. */ unsigned int off : 4 GNUNET_PACKED; -#elif __BYTE_ORDER == __BIG_ENDIAN || _BYTE_ORDER == _BIG_ENDIAN +#elif __BYTE_ORDER == __BIG_ENDIAN /** * Number of 32-bit words in TCP header. */ diff --git a/src/util/common_endian.c b/src/util/common_endian.c index 1867ba01d..117e575e4 100644 --- a/src/util/common_endian.c +++ b/src/util/common_endian.c @@ -32,9 +32,9 @@ uint64_t GNUNET_ntohll (uint64_t n) { -#if __BYTE_ORDER == __BIG_ENDIAN || _BYTE_ORDER == _BIG_ENDIAN +#if __BYTE_ORDER == __BIG_ENDIAN return n; -#elif __BYTE_ORDER == __LITTLE_ENDIAN || _BYTE_ORDER == _LITTLE_ENDIAN +#elif __BYTE_ORDER == __LITTLE_ENDIAN return (((uint64_t) ntohl (n)) << 32) + ntohl (n >> 32); #else #error byteorder undefined @@ -44,9 +44,9 @@ GNUNET_ntohll (uint64_t n) uint64_t GNUNET_htonll (uint64_t n) { -#if __BYTE_ORDER == __BIG_ENDIAN || _BYTE_ORDER == _BIG_ENDIAN +#if __BYTE_ORDER == __BIG_ENDIAN return n; -#elif __BYTE_ORDER == __LITTLE_ENDIAN || _BYTE_ORDER == _LITTLE_ENDIAN +#elif __BYTE_ORDER == __LITTLE_ENDIAN return (((uint64_t) htonl (n)) << 32) + htonl (n >> 32); #else #error byteorder undefined -- 2.25.1