Statistics
| Branch: | Revision:

grapes / src / int_coding.h @ 38a61cd6

History | View | Annotate | Download (628 Bytes)

1 60fa723d Luca Abeni
#ifndef INT_CODING
2
#define INT_CODING
3
4 07d576c3 Luca Abeni
#if defined(_WIN32)
5
#include <winsock2.h>
6
#else
7 e04b9596 Luca Abeni
#include <arpa/inet.h>
8 07d576c3 Luca Abeni
#endif
9 e04b9596 Luca Abeni
10 92775ce4 Luca Abeni
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 38a61cd6 Csaba Kiraly
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 92775ce4 Luca Abeni
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 38a61cd6 Csaba Kiraly
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 60fa723d Luca Abeni
#endif        /* INT_CODING */