source: gsdl/trunk/trunk/mgpp/lib/win32in.c@ 16583

Last change on this file since 16583 was 16583, checked in by davidb, 16 years ago

Undoing change commited in r16582

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 2.1 KB
Line 
1/* This module provides an equivalent of <netinet/in.h> on */
2/* unix systems. */
3#include "win32in.h"
4
5unsigned long htonl(unsigned long x) {
6#if defined (LITTLE_ENDIAN) || defined (_LITTLE_ENDIAN) || defined(__LITTLE_ENDIAN)
7 x = ((x >> 24) & 0x000000FF) | ((x >> 8) & 0x0000FF00) |
8 ((x << 8) & 0x00FF0000) | ((x << 24) & 0xFF000000);
9#endif
10
11 return x;
12}
13
14mg_ullong ntohll(mg_ullong x)
15{
16#if defined (LITTLE_ENDIAN) || defined(_LITTLE_ENDIAN) || defined(__LITTLE_ENDIAN)
17 x =
18 ((x >> 56) & 0x00000000000000FF) | ((x >> 40) & 0x000000000000FF00) |
19 ((x >> 24) & 0x0000000000FF0000) | ((x >> 8) & 0x00000000FF000000) |
20 ((x << 8) & 0x000000FF00000000) | ((x << 24) & 0x0000FF0000000000) |
21 ((x << 40) & 0x00FF000000000000) | ((x << 56) & 0xFF00000000000000);
22#endif
23 return x;
24}
25
26unsigned long ntohl(unsigned long x) {
27#if defined (LITTLE_ENDIAN) || defined (_LITTLE_ENDIAN) || defined(__LITTLE_ENDIAN)
28 x = ((x >> 24) & 0x000000FF) | ((x >> 8) & 0x0000FF00) |
29 ((x << 8) & 0x00FF0000) | ((x << 24) & 0xFF000000);
30#endif
31 return x;
32}
33
34unsigned short htons(unsigned short x) {
35#if defined (LITTLE_ENDIAN) || defined (_LITTLE_ENDIAN) || defined(__LITTLE_ENDIAN)
36 x = ((x >> 8) & 0x00FF) | ((x << 8) & 0xFF00);
37#endif
38 return x;
39}
40
41unsigned short ntohs(unsigned short x) {
42#if defined (LITTLE_ENDIAN) || defined (_LITTLE_ENDIAN) || defined(__LITTLE_ENDIAN)
43 x = ((x >> 8) & 0x00FF) | ((x << 8) & 0xFF00);
44#endif
45 return x;
46}
47
48/* just to test stuff
49#include <stdio.h>
50
51main () {
52 long x;
53 short sx;
54
55 x = 0x000000FF;
56 printf ("before %i, ",(int)x);
57 x = htonl (x);
58 printf ("after %i\n",(int)x);
59
60 x = 0x0000FF00;
61 printf ("before %i, ",(int)x);
62 x = htonl (x);
63 printf ("after %i\n",(int)x);
64
65 x = 0x00FF0000;
66 printf ("before %i, ",(int)x);
67 x = htonl (x);
68 printf ("after %i\n",(int)x);
69
70 x = 0xFF000000;
71 printf ("before %i, ",(int)x);
72 x = htonl (x);
73 printf ("after %i\n\n",(int)x);
74
75 sx = 0x00FF;
76 printf ("before %i, ",(int)sx);
77 sx = htons (sx);
78 printf ("after %i\n",(int)sx);
79
80 sx = 0xFF00;
81 printf ("before %i, ",(int)sx);
82 sx = htons (sx);
83 printf ("after %i\n",(int)sx);
84}
85*/
Note: See TracBrowser for help on using the repository browser.