| OLD | NEW | 
|---|
| 1 /* | 1 /* | 
| 2  *  Copyright 2008 The WebRTC Project Authors. All rights reserved. | 2  *  Copyright 2008 The WebRTC Project Authors. All rights reserved. | 
| 3  * | 3  * | 
| 4  *  Use of this source code is governed by a BSD-style license | 4  *  Use of this source code is governed by a BSD-style license | 
| 5  *  that can be found in the LICENSE file in the root of the source | 5  *  that can be found in the LICENSE file in the root of the source | 
| 6  *  tree. An additional intellectual property rights grant can be found | 6  *  tree. An additional intellectual property rights grant can be found | 
| 7  *  in the file PATENTS.  All contributing project authors may | 7  *  in the file PATENTS.  All contributing project authors may | 
| 8  *  be found in the AUTHORS file in the root of the source tree. | 8  *  be found in the AUTHORS file in the root of the source tree. | 
| 9  */ | 9  */ | 
| 10 | 10 | 
| (...skipping 25 matching lines...) Expand all  Loading... | 
| 36                     std::vector<IPAddress>* addresses) { | 36                     std::vector<IPAddress>* addresses) { | 
| 37 #ifdef __native_client__ | 37 #ifdef __native_client__ | 
| 38   RTC_NOTREACHED(); | 38   RTC_NOTREACHED(); | 
| 39   LOG(LS_WARNING) << "ResolveHostname() is not implemented for NaCl"; | 39   LOG(LS_WARNING) << "ResolveHostname() is not implemented for NaCl"; | 
| 40   return -1; | 40   return -1; | 
| 41 #else  // __native_client__ | 41 #else  // __native_client__ | 
| 42   if (!addresses) { | 42   if (!addresses) { | 
| 43     return -1; | 43     return -1; | 
| 44   } | 44   } | 
| 45   addresses->clear(); | 45   addresses->clear(); | 
| 46   struct addrinfo* result = NULL; | 46   struct addrinfo* result = nullptr; | 
| 47   struct addrinfo hints = {0}; | 47   struct addrinfo hints = {0}; | 
| 48   hints.ai_family = family; | 48   hints.ai_family = family; | 
| 49   // |family| here will almost always be AF_UNSPEC, because |family| comes from | 49   // |family| here will almost always be AF_UNSPEC, because |family| comes from | 
| 50   // AsyncResolver::addr_.family(), which comes from a SocketAddress constructed | 50   // AsyncResolver::addr_.family(), which comes from a SocketAddress constructed | 
| 51   // with a hostname. When a SocketAddress is constructed with a hostname, its | 51   // with a hostname. When a SocketAddress is constructed with a hostname, its | 
| 52   // family is AF_UNSPEC. However, if someday in the future we construct | 52   // family is AF_UNSPEC. However, if someday in the future we construct | 
| 53   // a SocketAddress with both a hostname and a family other than AF_UNSPEC, | 53   // a SocketAddress with both a hostname and a family other than AF_UNSPEC, | 
| 54   // then it would be possible to get a specific family value here. | 54   // then it would be possible to get a specific family value here. | 
| 55 | 55 | 
| 56   // The behavior of AF_UNSPEC is roughly "get both ipv4 and ipv6", as | 56   // The behavior of AF_UNSPEC is roughly "get both ipv4 and ipv6", as | 
| 57   // documented by the various operating systems: | 57   // documented by the various operating systems: | 
| 58   // Linux: http://man7.org/linux/man-pages/man3/getaddrinfo.3.html | 58   // Linux: http://man7.org/linux/man-pages/man3/getaddrinfo.3.html | 
| 59   // Windows: https://msdn.microsoft.com/en-us/library/windows/desktop/ | 59   // Windows: https://msdn.microsoft.com/en-us/library/windows/desktop/ | 
| 60   // ms738520(v=vs.85).aspx | 60   // ms738520(v=vs.85).aspx | 
| 61   // Mac: https://developer.apple.com/legacy/library/documentation/Darwin/ | 61   // Mac: https://developer.apple.com/legacy/library/documentation/Darwin/ | 
| 62   // Reference/ManPages/man3/getaddrinfo.3.html | 62   // Reference/ManPages/man3/getaddrinfo.3.html | 
| 63   // Android (source code, not documentation): | 63   // Android (source code, not documentation): | 
| 64   // https://android.googlesource.com/platform/bionic/+/ | 64   // https://android.googlesource.com/platform/bionic/+/ | 
| 65   // 7e0bfb511e85834d7c6cb9631206b62f82701d60/libc/netbsd/net/getaddrinfo.c#1657 | 65   // 7e0bfb511e85834d7c6cb9631206b62f82701d60/libc/netbsd/net/getaddrinfo.c#1657 | 
| 66   hints.ai_flags = AI_ADDRCONFIG; | 66   hints.ai_flags = AI_ADDRCONFIG; | 
| 67   int ret = getaddrinfo(hostname.c_str(), NULL, &hints, &result); | 67   int ret = getaddrinfo(hostname.c_str(), nullptr, &hints, &result); | 
| 68   if (ret != 0) { | 68   if (ret != 0) { | 
| 69     return ret; | 69     return ret; | 
| 70   } | 70   } | 
| 71   struct addrinfo* cursor = result; | 71   struct addrinfo* cursor = result; | 
| 72   for (; cursor; cursor = cursor->ai_next) { | 72   for (; cursor; cursor = cursor->ai_next) { | 
| 73     if (family == AF_UNSPEC || cursor->ai_family == family) { | 73     if (family == AF_UNSPEC || cursor->ai_family == family) { | 
| 74       IPAddress ip; | 74       IPAddress ip; | 
| 75       if (IPFromAddrInfo(cursor, &ip)) { | 75       if (IPFromAddrInfo(cursor, &ip)) { | 
| 76         addresses->push_back(ip); | 76         addresses->push_back(ip); | 
| 77       } | 77       } | 
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 144 bool HasIPv6Enabled() { | 144 bool HasIPv6Enabled() { | 
| 145 #if defined(WEBRTC_WIN) | 145 #if defined(WEBRTC_WIN) | 
| 146   if (IsWindowsVistaOrLater()) { | 146   if (IsWindowsVistaOrLater()) { | 
| 147     return true; | 147     return true; | 
| 148   } | 148   } | 
| 149   if (!IsWindowsXpOrLater()) { | 149   if (!IsWindowsXpOrLater()) { | 
| 150     return false; | 150     return false; | 
| 151   } | 151   } | 
| 152   DWORD protbuff_size = 4096; | 152   DWORD protbuff_size = 4096; | 
| 153   std::unique_ptr<char[]> protocols; | 153   std::unique_ptr<char[]> protocols; | 
| 154   LPWSAPROTOCOL_INFOW protocol_infos = NULL; | 154   LPWSAPROTOCOL_INFOW protocol_infos = nullptr; | 
| 155   int requested_protocols[2] = {AF_INET6, 0}; | 155   int requested_protocols[2] = {AF_INET6, 0}; | 
| 156 | 156 | 
| 157   int err = 0; | 157   int err = 0; | 
| 158   int ret = 0; | 158   int ret = 0; | 
| 159   // Check for protocols in a do-while loop until we provide a buffer large | 159   // Check for protocols in a do-while loop until we provide a buffer large | 
| 160   // enough. (WSCEnumProtocols sets protbuff_size to its desired value). | 160   // enough. (WSCEnumProtocols sets protbuff_size to its desired value). | 
| 161   // It is extremely unlikely that this will loop more than once. | 161   // It is extremely unlikely that this will loop more than once. | 
| 162   do { | 162   do { | 
| 163     protocols.reset(new char[protbuff_size]); | 163     protocols.reset(new char[protbuff_size]); | 
| 164     protocol_infos = reinterpret_cast<LPWSAPROTOCOL_INFOW>(protocols.get()); | 164     protocol_infos = reinterpret_cast<LPWSAPROTOCOL_INFOW>(protocols.get()); | 
| (...skipping 25 matching lines...) Expand all  Loading... | 
| 190       break; | 190       break; | 
| 191     } | 191     } | 
| 192   } | 192   } | 
| 193   freeifaddrs(ifa); | 193   freeifaddrs(ifa); | 
| 194   return has_ipv6; | 194   return has_ipv6; | 
| 195 #else | 195 #else | 
| 196   return true; | 196   return true; | 
| 197 #endif | 197 #endif | 
| 198 } | 198 } | 
| 199 }  // namespace rtc | 199 }  // namespace rtc | 
| OLD | NEW | 
|---|