1 //
2 // detail/old_win_sdk_compat.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2016 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 //
10 
11 #ifndef ASIO_DETAIL_OLD_WIN_SDK_COMPAT_HPP
12 #define ASIO_DETAIL_OLD_WIN_SDK_COMPAT_HPP
13 
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17 
18 #include "asio/detail/config.hpp"
19 
20 #if defined(ASIO_WINDOWS) || defined(__CYGWIN__)
21 
22 // Guess whether we are building against on old Platform SDK.
23 #if !defined(IN6ADDR_ANY_INIT)
24 #define ASIO_HAS_OLD_WIN_SDK 1
25 #endif // !defined(IN6ADDR_ANY_INIT)
26 
27 #if defined(ASIO_HAS_OLD_WIN_SDK)
28 
29 // Emulation of types that are missing from old Platform SDKs.
30 //
31 // N.B. this emulation is also used if building for a Windows 2000 target with
32 // a recent (i.e. Vista or later) SDK, as the SDK does not provide IPv6 support
33 // in that case.
34 
35 #include "asio/detail/push_options.hpp"
36 
37 namespace asio {
38 namespace detail {
39 
40 enum
41 {
42   sockaddr_storage_maxsize = 128, // Maximum size.
43   sockaddr_storage_alignsize = (sizeof(__int64)), // Desired alignment.
44   sockaddr_storage_pad1size = (sockaddr_storage_alignsize - sizeof(short)),
45   sockaddr_storage_pad2size = (sockaddr_storage_maxsize -
46       (sizeof(short) + sockaddr_storage_pad1size + sockaddr_storage_alignsize))
47 };
48 
49 struct sockaddr_storage_emulation
50 {
51   short ss_family;
52   char __ss_pad1[sockaddr_storage_pad1size];
53   __int64 __ss_align;
54   char __ss_pad2[sockaddr_storage_pad2size];
55 };
56 
57 struct in6_addr_emulation
58 {
59   union
60   {
61     u_char Byte[16];
62     u_short Word[8];
63   } u;
64 };
65 
66 #if !defined(s6_addr)
67 # define _S6_un u
68 # define _S6_u8 Byte
69 # define s6_addr _S6_un._S6_u8
70 #endif // !defined(s6_addr)
71 
72 struct sockaddr_in6_emulation
73 {
74   short sin6_family;
75   u_short sin6_port;
76   u_long sin6_flowinfo;
77   in6_addr_emulation sin6_addr;
78   u_long sin6_scope_id;
79 };
80 
81 struct ipv6_mreq_emulation
82 {
83   in6_addr_emulation ipv6mr_multiaddr;
84   unsigned int ipv6mr_interface;
85 };
86 
87 struct addrinfo_emulation
88 {
89   int ai_flags;
90   int ai_family;
91   int ai_socktype;
92   int ai_protocol;
93   size_t ai_addrlen;
94   char* ai_canonname;
95   sockaddr* ai_addr;
96   addrinfo_emulation* ai_next;
97 };
98 
99 #if !defined(AI_PASSIVE)
100 # define AI_PASSIVE 0x1
101 #endif
102 
103 #if !defined(AI_CANONNAME)
104 # define AI_CANONNAME 0x2
105 #endif
106 
107 #if !defined(AI_NUMERICHOST)
108 # define AI_NUMERICHOST 0x4
109 #endif
110 
111 #if !defined(EAI_AGAIN)
112 # define EAI_AGAIN WSATRY_AGAIN
113 #endif
114 
115 #if !defined(EAI_BADFLAGS)
116 # define EAI_BADFLAGS WSAEINVAL
117 #endif
118 
119 #if !defined(EAI_FAIL)
120 # define EAI_FAIL WSANO_RECOVERY
121 #endif
122 
123 #if !defined(EAI_FAMILY)
124 # define EAI_FAMILY WSAEAFNOSUPPORT
125 #endif
126 
127 #if !defined(EAI_MEMORY)
128 # define EAI_MEMORY WSA_NOT_ENOUGH_MEMORY
129 #endif
130 
131 #if !defined(EAI_NODATA)
132 # define EAI_NODATA WSANO_DATA
133 #endif
134 
135 #if !defined(EAI_NONAME)
136 # define EAI_NONAME WSAHOST_NOT_FOUND
137 #endif
138 
139 #if !defined(EAI_SERVICE)
140 # define EAI_SERVICE WSATYPE_NOT_FOUND
141 #endif
142 
143 #if !defined(EAI_SOCKTYPE)
144 # define EAI_SOCKTYPE WSAESOCKTNOSUPPORT
145 #endif
146 
147 #if !defined(NI_NOFQDN)
148 # define NI_NOFQDN 0x01
149 #endif
150 
151 #if !defined(NI_NUMERICHOST)
152 # define NI_NUMERICHOST 0x02
153 #endif
154 
155 #if !defined(NI_NAMEREQD)
156 # define NI_NAMEREQD 0x04
157 #endif
158 
159 #if !defined(NI_NUMERICSERV)
160 # define NI_NUMERICSERV 0x08
161 #endif
162 
163 #if !defined(NI_DGRAM)
164 # define NI_DGRAM 0x10
165 #endif
166 
167 #if !defined(IPPROTO_IPV6)
168 # define IPPROTO_IPV6 41
169 #endif
170 
171 #if !defined(IPV6_UNICAST_HOPS)
172 # define IPV6_UNICAST_HOPS 4
173 #endif
174 
175 #if !defined(IPV6_MULTICAST_IF)
176 # define IPV6_MULTICAST_IF 9
177 #endif
178 
179 #if !defined(IPV6_MULTICAST_HOPS)
180 # define IPV6_MULTICAST_HOPS 10
181 #endif
182 
183 #if !defined(IPV6_MULTICAST_LOOP)
184 # define IPV6_MULTICAST_LOOP 11
185 #endif
186 
187 #if !defined(IPV6_JOIN_GROUP)
188 # define IPV6_JOIN_GROUP 12
189 #endif
190 
191 #if !defined(IPV6_LEAVE_GROUP)
192 # define IPV6_LEAVE_GROUP 13
193 #endif
194 
195 } // namespace detail
196 } // namespace asio
197 
198 #include "asio/detail/pop_options.hpp"
199 
200 #endif // defined(ASIO_HAS_OLD_WIN_SDK)
201 
202 // Even newer Platform SDKs that support IPv6 may not define IPV6_V6ONLY.
203 #if !defined(IPV6_V6ONLY)
204 # define IPV6_V6ONLY 27
205 #endif
206 
207 // Some SDKs (e.g. Windows CE) don't define IPPROTO_ICMPV6.
208 #if !defined(IPPROTO_ICMPV6)
209 # define IPPROTO_ICMPV6 58
210 #endif
211 
212 #endif // defined(ASIO_WINDOWS) || defined(__CYGWIN__)
213 
214 #endif // ASIO_DETAIL_OLD_WIN_SDK_COMPAT_HPP
215