-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathabcehdr.h
76 lines (62 loc) · 1.38 KB
/
abcehdr.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#ifndef _ABCE_HDR_H_
#define _ABCE_HDR_H_
#include <string.h>
#include <arpa/inet.h>
#include <netinet/in.h>
static inline uint64_t abce_hdr_get64h(const void *buf)
{
uint64_t res;
memcpy(&res, buf, sizeof(res));
return res;
}
static inline uint32_t abce_hdr_get32h(const void *buf)
{
uint32_t res;
memcpy(&res, buf, sizeof(res));
return res;
}
static inline uint16_t abce_hdr_get16h(const void *buf)
{
uint16_t res;
memcpy(&res, buf, sizeof(res));
return res;
}
static inline uint8_t abce_hdr_get8h(const void *buf)
{
uint8_t res;
memcpy(&res, buf, sizeof(res));
return res;
}
static inline void abce_hdr_set64h(void *buf, uint64_t val)
{
memcpy(buf, &val, sizeof(val));
}
static inline void abce_hdr_set32h(void *buf, uint32_t val)
{
memcpy(buf, &val, sizeof(val));
}
static inline void abce_hdr_set16h(void *buf, uint16_t val)
{
memcpy(buf, &val, sizeof(val));
}
static inline void abce_hdr_set8h(void *buf, uint8_t val)
{
memcpy(buf, &val, sizeof(val));
}
static inline uint32_t abce_hdr_get32n(const void *buf)
{
return ntohl(abce_hdr_get32h(buf));
}
static inline uint16_t abce_hdr_get16n(const void *buf)
{
return ntohs(abce_hdr_get16h(buf));
}
static inline void abce_hdr_set32n(void *buf, uint32_t val)
{
abce_hdr_set32h(buf, htonl(val));
}
static inline void abce_hdr_set16n(void *buf, uint16_t val)
{
abce_hdr_set16h(buf, htons(val));
}
#endif