2
// old_win_sdk_compat.hpp
3
// ~~~~~~~~~~~~~~~~~~~~~~
5
// Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com)
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)
11
#ifndef ASIO_DETAIL_OLD_WIN_SDK_COMPAT_HPP
12
#define ASIO_DETAIL_OLD_WIN_SDK_COMPAT_HPP
14
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
16
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18
#include "asio/detail/push_options.hpp"
20
#include "asio/detail/push_options.hpp"
21
#include <boost/config.hpp>
22
#include "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 ASIO_HAS_OLD_WIN_SDK 1
29
#endif // !defined(IN6ADDR_ANY_INIT)
31
#if defined(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
44
sockaddr_storage_maxsize = 128, // Maximum size.
45
sockaddr_storage_alignsize = (sizeof(__int64)), // Desired alignment.
46
sockaddr_storage_pad1size = (sockaddr_storage_alignsize - sizeof(short)),
47
sockaddr_storage_pad2size = (sockaddr_storage_maxsize -
48
(sizeof(short) + sockaddr_storage_pad1size + sockaddr_storage_alignsize))
51
struct sockaddr_storage_emulation
54
char __ss_pad1[sockaddr_storage_pad1size];
56
char __ss_pad2[sockaddr_storage_pad2size];
59
struct in6_addr_emulation
71
# define s6_addr _S6_un._S6_u8
72
#endif // !defined(s6_addr)
74
struct sockaddr_in6_emulation
79
in6_addr_emulation sin6_addr;
83
struct ipv6_mreq_emulation
85
in6_addr_emulation ipv6mr_multiaddr;
86
unsigned int ipv6mr_interface;
89
#if !defined(IN6ADDR_ANY_INIT)
90
# define IN6ADDR_ANY_INIT { 0 }
93
#if !defined(IN6ADDR_LOOPBACK_INIT)
94
# define IN6ADDR_LOOPBACK_INIT { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 }
97
struct addrinfo_emulation
106
addrinfo_emulation* ai_next;
109
#if !defined(AI_PASSIVE)
110
# define AI_PASSIVE 0x1
113
#if !defined(AI_CANONNAME)
114
# define AI_CANONNAME 0x2
117
#if !defined(AI_NUMERICHOST)
118
# define AI_NUMERICHOST 0x4
121
#if !defined(EAI_AGAIN)
122
# define EAI_AGAIN WSATRY_AGAIN
125
#if !defined(EAI_BADFLAGS)
126
# define EAI_BADFLAGS WSAEINVAL
129
#if !defined(EAI_FAIL)
130
# define EAI_FAIL WSANO_RECOVERY
133
#if !defined(EAI_FAMILY)
134
# define EAI_FAMILY WSAEAFNOSUPPORT
137
#if !defined(EAI_MEMORY)
138
# define EAI_MEMORY WSA_NOT_ENOUGH_MEMORY
141
#if !defined(EAI_NODATA)
142
# define EAI_NODATA WSANO_DATA
145
#if !defined(EAI_NONAME)
146
# define EAI_NONAME WSAHOST_NOT_FOUND
149
#if !defined(EAI_SERVICE)
150
# define EAI_SERVICE WSATYPE_NOT_FOUND
153
#if !defined(EAI_SOCKTYPE)
154
# define EAI_SOCKTYPE WSAESOCKTNOSUPPORT
157
#if !defined(NI_NOFQDN)
158
# define NI_NOFQDN 0x01
161
#if !defined(NI_NUMERICHOST)
162
# define NI_NUMERICHOST 0x02
165
#if !defined(NI_NAMEREQD)
166
# define NI_NAMEREQD 0x04
169
#if !defined(NI_NUMERICSERV)
170
# define NI_NUMERICSERV 0x08
173
#if !defined(NI_DGRAM)
174
# define NI_DGRAM 0x10
177
#if !defined(IPPROTO_IPV6)
178
# define IPPROTO_IPV6 41
181
#if !defined(IPV6_UNICAST_HOPS)
182
# define IPV6_UNICAST_HOPS 4
185
#if !defined(IPV6_MULTICAST_IF)
186
# define IPV6_MULTICAST_IF 9
189
#if !defined(IPV6_MULTICAST_HOPS)
190
# define IPV6_MULTICAST_HOPS 10
193
#if !defined(IPV6_MULTICAST_LOOP)
194
# define IPV6_MULTICAST_LOOP 11
197
#if !defined(IPV6_JOIN_GROUP)
198
# define IPV6_JOIN_GROUP 12
201
#if !defined(IPV6_LEAVE_GROUP)
202
# define IPV6_LEAVE_GROUP 13
205
inline int IN6_IS_ADDR_UNSPECIFIED(const in6_addr_emulation* a)
207
return ((a->s6_addr[0] == 0)
208
&& (a->s6_addr[1] == 0)
209
&& (a->s6_addr[2] == 0)
210
&& (a->s6_addr[3] == 0)
211
&& (a->s6_addr[4] == 0)
212
&& (a->s6_addr[5] == 0)
213
&& (a->s6_addr[6] == 0)
214
&& (a->s6_addr[7] == 0)
215
&& (a->s6_addr[8] == 0)
216
&& (a->s6_addr[9] == 0)
217
&& (a->s6_addr[10] == 0)
218
&& (a->s6_addr[11] == 0)
219
&& (a->s6_addr[12] == 0)
220
&& (a->s6_addr[13] == 0)
221
&& (a->s6_addr[14] == 0)
222
&& (a->s6_addr[15] == 0));
225
inline int IN6_IS_ADDR_LOOPBACK(const in6_addr_emulation* a)
227
return ((a->s6_addr[0] == 0)
228
&& (a->s6_addr[1] == 0)
229
&& (a->s6_addr[2] == 0)
230
&& (a->s6_addr[3] == 0)
231
&& (a->s6_addr[4] == 0)
232
&& (a->s6_addr[5] == 0)
233
&& (a->s6_addr[6] == 0)
234
&& (a->s6_addr[7] == 0)
235
&& (a->s6_addr[8] == 0)
236
&& (a->s6_addr[9] == 0)
237
&& (a->s6_addr[10] == 0)
238
&& (a->s6_addr[11] == 0)
239
&& (a->s6_addr[12] == 0)
240
&& (a->s6_addr[13] == 0)
241
&& (a->s6_addr[14] == 0)
242
&& (a->s6_addr[15] == 1));
245
inline int IN6_IS_ADDR_MULTICAST(const in6_addr_emulation* a)
247
return (a->s6_addr[0] == 0xff);
250
inline int IN6_IS_ADDR_LINKLOCAL(const in6_addr_emulation* a)
252
return ((a->s6_addr[0] == 0xfe) && ((a->s6_addr[1] & 0xc0) == 0x80));
255
inline int IN6_IS_ADDR_SITELOCAL(const in6_addr_emulation* a)
257
return ((a->s6_addr[0] == 0xfe) && ((a->s6_addr[1] & 0xc0) == 0xc0));
260
inline int IN6_IS_ADDR_V4MAPPED(const in6_addr_emulation* a)
262
return ((a->s6_addr[0] == 0)
263
&& (a->s6_addr[1] == 0)
264
&& (a->s6_addr[2] == 0)
265
&& (a->s6_addr[3] == 0)
266
&& (a->s6_addr[4] == 0)
267
&& (a->s6_addr[5] == 0)
268
&& (a->s6_addr[6] == 0)
269
&& (a->s6_addr[7] == 0)
270
&& (a->s6_addr[8] == 0)
271
&& (a->s6_addr[9] == 0)
272
&& (a->s6_addr[10] == 0xff)
273
&& (a->s6_addr[11] == 0xff));
276
inline int IN6_IS_ADDR_V4COMPAT(const in6_addr_emulation* a)
278
return ((a->s6_addr[0] == 0)
279
&& (a->s6_addr[1] == 0)
280
&& (a->s6_addr[2] == 0)
281
&& (a->s6_addr[3] == 0)
282
&& (a->s6_addr[4] == 0)
283
&& (a->s6_addr[5] == 0)
284
&& (a->s6_addr[6] == 0)
285
&& (a->s6_addr[7] == 0)
286
&& (a->s6_addr[8] == 0)
287
&& (a->s6_addr[9] == 0)
288
&& (a->s6_addr[10] == 0xff)
289
&& (a->s6_addr[11] == 0xff)
290
&& !((a->s6_addr[12] == 0)
291
&& (a->s6_addr[13] == 0)
292
&& (a->s6_addr[14] == 0)
293
&& ((a->s6_addr[15] == 0) || (a->s6_addr[15] == 1))));
296
inline int IN6_IS_ADDR_MC_NODELOCAL(const in6_addr_emulation* a)
298
return IN6_IS_ADDR_MULTICAST(a) && ((a->s6_addr[1] & 0xf) == 1);
301
inline int IN6_IS_ADDR_MC_LINKLOCAL(const in6_addr_emulation* a)
303
return IN6_IS_ADDR_MULTICAST(a) && ((a->s6_addr[1] & 0xf) == 2);
306
inline int IN6_IS_ADDR_MC_SITELOCAL(const in6_addr_emulation* a)
308
return IN6_IS_ADDR_MULTICAST(a) && ((a->s6_addr[1] & 0xf) == 5);
311
inline int IN6_IS_ADDR_MC_ORGLOCAL(const in6_addr_emulation* a)
313
return IN6_IS_ADDR_MULTICAST(a) && ((a->s6_addr[1] & 0xf) == 8);
316
inline int IN6_IS_ADDR_MC_GLOBAL(const in6_addr_emulation* a)
318
return IN6_IS_ADDR_MULTICAST(a) && ((a->s6_addr[1] & 0xf) == 0xe);
321
} // namespace detail
324
#endif // defined(ASIO_HAS_OLD_WIN_SDK)
326
// Even newer Platform SDKs that support IPv6 may not define IPV6_V6ONLY.
327
#if !defined(IPV6_V6ONLY)
328
# define IPV6_V6ONLY 27
331
// Some SDKs (e.g. Windows CE) don't define IPPROTO_ICMPV6.
332
#if !defined(IPPROTO_ICMPV6)
333
# define IPPROTO_ICMPV6 58
336
#endif // defined(BOOST_WINDOWS) || defined(__CYGWIN__)
338
#include "asio/detail/pop_options.hpp"
340
#endif // ASIO_DETAIL_OLD_WIN_SDK_COMPAT_HPP