blob: 19d0604f86946824b04138e8bcaf29f3628ab808 [file] [log] [blame]
David S. Millerbc1bafb2017-05-01 12:43:49 -07001#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