From 86115434f1f60afe51a87d4c1674a3e2c0d18700 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Sun, 22 Mar 2015 09:37:17 +0100 Subject: endian: Use the new endian macros for portability Use the new macros to deal with little/big endian. Im a bit worried to make this change due the little test coverage in this module but in case of a typo the elements would not be defined. --- configure.ac | 2 -- examples/rs232-write.c | 5 +++-- include/osmocom/netif/amr.h | 6 ++++-- include/osmocom/netif/osmux.h | 10 ++++++---- include/osmocom/netif/rtp.h | 6 ++++-- src/rtp.c | 1 - 6 files changed, 17 insertions(+), 13 deletions(-) diff --git a/configure.ac b/configure.ac index 28dde0c..47fba65 100644 --- a/configure.ac +++ b/configure.ac @@ -32,8 +32,6 @@ AC_COMPILE_IFELSE([AC_LANG_SOURCE([char foo;])], CFLAGS="$saved_CFLAGS" AC_SUBST(SYMBOL_VISIBILITY) -AC_CHECK_HEADER([endian.h], [], [AC_MSG_ERROR([endian.h not found!]) ]) - dnl Generate the output AM_CONFIG_HEADER(config.h) diff --git a/examples/rs232-write.c b/examples/rs232-write.c index 370bd12..11498f3 100644 --- a/examples/rs232-write.c +++ b/examples/rs232-write.c @@ -9,6 +9,7 @@ #include #include #include +#include #include @@ -110,13 +111,13 @@ static void ubx_checksum(struct msgb *msg, uint8_t *ck) } } -# if __BYTE_ORDER == __LITTLE_ENDIAN +# if OSMO_IS_LITTLE_ENDIAN # define utohl(x) (x) # define utohs(x) (x) # define htoul(x) (x) # define htous(x) (x) # else -# if __BYTE_ORDER == __BIG_ENDIAN +# if OSMO_IS_BIG_ENDIAN # define utohl(x) __bswap_32 (x) # define utohs(x) __bswap_16 (x) # define htoul(x) __bswap_32 (x) diff --git a/include/osmocom/netif/amr.h b/include/osmocom/netif/amr.h index 60dacf6..b0ab8a3 100644 --- a/include/osmocom/netif/amr.h +++ b/include/osmocom/netif/amr.h @@ -1,6 +1,8 @@ #ifndef _OSMO_AMR_H_ #define _OSMO_AMR_H_ +#include + /* As defined by RFC3267: Adaptive Multi-Rate (AMR) */ /* @@ -41,7 +43,7 @@ */ struct amr_hdr { -#if __BYTE_ORDER == __BIG_ENDIAN +#if OSMO_IS_BIG_ENDIAN /* Payload Header */ uint8_t cmr:4, /* Codec Mode Request */ pad1:4; @@ -50,7 +52,7 @@ struct amr_hdr { ft:4, /* coding mode */ q:1, /* OK (not damaged) at origin? */ pad2:2; -#elif __BYTE_ORDER == __LITTLE_ENDIAN +#elif OSMO_IS_LITTLE_ENDIAN /* Payload Header */ uint8_t pad1:4, cmr:4; diff --git a/include/osmocom/netif/osmux.h b/include/osmocom/netif/osmux.h index 493f64f..0f6f5c9 100644 --- a/include/osmocom/netif/osmux.h +++ b/include/osmocom/netif/osmux.h @@ -1,6 +1,8 @@ #ifndef _OSMUX_H_ #define _OSMUX_H_ +#include + /* OSmux header: * * ft (3 bits): 0=signalling, 1=voice @@ -17,12 +19,12 @@ #define OSMUX_FT_VOICE_AMR 1 struct osmux_hdr { -#if __BYTE_ORDER == __BIG_ENDIAN +#if OSMO_IS_BIG_ENDIAN uint8_t ft:3, ctr:3, amr_f:1, amr_q:1; -#elif __BYTE_ORDER == __LITTLE_ENDIAN +#elif OSMO_IS_LITTLE_ENDIAN uint8_t amr_q:1, amr_f:1, ctr:3, @@ -31,10 +33,10 @@ struct osmux_hdr { uint8_t seq; #define OSMUX_CID_MAX 255 /* determined by circuit_id */ uint8_t circuit_id; -#if __BYTE_ORDER == __BIG_ENDIAN +#if OSMO_IS_BIG_ENDIAN uint8_t amr_ft:4, amr_cmr:4; -#elif __BYTE_ORDER == __LITTLE_ENDIAN +#elif OSMO_IS_LITTLE_ENDIAN uint8_t amr_cmr:4, amr_ft:4; #endif diff --git a/include/osmocom/netif/rtp.h b/include/osmocom/netif/rtp.h index 1854d6c..729e5c9 100644 --- a/include/osmocom/netif/rtp.h +++ b/include/osmocom/netif/rtp.h @@ -1,16 +1,18 @@ #ifndef _OSMO_RTP_H_ #define _OSMO_RTP_H_ +#include + /* RTP header as defined by RFC 3550 */ struct rtp_hdr { -#if __BYTE_ORDER == __LITTLE_ENDIAN +#if OSMO_IS_LITTLE_ENDIAN uint8_t csrc_count:4, extension:1, padding:1, version:2; uint8_t payload_type:7, marker:1; -#elif __BYTE_ORDER == __BIG_ENDIAN +#elif OSMO_IS_BIG_ENDIAN uint8_t version:2, padding:1, extension:1, diff --git a/src/rtp.c b/src/rtp.c index 2a6ba54..e965d85 100644 --- a/src/rtp.c +++ b/src/rtp.c @@ -1,6 +1,5 @@ #include #include -#include #include #include /* for memcpy. */ #include /* for ntohs. */ -- cgit v1.2.3