@@ -60,6 +60,10 @@ typedef uint32_t in_addr_t;
6060
6161#ifdef HAVE_ENDIAN_H
6262#include < endian.h>
63+ #elif defined(__APPLE__)
64+ #include < libkern/OSByteOrder.h>
65+ #define be64toh (x ) OSSwapBigToHostInt64(x)
66+ #define htobe64 (x ) OSSwapHostToBigInt64(x)
6367#endif // HAVE_ENDIAN_H
6468#include < errno.h>
6569#include < limits.h>
@@ -160,11 +164,11 @@ uint32_t NetworkToHost(uint32_t value) {
160164}
161165
162166uint64_t NetworkToHost (uint64_t value) {
163- #ifdef HAVE_ENDIAN_H
167+ #if defined( HAVE_ENDIAN_H) || defined(__APPLE__)
164168 return be64toh (value);
165169#else
166170#error "No be64toh for NetworkToHost, please report this."
167- #endif // HAVE_ENDIAN_H
171+ #endif // defined( HAVE_ENDIAN_H) || defined(__APPLE__)
168172}
169173
170174int16_t NetworkToHost (int16_t value) {
@@ -176,11 +180,11 @@ int32_t NetworkToHost(int32_t value) {
176180}
177181
178182int64_t NetworkToHost (int64_t value) {
179- #ifdef HAVE_ENDIAN_H
183+ #if defined( HAVE_ENDIAN_H) || defined(__APPLE__)
180184 return be64toh (value);
181185#else
182186#error "No be64toh for NetworkToHost, please report this."
183- #endif // HAVE_ENDIAN_H
187+ #endif // defined( HAVE_ENDIAN_H) || defined(__APPLE__)
184188}
185189
186190uint16_t HostToNetwork (uint16_t value) {
@@ -200,19 +204,19 @@ int32_t HostToNetwork(int32_t value) {
200204}
201205
202206uint64_t HostToNetwork (uint64_t value) {
203- #ifdef HAVE_ENDIAN_H
207+ #if defined( HAVE_ENDIAN_H) || defined(__APPLE__)
204208 return htobe64 (value);
205209#else
206210#error "No htobe64 for HostToNetwork, please report this."
207- #endif // HAVE_ENDIAN_H
211+ #endif // defined( HAVE_ENDIAN_H) || defined(__APPLE__)
208212}
209213
210214int64_t HostToNetwork (int64_t value) {
211- #ifdef HAVE_ENDIAN_H
215+ #if defined( HAVE_ENDIAN_H) || defined(__APPLE__)
212216 return htobe64 (value);
213217#else
214218#error "No htobe64 for HostToNetwork, please report this."
215- #endif // HAVE_ENDIAN_H
219+ #endif // defined( HAVE_ENDIAN_H) || defined(__APPLE__)
216220}
217221
218222uint16_t HostToLittleEndian (uint16_t value) {
0 commit comments