diff options
author | Martin Willi <martin@revosec.ch> | 2011-12-05 15:44:51 +0100 |
---|---|---|
committer | Martin Willi <martin@revosec.ch> | 2012-03-20 17:31:12 +0100 |
commit | f4e25e602b44a98d581f4da2daa61c13aa06ad9a (patch) | |
tree | c070ec099ade1fbccb4e26754510d11da7a56c87 | |
parent | 65840cc4626673c477b9bdd198f06421b7137e98 (diff) | |
download | strongswan-f4e25e602b44a98d581f4da2daa61c13aa06ad9a.tar.bz2 strongswan-f4e25e602b44a98d581f4da2daa61c13aa06ad9a.tar.xz |
Implement htoun/untoh64 with potentially faster htobe64/be64toh macros, if available
-rw-r--r-- | src/libstrongswan/utils.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/libstrongswan/utils.h b/src/libstrongswan/utils.h index 3014e2f60..e5e4a10c0 100644 --- a/src/libstrongswan/utils.h +++ b/src/libstrongswan/utils.h @@ -491,6 +491,11 @@ static inline void htoun32(void *network, u_int32_t host) static inline void htoun64(void *network, u_int64_t host) { char *unaligned = (char*)network; + +#ifdef be64toh + host = htobe64(host); + memcpy((char*)unaligned, &host, sizeof(host)); +#else u_int32_t high_part, low_part; high_part = host >> 32; @@ -501,6 +506,7 @@ static inline void htoun64(void *network, u_int64_t host) memcpy(unaligned, &high_part, sizeof(high_part)); unaligned += sizeof(high_part); memcpy(unaligned, &low_part, sizeof(low_part)); +#endif } /** @@ -542,6 +548,13 @@ static inline u_int32_t untoh32(void *network) static inline u_int64_t untoh64(void *network) { char *unaligned = (char*)network; + +#ifdef be64toh + u_int64_t tmp; + + memcpy(&tmp, unaligned, sizeof(tmp)); + return be64toh(tmp); +#else u_int32_t high_part, low_part; memcpy(&high_part, unaligned, sizeof(high_part)); @@ -552,6 +565,7 @@ static inline u_int64_t untoh64(void *network) low_part = ntohl(low_part); return (((u_int64_t)high_part) << 32) + low_part; +#endif } /** |