Usermode/AxWin4 - (minor) Log and fail when wrong window ID is returned from server
[tpg/acess2.git] / Usermode / Libraries / libpsocket.so_src / byteordering.c
1 /*
2  * Acess2 POSIX Sockets Library
3  * - By John Hodge (thePowersGang)
4  *
5  * byteordering.c
6  * - hton/ntoh
7  */
8 #include <arpa/inet.h>
9
10 // === CODE ===
11 static uint32_t Flip32(uint32_t val)
12 {
13         return (((val >> 24) & 0xFF) << 0)
14                 | (((val >> 16) & 0xFF) << 8)
15                 | (((val >> 8) & 0xFF) << 16)
16                 | (((val >> 0) & 0xFF) << 24)
17                 ;
18 }
19
20 static uint16_t Flip16(uint16_t val)
21 {
22         return (val >> 8) | (val << 8);
23 }
24
25 uint32_t htonl(uint32_t hostlong)
26 {
27         #if BIG_ENDIAN
28         return hostlong;
29         #else
30         return Flip32(hostlong);
31         #endif
32 }
33 uint16_t htons(uint16_t hostshort)
34 {
35         #if BIG_ENDIAN
36         return hostshort;
37         #else
38         return Flip16(hostshort);
39         #endif
40 }
41 uint32_t ntohl(uint32_t netlong)
42 {
43         #if BIG_ENDIAN
44         return netlong;
45         #else
46         return Flip32(netlong);
47         #endif
48 }
49 uint16_t ntohs(uint16_t netshort)
50 {
51         #if BIG_ENDIAN
52         return netshort;
53         #else
54         return Flip16(netshort);
55         #endif
56 }
57
58

UCC git Repository :: git.ucc.asn.au