source: trunk/indexers/mg/lib/win32in.c@ 3745

Last change on this file since 3745 was 3745, checked in by mdewsnip, 21 years ago

Addition of MG package for search and retrieval

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