Statistics
| Branch: | Revision:

grapes / include / int_coding.h @ master

History | View | Annotate | Download (664 Bytes)

1
#ifndef INT_CODING
2
#define INT_CODING
3

    
4
#ifdef _WIN32
5
#include <winsock2.h>
6
#include <ws2tcpip.h>
7
#else
8
#include <arpa/inet.h>
9
#endif
10
#include <string.h>
11

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

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

    
24
  tmp = htons(v);
25
  memcpy(p, &tmp, 2);
26
}
27

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

    
35
  return tmp;
36
}
37

    
38
static inline uint16_t int16_rcpy(const uint8_t *p)
39
{
40
  uint16_t tmp;
41

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

    
47
#endif        /* INT_CODING */