fix doc example typo
[boost.git] / boost / asio / detail / old_win_sdk_compat.hpp
blob5f0aba1d4d41ba337c152dad2b7063269237bc0f
1 //
2 // old_win_sdk_compat.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 //
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 //
11 #ifndef BOOST_ASIO_DETAIL_OLD_WIN_SDK_COMPAT_HPP
12 #define BOOST_ASIO_DETAIL_OLD_WIN_SDK_COMPAT_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/push_options.hpp>
20 #include <boost/asio/detail/push_options.hpp>
21 #include <boost/config.hpp>
22 #include <boost/asio/detail/pop_options.hpp>
24 #if defined(BOOST_WINDOWS) || defined(__CYGWIN__)
26 // Guess whether we are building against on old Platform SDK.
27 #if !defined(IN6ADDR_ANY_INIT)
28 #define BOOST_ASIO_HAS_OLD_WIN_SDK 1
29 #endif // !defined(IN6ADDR_ANY_INIT)
31 #if defined(BOOST_ASIO_HAS_OLD_WIN_SDK)
33 // Emulation of types that are missing from old Platform SDKs.
35 // N.B. this emulation is also used if building for a Windows 2000 target with
36 // a recent (i.e. Vista or later) SDK, as the SDK does not provide IPv6 support
37 // in that case.
39 namespace boost {
40 namespace asio {
41 namespace detail {
43 enum
45 sockaddr_storage_maxsize = 128, // Maximum size.
46 sockaddr_storage_alignsize = (sizeof(__int64)), // Desired alignment.
47 sockaddr_storage_pad1size = (sockaddr_storage_alignsize - sizeof(short)),
48 sockaddr_storage_pad2size = (sockaddr_storage_maxsize -
49 (sizeof(short) + sockaddr_storage_pad1size + sockaddr_storage_alignsize))
52 struct sockaddr_storage_emulation
54 short ss_family;
55 char __ss_pad1[sockaddr_storage_pad1size];
56 __int64 __ss_align;
57 char __ss_pad2[sockaddr_storage_pad2size];
60 struct in6_addr_emulation
62 union
64 u_char Byte[16];
65 u_short Word[8];
66 } u;
69 #if !defined(s6_addr)
70 # define _S6_un u
71 # define _S6_u8 Byte
72 # define s6_addr _S6_un._S6_u8
73 #endif // !defined(s6_addr)
75 struct sockaddr_in6_emulation
77 short sin6_family;
78 u_short sin6_port;
79 u_long sin6_flowinfo;
80 in6_addr_emulation sin6_addr;
81 u_long sin6_scope_id;
84 struct ipv6_mreq_emulation
86 in6_addr_emulation ipv6mr_multiaddr;
87 unsigned int ipv6mr_interface;
90 #if !defined(IN6ADDR_ANY_INIT)
91 # define IN6ADDR_ANY_INIT { 0 }
92 #endif
94 #if !defined(IN6ADDR_LOOPBACK_INIT)
95 # define IN6ADDR_LOOPBACK_INIT { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 }
96 #endif
98 struct addrinfo_emulation
100 int ai_flags;
101 int ai_family;
102 int ai_socktype;
103 int ai_protocol;
104 size_t ai_addrlen;
105 char* ai_canonname;
106 sockaddr* ai_addr;
107 addrinfo_emulation* ai_next;
110 #if !defined(AI_PASSIVE)
111 # define AI_PASSIVE 0x1
112 #endif
114 #if !defined(AI_CANONNAME)
115 # define AI_CANONNAME 0x2
116 #endif
118 #if !defined(AI_NUMERICHOST)
119 # define AI_NUMERICHOST 0x4
120 #endif
122 #if !defined(EAI_AGAIN)
123 # define EAI_AGAIN WSATRY_AGAIN
124 #endif
126 #if !defined(EAI_BADFLAGS)
127 # define EAI_BADFLAGS WSAEINVAL
128 #endif
130 #if !defined(EAI_FAIL)
131 # define EAI_FAIL WSANO_RECOVERY
132 #endif
134 #if !defined(EAI_FAMILY)
135 # define EAI_FAMILY WSAEAFNOSUPPORT
136 #endif
138 #if !defined(EAI_MEMORY)
139 # define EAI_MEMORY WSA_NOT_ENOUGH_MEMORY
140 #endif
142 #if !defined(EAI_NODATA)
143 # define EAI_NODATA WSANO_DATA
144 #endif
146 #if !defined(EAI_NONAME)
147 # define EAI_NONAME WSAHOST_NOT_FOUND
148 #endif
150 #if !defined(EAI_SERVICE)
151 # define EAI_SERVICE WSATYPE_NOT_FOUND
152 #endif
154 #if !defined(EAI_SOCKTYPE)
155 # define EAI_SOCKTYPE WSAESOCKTNOSUPPORT
156 #endif
158 #if !defined(NI_NOFQDN)
159 # define NI_NOFQDN 0x01
160 #endif
162 #if !defined(NI_NUMERICHOST)
163 # define NI_NUMERICHOST 0x02
164 #endif
166 #if !defined(NI_NAMEREQD)
167 # define NI_NAMEREQD 0x04
168 #endif
170 #if !defined(NI_NUMERICSERV)
171 # define NI_NUMERICSERV 0x08
172 #endif
174 #if !defined(NI_DGRAM)
175 # define NI_DGRAM 0x10
176 #endif
178 #if !defined(IPPROTO_IPV6)
179 # define IPPROTO_IPV6 41
180 #endif
182 #if !defined(IPV6_UNICAST_HOPS)
183 # define IPV6_UNICAST_HOPS 4
184 #endif
186 #if !defined(IPV6_MULTICAST_IF)
187 # define IPV6_MULTICAST_IF 9
188 #endif
190 #if !defined(IPV6_MULTICAST_HOPS)
191 # define IPV6_MULTICAST_HOPS 10
192 #endif
194 #if !defined(IPV6_MULTICAST_LOOP)
195 # define IPV6_MULTICAST_LOOP 11
196 #endif
198 #if !defined(IPV6_JOIN_GROUP)
199 # define IPV6_JOIN_GROUP 12
200 #endif
202 #if !defined(IPV6_LEAVE_GROUP)
203 # define IPV6_LEAVE_GROUP 13
204 #endif
206 inline int IN6_IS_ADDR_UNSPECIFIED(const in6_addr_emulation* a)
208 return ((a->s6_addr[0] == 0)
209 && (a->s6_addr[1] == 0)
210 && (a->s6_addr[2] == 0)
211 && (a->s6_addr[3] == 0)
212 && (a->s6_addr[4] == 0)
213 && (a->s6_addr[5] == 0)
214 && (a->s6_addr[6] == 0)
215 && (a->s6_addr[7] == 0)
216 && (a->s6_addr[8] == 0)
217 && (a->s6_addr[9] == 0)
218 && (a->s6_addr[10] == 0)
219 && (a->s6_addr[11] == 0)
220 && (a->s6_addr[12] == 0)
221 && (a->s6_addr[13] == 0)
222 && (a->s6_addr[14] == 0)
223 && (a->s6_addr[15] == 0));
226 inline int IN6_IS_ADDR_LOOPBACK(const in6_addr_emulation* a)
228 return ((a->s6_addr[0] == 0)
229 && (a->s6_addr[1] == 0)
230 && (a->s6_addr[2] == 0)
231 && (a->s6_addr[3] == 0)
232 && (a->s6_addr[4] == 0)
233 && (a->s6_addr[5] == 0)
234 && (a->s6_addr[6] == 0)
235 && (a->s6_addr[7] == 0)
236 && (a->s6_addr[8] == 0)
237 && (a->s6_addr[9] == 0)
238 && (a->s6_addr[10] == 0)
239 && (a->s6_addr[11] == 0)
240 && (a->s6_addr[12] == 0)
241 && (a->s6_addr[13] == 0)
242 && (a->s6_addr[14] == 0)
243 && (a->s6_addr[15] == 1));
246 inline int IN6_IS_ADDR_MULTICAST(const in6_addr_emulation* a)
248 return (a->s6_addr[0] == 0xff);
251 inline int IN6_IS_ADDR_LINKLOCAL(const in6_addr_emulation* a)
253 return ((a->s6_addr[0] == 0xfe) && ((a->s6_addr[1] & 0xc0) == 0x80));
256 inline int IN6_IS_ADDR_SITELOCAL(const in6_addr_emulation* a)
258 return ((a->s6_addr[0] == 0xfe) && ((a->s6_addr[1] & 0xc0) == 0xc0));
261 inline int IN6_IS_ADDR_V4MAPPED(const in6_addr_emulation* a)
263 return ((a->s6_addr[0] == 0)
264 && (a->s6_addr[1] == 0)
265 && (a->s6_addr[2] == 0)
266 && (a->s6_addr[3] == 0)
267 && (a->s6_addr[4] == 0)
268 && (a->s6_addr[5] == 0)
269 && (a->s6_addr[6] == 0)
270 && (a->s6_addr[7] == 0)
271 && (a->s6_addr[8] == 0)
272 && (a->s6_addr[9] == 0)
273 && (a->s6_addr[10] == 0xff)
274 && (a->s6_addr[11] == 0xff));
277 inline int IN6_IS_ADDR_V4COMPAT(const in6_addr_emulation* a)
279 return ((a->s6_addr[0] == 0)
280 && (a->s6_addr[1] == 0)
281 && (a->s6_addr[2] == 0)
282 && (a->s6_addr[3] == 0)
283 && (a->s6_addr[4] == 0)
284 && (a->s6_addr[5] == 0)
285 && (a->s6_addr[6] == 0)
286 && (a->s6_addr[7] == 0)
287 && (a->s6_addr[8] == 0)
288 && (a->s6_addr[9] == 0)
289 && (a->s6_addr[10] == 0xff)
290 && (a->s6_addr[11] == 0xff)
291 && !((a->s6_addr[12] == 0)
292 && (a->s6_addr[13] == 0)
293 && (a->s6_addr[14] == 0)
294 && ((a->s6_addr[15] == 0) || (a->s6_addr[15] == 1))));
297 inline int IN6_IS_ADDR_MC_NODELOCAL(const in6_addr_emulation* a)
299 return IN6_IS_ADDR_MULTICAST(a) && ((a->s6_addr[1] & 0xf) == 1);
302 inline int IN6_IS_ADDR_MC_LINKLOCAL(const in6_addr_emulation* a)
304 return IN6_IS_ADDR_MULTICAST(a) && ((a->s6_addr[1] & 0xf) == 2);
307 inline int IN6_IS_ADDR_MC_SITELOCAL(const in6_addr_emulation* a)
309 return IN6_IS_ADDR_MULTICAST(a) && ((a->s6_addr[1] & 0xf) == 5);
312 inline int IN6_IS_ADDR_MC_ORGLOCAL(const in6_addr_emulation* a)
314 return IN6_IS_ADDR_MULTICAST(a) && ((a->s6_addr[1] & 0xf) == 8);
317 inline int IN6_IS_ADDR_MC_GLOBAL(const in6_addr_emulation* a)
319 return IN6_IS_ADDR_MULTICAST(a) && ((a->s6_addr[1] & 0xf) == 0xe);
322 } // namespace detail
323 } // namespace asio
324 } // namespace boost
326 #endif // defined(BOOST_ASIO_HAS_OLD_WIN_SDK)
328 // Even newer Platform SDKs that support IPv6 may not define IPV6_V6ONLY.
329 #if !defined(IPV6_V6ONLY)
330 # define IPV6_V6ONLY 27
331 #endif
333 // Some SDKs (e.g. Windows CE) don't define IPPROTO_ICMPV6.
334 #if !defined(IPPROTO_ICMPV6)
335 # define IPPROTO_ICMPV6 58
336 #endif
338 #endif // defined(BOOST_WINDOWS) || defined(__CYGWIN__)
340 #include <boost/asio/detail/pop_options.hpp>
342 #endif // BOOST_ASIO_DETAIL_OLD_WIN_SDK_COMPAT_HPP