Statistics
| Branch: | Revision:

grapes / src / int_coding.h @ df7b3cef

History | View | Annotate | Download (648 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 71175cc4 Csaba Kiraly
#include <string.h>
10 e04b9596 Luca Abeni
11 92775ce4 Luca Abeni
static inline void int_cpy(uint8_t *p, int v)
12
{
13
  uint32_t tmp;
14
  
15
  tmp = htonl(v);
16
  memcpy(p, &tmp, 4);
17
}
18
19 38a61cd6 Csaba Kiraly
static inline void int16_cpy(uint8_t *p, uint16_t v)
20
{
21
  uint16_t tmp;
22
23
  tmp = htons(v);
24
  memcpy(p, &tmp, 2);
25
}
26
27 92775ce4 Luca Abeni
static inline uint32_t int_rcpy(const uint8_t *p)
28
{
29
  uint32_t tmp;
30
  
31
  memcpy(&tmp, p, 4);
32
  tmp = ntohl(tmp);
33
34
  return tmp;
35
}
36 38a61cd6 Csaba Kiraly
37
static inline uint16_t int16_rcpy(const uint8_t *p)
38
{
39
  uint16_t tmp;
40
41
  memcpy(&tmp, p, 2);
42
  tmp = ntohs(tmp);
43
  return tmp;
44
}
45
46 60fa723d Luca Abeni
#endif        /* INT_CODING */