diff options
author | Daniel Stenberg <daniel@haxx.se> | 2005-11-14 23:14:54 +0000 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2005-11-14 23:14:54 +0000 |
commit | 772b64d9d388c6c4fe3930bffbcf4102b03840ef (patch) | |
tree | 3f0f7d2fa362742e32af1148b6208b6d3d35077c /ares | |
parent | 92c0de518eee482c8a9c516ec5c1e6b447b2a1a5 (diff) |
Detect big/little endian in the configure script and adjust the ares_dns.h
macros accordingly.
Diffstat (limited to 'ares')
-rw-r--r-- | ares/ares_dns.h | 19 | ||||
-rw-r--r-- | ares/configure.ac | 6 |
2 files changed, 23 insertions, 2 deletions
diff --git a/ares/ares_dns.h b/ares/ares_dns.h index 3e5757237..290c8fb8a 100644 --- a/ares/ares_dns.h +++ b/ares/ares_dns.h @@ -18,7 +18,18 @@ #ifndef ARES__DNS_H #define ARES__DNS_H -#if 0 +#ifdef ARES_BIG_ENDIAN +/* big-endian aware versions */ +#define DNS__16BIT(p) (((p)[1] << 8) | (p)[0]) +#define DNS__32BIT(p) (((p)[3] << 24) | ((p)[2] << 16) | \ + ((p)[1] << 8) | (p)[0]) +#define DNS__SET16BIT(p, v) (((p)[1] = ((v) >> 8) & 0xff), \ + ((p)[0] = (v) & 0xff)) +#define DNS__SET32BIT(p, v) (((p)[3] = ((v) >> 24) & 0xff), \ + ((p)[2] = ((v) >> 16) & 0xff), \ + ((p)[1] = ((v) >> 8) & 0xff), \ + ((p)[0] = (v) & 0xff)) +#else #define DNS__16BIT(p) (((p)[0] << 8) | (p)[1]) #define DNS__32BIT(p) (((p)[0] << 24) | ((p)[1] << 16) | \ ((p)[2] << 8) | (p)[3]) @@ -28,7 +39,11 @@ ((p)[1] = ((v) >> 16) & 0xff), \ ((p)[2] = ((v) >> 8) & 0xff), \ ((p)[3] = (v) & 0xff)) -#else /* big-endian aware versions */ +#endif + +#if 0 +/* we cannot use this approach on systems where we can't access 16/32 bit + data on un-aligned addresses */ #define DNS__16BIT(p) ntohs(*(unsigned short*)(p)) #define DNS__32BIT(p) ntohl(*(unsigned long*)(p)) #define DNS__SET16BIT(p, v) *(unsigned short*)(p) = htons(v) diff --git a/ares/configure.ac b/ares/configure.ac index f4cc52372..c20685bc8 100644 --- a/ares/configure.ac +++ b/ares/configure.ac @@ -356,4 +356,10 @@ CARES_CHECK_GETSERVBYPORT_R CURL_CHECK_NONBLOCKING_SOCKET +AC_C_BIGENDIAN( + [AC_DEFINE(ARES_BIG_ENDIAN, 1, [define this if ares is built for a big endian system])], + , + [AC_MSG_WARN([couldn't figure out endianess, assuming little endian!])] +) + AC_OUTPUT(Makefile) |