@@ -61,6 +61,9 @@ typedef uint32_t in_addr_t;
6161#ifdef HAVE_ENDIAN_H
6262#include < endian.h>
6363#endif // HAVE_ENDIAN_H
64+ #ifdef HAVE_LIBKERN_OSBYTEORDER_H
65+ #include < libkern/OSByteOrder.h>
66+ #endif // HAVE_LIBKERN_OSBYTEORDER_H
6467#include < errno.h>
6568#include < limits.h>
6669#include < stdlib.h>
@@ -162,8 +165,10 @@ uint32_t NetworkToHost(uint32_t value) {
162165uint64_t NetworkToHost (uint64_t value) {
163166#ifdef HAVE_ENDIAN_H
164167 return be64toh (value);
168+ #elif defined(HAVE_LIBKERN_OSBYTEORDER_H)
169+ return OSSwapBigToHostInt64 (value);
165170#else
166- #error "No be64toh for NetworkToHost, please report this."
171+ #error "No big endian 64 bit to host for NetworkToHost, please report this."
167172#endif // HAVE_ENDIAN_H
168173}
169174
@@ -178,8 +183,10 @@ int32_t NetworkToHost(int32_t value) {
178183int64_t NetworkToHost (int64_t value) {
179184#ifdef HAVE_ENDIAN_H
180185 return be64toh (value);
186+ #elif defined(HAVE_LIBKERN_OSBYTEORDER_H)
187+ return OSSwapBigToHostInt64 (value);
181188#else
182- #error "No be64toh for NetworkToHost, please report this."
189+ #error "No big endian 64 bit to host for NetworkToHost, please report this."
183190#endif // HAVE_ENDIAN_H
184191}
185192
@@ -202,16 +209,20 @@ int32_t HostToNetwork(int32_t value) {
202209uint64_t HostToNetwork (uint64_t value) {
203210#ifdef HAVE_ENDIAN_H
204211 return htobe64 (value);
212+ #elif defined(HAVE_LIBKERN_OSBYTEORDER_H)
213+ return OSSwapHostToBigInt64 (value);
205214#else
206- #error "No htobe64 for HostToNetwork, please report this."
215+ #error "No host to big endian 64 bit for HostToNetwork, please report this."
207216#endif // HAVE_ENDIAN_H
208217}
209218
210219int64_t HostToNetwork (int64_t value) {
211220#ifdef HAVE_ENDIAN_H
212221 return htobe64 (value);
222+ #elif defined(HAVE_LIBKERN_OSBYTEORDER_H)
223+ return OSSwapHostToBigInt64 (value);
213224#else
214- #error "No htobe64 for HostToNetwork, please report this."
225+ #error "No host to big endian 64 bit for HostToNetwork, please report this."
215226#endif // HAVE_ENDIAN_H
216227}
217228
0 commit comments