From af7b17d60fb789b4160e8ce45d2b197b51f79350 Mon Sep 17 00:00:00 2001 From: Nathael Pajani Date: Fri, 28 Oct 2016 03:20:50 +0200 Subject: [PATCH] Add ntohl, htonl, ntohs and htons to lib/utils.h --- include/lib/utils.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/include/lib/utils.h b/include/lib/utils.h index e8ffac2..5062d1c 100644 --- a/include/lib/utils.h +++ b/include/lib/utils.h @@ -26,6 +26,7 @@ /***************************************************************************** */ #include "lib/stdint.h" +#include "core/lpc_core.h" /***************************************************************************** */ @@ -48,11 +49,19 @@ uint8_t clz(uint32_t x); */ uint8_t ctz(uint32_t x); -/* - * Count bits set +/* Count bits set */ uint8_t bits_set(uint32_t x); + +/* Network to host and host to network. + * LPC1224 is a little endian platform, we need to change endianness (reverse byte order) + */ +static inline uint32_t ntohl(uint32_t val) __attribute__ ((alias ("byte_swap_32"))); +static inline uint32_t htonl(uint32_t val) __attribute__ ((alias ("byte_swap_32"))); +/* Short versions */ +static inline uint32_t ntohs(uint32_t val) __attribute__ ((alias ("byte_swap_16"))); +static inline uint32_t htons(uint32_t val) __attribute__ ((alias ("byte_swap_16"))); #endif /* LIB_UTILS_H */ -- 2.43.0