summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: c572f40)
raw | patch | inline | side by side (parent: c572f40)
author | Florian Forster <octo@collectd.org> | |
Thu, 9 Nov 2017 15:42:22 +0000 (16:42 +0100) | ||
committer | Florian Forster <octo@collectd.org> | |
Sun, 12 Nov 2017 19:55:59 +0000 (20:55 +0100) |
src/libcollectdclient/network_parse.c | patch | blob | history |
index d158b9373a84210dbc8f1cb05744636540e53807..2365ab0addf575c037735654a3c992be8511b463 100644 (file)
#include <endian.h>
#elif HAVE_SYS_ENDIAN_H
#include <sys/endian.h>
-#elif defined(_AIX) && defined(__GNUC__)
-/* AIX is always big endian */
-#define be16toh(x) (x)
-#define be64toh(x) (x)
+#else /* fallback */
+__attribute__((const)) static uint16_t be16toh(uint16_t n) {
+ uint8_t tmp[2];
+ memmove(tmp, &n, sizeof(tmp));
+
+ return ((uint16_t)tmp[0] << 8) | ((uint16_t)tmp[1] << 0);
+}
+
+__attribute__((const)) static uint64_t be64toh(uint64_t n) {
+ uint8_t tmp[8];
+ memmove(tmp, &n, sizeof(tmp));
+
+ return ((uint64_t)tmp[0] << 56) | ((uint64_t)tmp[1] << 48) |
+ ((uint64_t)tmp[2] << 40) | ((uint64_t)tmp[3] << 32) |
+ ((uint64_t)tmp[4] << 24) | ((uint64_t)tmp[5] << 16) |
+ ((uint64_t)tmp[6] << 8) | ((uint64_t)tmp[7] << 0);
+}
#endif
#if HAVE_GCRYPT_H