Watt-32 tcp/ip  2.2 dev-rel.10
getput.c
Go to the documentation of this file.
1 
6 /* Copyright (c) 1997-2002 Gisle Vanem <gvanem@yahoo.no>
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution.
16  * 3. All advertising materials mentioning features or use of this software
17  * must display the following acknowledgement:
18  * This product includes software developed by Gisle Vanem
19  * Bergen, Norway.
20  *
21  * THIS SOFTWARE IS PROVIDED BY ME (Gisle Vanem) AND CONTRIBUTORS ``AS IS''
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL I OR CONTRIBUTORS BE LIABLE FOR ANY
25  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  */
33 
34 #include <arpa/nameser.h>
35 #include <resolv.h>
36 
37 #include "wattcp.h"
38 #include "chksum.h"
39 #include "misc.h"
40 
41 #undef GETSHORT
42 #undef GETLONG
43 #undef PUTSHORT
44 #undef PUTLONG
45 
46 
47 /*
48  * Functions for get/put short/long. Pointer is _NOT_ advanced.
49  */
50 #if !defined(USE_BIGENDIAN)
51 
52 #define GETSHORT(s, cp) { \
53  BYTE *t_cp = (BYTE*)(cp); \
54  (s) = ((WORD)t_cp[0] << 8) \
55  | ((WORD)t_cp[1]); \
56  }
57 
58 #define GETLONG(l, cp) { \
59  BYTE *t_cp = (BYTE*)(cp); \
60  (l) = ((DWORD)t_cp[0] << 24) \
61  | ((DWORD)t_cp[1] << 16) \
62  | ((DWORD)t_cp[2] << 8) \
63  | ((DWORD)t_cp[3]); \
64  }
65 
66 #define PUTSHORT(s, cp) { \
67  WORD t_s = (WORD)(s); \
68  BYTE *t_cp = (BYTE*)(cp); \
69  *t_cp++ = (BYTE)(t_s >> 8); \
70  *t_cp = (BYTE)t_s; \
71  }
72 
73 #define PUTLONG(l, cp) { \
74  DWORD t_l = (DWORD)(l); \
75  BYTE *t_cp = (BYTE*)(cp); \
76  *t_cp++ = (BYTE)(t_l >> 24); \
77  *t_cp++ = (BYTE)(t_l >> 16); \
78  *t_cp++ = (BYTE)(t_l >> 8); \
79  *t_cp = (BYTE)t_l; \
80  }
81 
82 
83 WORD W32_CALL _getshort (const BYTE *x) /* in <arpa/nameserv.h> */
84 {
85  WORD res;
86  GETSHORT (res, x);
87  return (res);
88 }
89 
90 DWORD W32_CALL _getlong (const BYTE *x) /* in <arpa/nameserv.h> */
91 {
92  DWORD res;
93  GETLONG (res, x);
94  return (res);
95 }
96 
97 void W32_CALL __putshort (WORD var, BYTE *ptr) /* in <resolv.h> */
98 {
99  PUTSHORT (var, ptr);
100 }
101 
102 void W32_CALL __putlong (DWORD var, BYTE *ptr) /* in <resolv.h> */
103 {
104  PUTLONG (var, ptr);
105 }
106 
107 /*
108  * If compiler/linker doesn't see our defines for htonl() etc.
109  */
110 #undef htonl
111 #undef ntohl
112 #undef htons
113 #undef ntohs
114 
115 DWORD W32_CALL htonl (DWORD val)
116 {
117  return intel (val);
118 }
119 DWORD W32_CALL ntohl (DWORD val)
120 {
121  return intel (val);
122 }
123 WORD W32_CALL htons (WORD val)
124 {
125  return intel16 (val);
126 }
127 WORD W32_CALL ntohs (WORD val)
128 {
129  return intel16 (val);
130 }
131 #endif /* USE_BIGENDIAN */
Core definitions.