Statistics
| Branch: | Revision:

grapes / src / int_coding.h @ 38a61cd6

History | View | Annotate | Download (628 Bytes)

1
#ifndef INT_CODING
2
#define INT_CODING
3

    
4
#if defined(_WIN32)
5
#include <winsock2.h>
6
#else
7
#include <arpa/inet.h>
8
#endif
9

    
10
static inline void int_cpy(uint8_t *p, int v)
11
{
12
  uint32_t tmp;
13
  
14
  tmp = htonl(v);
15
  memcpy(p, &tmp, 4);
16
}
17

    
18
static inline void int16_cpy(uint8_t *p, uint16_t v)
19
{
20
  uint16_t tmp;
21

    
22
  tmp = htons(v);
23
  memcpy(p, &tmp, 2);
24
}
25

    
26
static inline uint32_t int_rcpy(const uint8_t *p)
27
{
28
  uint32_t tmp;
29
  
30
  memcpy(&tmp, p, 4);
31
  tmp = ntohl(tmp);
32

    
33
  return tmp;
34
}
35

    
36
static inline uint16_t int16_rcpy(const uint8_t *p)
37
{
38
  uint16_t tmp;
39

    
40
  memcpy(&tmp, p, 2);
41
  tmp = ntohs(tmp);
42
  return tmp;
43
}
44

    
45
#endif        /* INT_CODING */