-
Notifications
You must be signed in to change notification settings - Fork 4
/
byte_manip.h
28 lines (24 loc) · 937 Bytes
/
byte_manip.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//
// Created by thomas on 4/06/20.
//
#ifndef PLUGINIZED_BIRD_BYTE_MANIP_H
#define PLUGINIZED_BIRD_BYTE_MANIP_H
#define get_u32(data) \
({ \
uint32_t a; \
a = *((const uint32_t *) (data)); \
ebpf_ntohl(a); \
})
#define get_u32_t2_friendly(data) ({ \
unsigned long __o__ = 0; \
if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) { \
__o__ = ((((data) & 0x000000FFu) << 24u) | \
(((data) & 0x0000FF00u) << 8u) | \
(((data) & 0x00FF0000u) >> 8u) | \
(((data) & 0xFF000000u) >> 24u)); \
} else if (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) { \
__o__ = data; \
} \
__o__; \
})
#endif //PLUGINIZED_BIRD_BYTE_MANIP_H