summaryrefslogtreecommitdiff
path: root/lib/swap.h
blob: fbe2a9ffdc8d61eac8bd86e35b496a660b41f3a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#ifndef lib_swap_h
#define lib_swap_h
/* Cesar project {{{
 *
 * Copyright (C) 2007 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    lib/swap.h
 * \brief   generic swap functions
 * \ingroup lib
 */

/** swap an unsigned short */
extern u16 swap16(u16 x);

/** swap an unsigned long */
extern u32 swap32(u32 x);

#if DEFS_BIG_ENDIAN

#define ntohs(x) (x)
#define ntohl(x) (x)
#define htons(x) (x)
#define htonl(x) (x)

#else

#define ntohs(x) (swap16(x))
#define ntohl(x) (swap32(x))
#define htons(x) (swap16(x))
#define htonl(x) (swap32(x))

#endif

#endif /* lib_swap_h */