$search
00001 // 00002 // old_win_sdk_compat.hpp 00003 // ~~~~~~~~~~~~~~~~~~~~~~ 00004 // 00005 // Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com) 00006 // 00007 // Distributed under the Boost Software License, Version 1.0. (See accompanying 00008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 00009 // 00010 00011 #ifndef ASIO_DETAIL_OLD_WIN_SDK_COMPAT_HPP 00012 #define ASIO_DETAIL_OLD_WIN_SDK_COMPAT_HPP 00013 00014 #if defined(_MSC_VER) && (_MSC_VER >= 1200) 00015 # pragma once 00016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) 00017 00018 #include "asio/detail/push_options.hpp" 00019 00020 #include "asio/detail/push_options.hpp" 00021 #include <boost/config.hpp> 00022 #include "asio/detail/pop_options.hpp" 00023 00024 #if defined(BOOST_WINDOWS) || defined(__CYGWIN__) 00025 00026 // Guess whether we are building against on old Platform SDK. 00027 #if !defined(IN6ADDR_ANY_INIT) 00028 #define ASIO_HAS_OLD_WIN_SDK 1 00029 #endif // !defined(IN6ADDR_ANY_INIT) 00030 00031 #if defined(ASIO_HAS_OLD_WIN_SDK) 00032 00033 // Emulation of types that are missing from old Platform SDKs. 00034 // 00035 // N.B. this emulation is also used if building for a Windows 2000 target with 00036 // a recent (i.e. Vista or later) SDK, as the SDK does not provide IPv6 support 00037 // in that case. 00038 00039 namespace asio { 00040 namespace detail { 00041 00042 enum 00043 { 00044 sockaddr_storage_maxsize = 128, // Maximum size. 00045 sockaddr_storage_alignsize = (sizeof(__int64)), // Desired alignment. 00046 sockaddr_storage_pad1size = (sockaddr_storage_alignsize - sizeof(short)), 00047 sockaddr_storage_pad2size = (sockaddr_storage_maxsize - 00048 (sizeof(short) + sockaddr_storage_pad1size + sockaddr_storage_alignsize)) 00049 }; 00050 00051 struct sockaddr_storage_emulation 00052 { 00053 short ss_family; 00054 char __ss_pad1[sockaddr_storage_pad1size]; 00055 __int64 __ss_align; 00056 char __ss_pad2[sockaddr_storage_pad2size]; 00057 }; 00058 00059 struct in6_addr_emulation 00060 { 00061 union 00062 { 00063 u_char Byte[16]; 00064 u_short Word[8]; 00065 } u; 00066 }; 00067 00068 #if !defined(s6_addr) 00069 # define _S6_un u 00070 # define _S6_u8 Byte 00071 # define s6_addr _S6_un._S6_u8 00072 #endif // !defined(s6_addr) 00073 00074 struct sockaddr_in6_emulation 00075 { 00076 short sin6_family; 00077 u_short sin6_port; 00078 u_long sin6_flowinfo; 00079 in6_addr_emulation sin6_addr; 00080 u_long sin6_scope_id; 00081 }; 00082 00083 struct ipv6_mreq_emulation 00084 { 00085 in6_addr_emulation ipv6mr_multiaddr; 00086 unsigned int ipv6mr_interface; 00087 }; 00088 00089 #if !defined(IN6ADDR_ANY_INIT) 00090 # define IN6ADDR_ANY_INIT { 0 } 00091 #endif 00092 00093 #if !defined(IN6ADDR_LOOPBACK_INIT) 00094 # define IN6ADDR_LOOPBACK_INIT { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } 00095 #endif 00096 00097 struct addrinfo_emulation 00098 { 00099 int ai_flags; 00100 int ai_family; 00101 int ai_socktype; 00102 int ai_protocol; 00103 size_t ai_addrlen; 00104 char* ai_canonname; 00105 sockaddr* ai_addr; 00106 addrinfo_emulation* ai_next; 00107 }; 00108 00109 #if !defined(AI_PASSIVE) 00110 # define AI_PASSIVE 0x1 00111 #endif 00112 00113 #if !defined(AI_CANONNAME) 00114 # define AI_CANONNAME 0x2 00115 #endif 00116 00117 #if !defined(AI_NUMERICHOST) 00118 # define AI_NUMERICHOST 0x4 00119 #endif 00120 00121 #if !defined(EAI_AGAIN) 00122 # define EAI_AGAIN WSATRY_AGAIN 00123 #endif 00124 00125 #if !defined(EAI_BADFLAGS) 00126 # define EAI_BADFLAGS WSAEINVAL 00127 #endif 00128 00129 #if !defined(EAI_FAIL) 00130 # define EAI_FAIL WSANO_RECOVERY 00131 #endif 00132 00133 #if !defined(EAI_FAMILY) 00134 # define EAI_FAMILY WSAEAFNOSUPPORT 00135 #endif 00136 00137 #if !defined(EAI_MEMORY) 00138 # define EAI_MEMORY WSA_NOT_ENOUGH_MEMORY 00139 #endif 00140 00141 #if !defined(EAI_NODATA) 00142 # define EAI_NODATA WSANO_DATA 00143 #endif 00144 00145 #if !defined(EAI_NONAME) 00146 # define EAI_NONAME WSAHOST_NOT_FOUND 00147 #endif 00148 00149 #if !defined(EAI_SERVICE) 00150 # define EAI_SERVICE WSATYPE_NOT_FOUND 00151 #endif 00152 00153 #if !defined(EAI_SOCKTYPE) 00154 # define EAI_SOCKTYPE WSAESOCKTNOSUPPORT 00155 #endif 00156 00157 #if !defined(NI_NOFQDN) 00158 # define NI_NOFQDN 0x01 00159 #endif 00160 00161 #if !defined(NI_NUMERICHOST) 00162 # define NI_NUMERICHOST 0x02 00163 #endif 00164 00165 #if !defined(NI_NAMEREQD) 00166 # define NI_NAMEREQD 0x04 00167 #endif 00168 00169 #if !defined(NI_NUMERICSERV) 00170 # define NI_NUMERICSERV 0x08 00171 #endif 00172 00173 #if !defined(NI_DGRAM) 00174 # define NI_DGRAM 0x10 00175 #endif 00176 00177 #if !defined(IPPROTO_IPV6) 00178 # define IPPROTO_IPV6 41 00179 #endif 00180 00181 #if !defined(IPV6_UNICAST_HOPS) 00182 # define IPV6_UNICAST_HOPS 4 00183 #endif 00184 00185 #if !defined(IPV6_MULTICAST_IF) 00186 # define IPV6_MULTICAST_IF 9 00187 #endif 00188 00189 #if !defined(IPV6_MULTICAST_HOPS) 00190 # define IPV6_MULTICAST_HOPS 10 00191 #endif 00192 00193 #if !defined(IPV6_MULTICAST_LOOP) 00194 # define IPV6_MULTICAST_LOOP 11 00195 #endif 00196 00197 #if !defined(IPV6_JOIN_GROUP) 00198 # define IPV6_JOIN_GROUP 12 00199 #endif 00200 00201 #if !defined(IPV6_LEAVE_GROUP) 00202 # define IPV6_LEAVE_GROUP 13 00203 #endif 00204 00205 inline int IN6_IS_ADDR_UNSPECIFIED(const in6_addr_emulation* a) 00206 { 00207 return ((a->s6_addr[0] == 0) 00208 && (a->s6_addr[1] == 0) 00209 && (a->s6_addr[2] == 0) 00210 && (a->s6_addr[3] == 0) 00211 && (a->s6_addr[4] == 0) 00212 && (a->s6_addr[5] == 0) 00213 && (a->s6_addr[6] == 0) 00214 && (a->s6_addr[7] == 0) 00215 && (a->s6_addr[8] == 0) 00216 && (a->s6_addr[9] == 0) 00217 && (a->s6_addr[10] == 0) 00218 && (a->s6_addr[11] == 0) 00219 && (a->s6_addr[12] == 0) 00220 && (a->s6_addr[13] == 0) 00221 && (a->s6_addr[14] == 0) 00222 && (a->s6_addr[15] == 0)); 00223 } 00224 00225 inline int IN6_IS_ADDR_LOOPBACK(const in6_addr_emulation* a) 00226 { 00227 return ((a->s6_addr[0] == 0) 00228 && (a->s6_addr[1] == 0) 00229 && (a->s6_addr[2] == 0) 00230 && (a->s6_addr[3] == 0) 00231 && (a->s6_addr[4] == 0) 00232 && (a->s6_addr[5] == 0) 00233 && (a->s6_addr[6] == 0) 00234 && (a->s6_addr[7] == 0) 00235 && (a->s6_addr[8] == 0) 00236 && (a->s6_addr[9] == 0) 00237 && (a->s6_addr[10] == 0) 00238 && (a->s6_addr[11] == 0) 00239 && (a->s6_addr[12] == 0) 00240 && (a->s6_addr[13] == 0) 00241 && (a->s6_addr[14] == 0) 00242 && (a->s6_addr[15] == 1)); 00243 } 00244 00245 inline int IN6_IS_ADDR_MULTICAST(const in6_addr_emulation* a) 00246 { 00247 return (a->s6_addr[0] == 0xff); 00248 } 00249 00250 inline int IN6_IS_ADDR_LINKLOCAL(const in6_addr_emulation* a) 00251 { 00252 return ((a->s6_addr[0] == 0xfe) && ((a->s6_addr[1] & 0xc0) == 0x80)); 00253 } 00254 00255 inline int IN6_IS_ADDR_SITELOCAL(const in6_addr_emulation* a) 00256 { 00257 return ((a->s6_addr[0] == 0xfe) && ((a->s6_addr[1] & 0xc0) == 0xc0)); 00258 } 00259 00260 inline int IN6_IS_ADDR_V4MAPPED(const in6_addr_emulation* a) 00261 { 00262 return ((a->s6_addr[0] == 0) 00263 && (a->s6_addr[1] == 0) 00264 && (a->s6_addr[2] == 0) 00265 && (a->s6_addr[3] == 0) 00266 && (a->s6_addr[4] == 0) 00267 && (a->s6_addr[5] == 0) 00268 && (a->s6_addr[6] == 0) 00269 && (a->s6_addr[7] == 0) 00270 && (a->s6_addr[8] == 0) 00271 && (a->s6_addr[9] == 0) 00272 && (a->s6_addr[10] == 0xff) 00273 && (a->s6_addr[11] == 0xff)); 00274 } 00275 00276 inline int IN6_IS_ADDR_V4COMPAT(const in6_addr_emulation* a) 00277 { 00278 return ((a->s6_addr[0] == 0) 00279 && (a->s6_addr[1] == 0) 00280 && (a->s6_addr[2] == 0) 00281 && (a->s6_addr[3] == 0) 00282 && (a->s6_addr[4] == 0) 00283 && (a->s6_addr[5] == 0) 00284 && (a->s6_addr[6] == 0) 00285 && (a->s6_addr[7] == 0) 00286 && (a->s6_addr[8] == 0) 00287 && (a->s6_addr[9] == 0) 00288 && (a->s6_addr[10] == 0xff) 00289 && (a->s6_addr[11] == 0xff) 00290 && !((a->s6_addr[12] == 0) 00291 && (a->s6_addr[13] == 0) 00292 && (a->s6_addr[14] == 0) 00293 && ((a->s6_addr[15] == 0) || (a->s6_addr[15] == 1)))); 00294 } 00295 00296 inline int IN6_IS_ADDR_MC_NODELOCAL(const in6_addr_emulation* a) 00297 { 00298 return IN6_IS_ADDR_MULTICAST(a) && ((a->s6_addr[1] & 0xf) == 1); 00299 } 00300 00301 inline int IN6_IS_ADDR_MC_LINKLOCAL(const in6_addr_emulation* a) 00302 { 00303 return IN6_IS_ADDR_MULTICAST(a) && ((a->s6_addr[1] & 0xf) == 2); 00304 } 00305 00306 inline int IN6_IS_ADDR_MC_SITELOCAL(const in6_addr_emulation* a) 00307 { 00308 return IN6_IS_ADDR_MULTICAST(a) && ((a->s6_addr[1] & 0xf) == 5); 00309 } 00310 00311 inline int IN6_IS_ADDR_MC_ORGLOCAL(const in6_addr_emulation* a) 00312 { 00313 return IN6_IS_ADDR_MULTICAST(a) && ((a->s6_addr[1] & 0xf) == 8); 00314 } 00315 00316 inline int IN6_IS_ADDR_MC_GLOBAL(const in6_addr_emulation* a) 00317 { 00318 return IN6_IS_ADDR_MULTICAST(a) && ((a->s6_addr[1] & 0xf) == 0xe); 00319 } 00320 00321 } // namespace detail 00322 } // namespace asio 00323 00324 #endif // defined(ASIO_HAS_OLD_WIN_SDK) 00325 00326 // Even newer Platform SDKs that support IPv6 may not define IPV6_V6ONLY. 00327 #if !defined(IPV6_V6ONLY) 00328 # define IPV6_V6ONLY 27 00329 #endif 00330 00331 // Some SDKs (e.g. Windows CE) don't define IPPROTO_ICMPV6. 00332 #if !defined(IPPROTO_ICMPV6) 00333 # define IPPROTO_ICMPV6 58 00334 #endif 00335 00336 #endif // defined(BOOST_WINDOWS) || defined(__CYGWIN__) 00337 00338 #include "asio/detail/pop_options.hpp" 00339 00340 #endif // ASIO_DETAIL_OLD_WIN_SDK_COMPAT_HPP