David S. Miller | bc1bafb | 2017-05-01 12:43:49 -0700 | [diff] [blame] | 1 | #ifndef __BPF_ENDIAN__ |
| 2 | #define __BPF_ENDIAN__ |
| 3 | |
| 4 | #include <asm/byteorder.h> |
| 5 | |
| 6 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
| 7 | # define __bpf_ntohs(x) __builtin_bswap16(x) |
| 8 | # define __bpf_htons(x) __builtin_bswap16(x) |
| 9 | #elif __BYTE_ORDER == __BIG_ENDIAN |
| 10 | # define __bpf_ntohs(x) (x) |
| 11 | # define __bpf_htons(x) (x) |
| 12 | #else |
| 13 | # error "Fix your __BYTE_ORDER?!" |
| 14 | #endif |
| 15 | |
| 16 | #define bpf_htons(x) \ |
| 17 | (__builtin_constant_p(x) ? \ |
| 18 | __constant_htons(x) : __bpf_htons(x)) |
| 19 | #define bpf_ntohs(x) \ |
| 20 | (__builtin_constant_p(x) ? \ |
| 21 | __constant_ntohs(x) : __bpf_ntohs(x)) |
| 22 | |
| 23 | #endif |