@@ -60,11 +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)
6763#endif // HAVE_ENDIAN_H
64+ #ifdef HAVE_LIBKERN_OSBYTEORDER_H
65+ #include < libkern/OSByteOrder.h>
66+ #endif // HAVE_LIBKERN_OSBYTEORDER_H
6867#include < errno.h>
6968#include < limits.h>
7069#include < stdlib.h>
@@ -164,11 +163,13 @@ uint32_t NetworkToHost(uint32_t value) {
164163}
165164
166165uint64_t NetworkToHost (uint64_t value) {
167- #if defined( HAVE_ENDIAN_H) || defined(__APPLE__)
166+ #ifdef HAVE_ENDIAN_H
168167 return be64toh (value);
168+ #elif defined(HAVE_LIBKERN_OSBYTEORDER_H)
169+ return OSSwapBigToHostInt64 (value);
169170#else
170- #error "No be64toh for NetworkToHost, please report this."
171- #endif // defined( HAVE_ENDIAN_H) || defined(__APPLE__)
171+ #error "No big endian 64 bit to host for NetworkToHost, please report this."
172+ #endif // HAVE_ENDIAN_H
172173}
173174
174175int16_t NetworkToHost (int16_t value) {
@@ -180,11 +181,13 @@ int32_t NetworkToHost(int32_t value) {
180181}
181182
182183int64_t NetworkToHost (int64_t value) {
183- #if defined( HAVE_ENDIAN_H) || defined(__APPLE__)
184+ #ifdef HAVE_ENDIAN_H
184185 return be64toh (value);
186+ #elif defined(HAVE_LIBKERN_OSBYTEORDER_H)
187+ return OSSwapBigToHostInt64 (value);
185188#else
186- #error "No be64toh for NetworkToHost, please report this."
187- #endif // defined( HAVE_ENDIAN_H) || defined(__APPLE__)
189+ #error "No big endian 64 bit to host for NetworkToHost, please report this."
190+ #endif // HAVE_ENDIAN_H
188191}
189192
190193uint16_t HostToNetwork (uint16_t value) {
@@ -204,19 +207,23 @@ int32_t HostToNetwork(int32_t value) {
204207}
205208
206209uint64_t HostToNetwork (uint64_t value) {
207- #if defined( HAVE_ENDIAN_H) || defined(__APPLE__)
210+ #ifdef HAVE_ENDIAN_H
208211 return htobe64 (value);
212+ #elif defined(HAVE_LIBKERN_OSBYTEORDER_H)
213+ return OSSwapHostToBigInt64 (value);
209214#else
210- #error "No htobe64 for HostToNetwork, please report this."
211- #endif // defined( HAVE_ENDIAN_H) || defined(__APPLE__)
215+ #error "No host to big endian 64 bit for HostToNetwork, please report this."
216+ #endif // HAVE_ENDIAN_H
212217}
213218
214219int64_t HostToNetwork (int64_t value) {
215- #if defined( HAVE_ENDIAN_H) || defined(__APPLE__)
220+ #ifdef HAVE_ENDIAN_H
216221 return htobe64 (value);
222+ #elif defined(HAVE_LIBKERN_OSBYTEORDER_H)
223+ return OSSwapHostToBigInt64 (value);
217224#else
218- #error "No htobe64 for HostToNetwork, please report this."
219- #endif // defined( HAVE_ENDIAN_H) || defined(__APPLE__)
225+ #error "No host to big endian 64 bit for HostToNetwork, please report this."
226+ #endif // HAVE_ENDIAN_H
220227}
221228
222229uint16_t HostToLittleEndian (uint16_t value) {
0 commit comments