@@ -60,6 +60,10 @@ typedef uint32_t in_addr_t;
60
60
61
61
#ifdef HAVE_ENDIAN_H
62
62
#include < endian.h>
63
+ #elif defined(__APPLE__)
64
+ #include < libkern/OSByteOrder.h>
65
+ #define be64toh (x ) OSSwapBigToHostInt64(x)
66
+ #define htobe64 (x ) OSSwapHostToBigInt64(x)
63
67
#endif // HAVE_ENDIAN_H
64
68
#include < errno.h>
65
69
#include < limits.h>
@@ -160,11 +164,11 @@ uint32_t NetworkToHost(uint32_t value) {
160
164
}
161
165
162
166
uint64_t NetworkToHost (uint64_t value) {
163
- #ifdef HAVE_ENDIAN_H
167
+ #if defined( HAVE_ENDIAN_H) || defined(__APPLE__)
164
168
return be64toh (value);
165
169
#else
166
170
#error "No be64toh for NetworkToHost, please report this."
167
- #endif // HAVE_ENDIAN_H
171
+ #endif // defined( HAVE_ENDIAN_H) || defined(__APPLE__)
168
172
}
169
173
170
174
int16_t NetworkToHost (int16_t value) {
@@ -176,11 +180,11 @@ int32_t NetworkToHost(int32_t value) {
176
180
}
177
181
178
182
int64_t NetworkToHost (int64_t value) {
179
- #ifdef HAVE_ENDIAN_H
183
+ #if defined( HAVE_ENDIAN_H) || defined(__APPLE__)
180
184
return be64toh (value);
181
185
#else
182
186
#error "No be64toh for NetworkToHost, please report this."
183
- #endif // HAVE_ENDIAN_H
187
+ #endif // defined( HAVE_ENDIAN_H) || defined(__APPLE__)
184
188
}
185
189
186
190
uint16_t HostToNetwork (uint16_t value) {
@@ -200,19 +204,19 @@ int32_t HostToNetwork(int32_t value) {
200
204
}
201
205
202
206
uint64_t HostToNetwork (uint64_t value) {
203
- #ifdef HAVE_ENDIAN_H
207
+ #if defined( HAVE_ENDIAN_H) || defined(__APPLE__)
204
208
return htobe64 (value);
205
209
#else
206
210
#error "No htobe64 for HostToNetwork, please report this."
207
- #endif // HAVE_ENDIAN_H
211
+ #endif // defined( HAVE_ENDIAN_H) || defined(__APPLE__)
208
212
}
209
213
210
214
int64_t HostToNetwork (int64_t value) {
211
- #ifdef HAVE_ENDIAN_H
215
+ #if defined( HAVE_ENDIAN_H) || defined(__APPLE__)
212
216
return htobe64 (value);
213
217
#else
214
218
#error "No htobe64 for HostToNetwork, please report this."
215
- #endif // HAVE_ENDIAN_H
219
+ #endif // defined( HAVE_ENDIAN_H) || defined(__APPLE__)
216
220
}
217
221
218
222
uint16_t HostToLittleEndian (uint16_t value) {
0 commit comments