Statistics
| Branch: | Revision:

grapes / include / int_coding.h @ master

History | View | Annotate | Download (664 Bytes)

1 60fa723d Luca Abeni
#ifndef INT_CODING
2
#define INT_CODING
3
4 48a14cfb Alessandro Russo
#ifdef _WIN32
5 07d576c3 Luca Abeni
#include <winsock2.h>
6 48a14cfb Alessandro Russo
#include <ws2tcpip.h>
7 07d576c3 Luca Abeni
#else
8 e04b9596 Luca Abeni
#include <arpa/inet.h>
9 07d576c3 Luca Abeni
#endif
10 71175cc4 Csaba Kiraly
#include <string.h>
11 e04b9596 Luca Abeni
12 92775ce4 Luca Abeni
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 38a61cd6 Csaba Kiraly
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 92775ce4 Luca Abeni
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 38a61cd6 Csaba Kiraly
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 60fa723d Luca Abeni
#endif        /* INT_CODING */