OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/socket/socket_descriptor.h" | 5 #include "net/socket/socket_descriptor.h" |
6 | 6 |
7 #if defined(OS_POSIX) | 7 #if defined(OS_POSIX) |
8 #include <sys/types.h> | 8 #include <sys/types.h> |
9 #include <sys/socket.h> | 9 #include <sys/socket.h> |
10 #endif | 10 #endif |
11 | 11 |
12 #if defined(OS_WIN) | 12 #if defined(OS_WIN) |
13 #include <ws2tcpip.h> | 13 #include <ws2tcpip.h> |
14 #include "base/win/windows_version.h" | |
15 #include "net/base/winsock_init.h" | 14 #include "net/base/winsock_init.h" |
16 #endif | 15 #endif |
17 | 16 |
18 namespace net { | 17 namespace net { |
19 | 18 |
20 SocketDescriptor CreatePlatformSocket(int family, int type, int protocol) { | 19 SocketDescriptor CreatePlatformSocket(int family, int type, int protocol) { |
21 #if defined(OS_WIN) | 20 #if defined(OS_WIN) |
22 EnsureWinsockInit(); | 21 EnsureWinsockInit(); |
23 SocketDescriptor result = ::WSASocket(family, type, protocol, nullptr, 0, | 22 SocketDescriptor result = ::WSASocket(family, type, protocol, nullptr, 0, |
24 WSA_FLAG_OVERLAPPED); | 23 WSA_FLAG_OVERLAPPED); |
25 if (result != kInvalidSocket && family == AF_INET6 && | 24 if (result != kInvalidSocket && family == AF_INET6) { |
26 base::win::OSInfo::GetInstance()->version() >= base::win::VERSION_VISTA) { | |
27 DWORD value = 0; | 25 DWORD value = 0; |
28 if (setsockopt(result, IPPROTO_IPV6, IPV6_V6ONLY, | 26 if (setsockopt(result, IPPROTO_IPV6, IPV6_V6ONLY, |
29 reinterpret_cast<const char*>(&value), sizeof(value))) { | 27 reinterpret_cast<const char*>(&value), sizeof(value))) { |
30 closesocket(result); | 28 closesocket(result); |
31 return kInvalidSocket; | 29 return kInvalidSocket; |
32 } | 30 } |
33 } | 31 } |
34 return result; | 32 return result; |
35 #else // OS_WIN | 33 #else // OS_WIN |
36 return ::socket(family, type, protocol); | 34 return ::socket(family, type, protocol); |
37 #endif // OS_WIN | 35 #endif // OS_WIN |
38 | 36 |
39 } | 37 } |
40 | 38 |
41 } // namespace net | 39 } // namespace net |
OLD | NEW |