minor build fix for zonekeeperless builds
[distributedratelimiting.git] / extensions / chtons.h
1 #ifndef _CHTONS_H_
2 #define _CHTONS_H_
3
4 #include <endian.h>
5
6 #if __BYTE_ORDER == __BIG_ENDIAN
7 #      define BITNR(X) ((X)^31)
8 #      if !defined(__constant_htonl)
9 #              define __constant_htonl(x) (x)
10 #      endif
11 #      if !defined(__constant_htons)
12 #              define __constant_htons(x) (x)
13 #      endif
14 #elif __BYTE_ORDER == __LITTLE_ENDIAN
15 #      define BITNR(X) ((X)^7)
16 #      if !defined(__constant_htonl)
17 #              define __constant_htonl(x) \
18         ((unsigned long int)((((unsigned long int)(x) & 0x000000ffU) << 24) | \
19                              (((unsigned long int)(x) & 0x0000ff00U) <<  8) | \
20                              (((unsigned long int)(x) & 0x00ff0000U) >>  8) | \
21                              (((unsigned long int)(x) & 0xff000000U) >> 24)))
22 #      endif
23 #      if !defined(__constant_htons)
24 #              define __constant_htons(x) \
25         ((unsigned short int)((((unsigned short int)(x) & 0x00ff) << 8) | \
26                               (((unsigned short int)(x) & 0xff00) >> 8)))
27 #      endif
28 #else
29 #      error "Don't know if bytes are big- or little-endian!"
30 #endif
31
32 #endif