Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: webrtc/base/nethelpers.cc

Issue 2083013008: Return both IPv6 and IPv4 address from the lookup. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: . Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 26 matching lines...) Expand all
37 ASSERT(false); 37 ASSERT(false);
38 LOG(LS_WARNING) << "ResolveHostname() is not implemented for NaCl"; 38 LOG(LS_WARNING) << "ResolveHostname() is not implemented for NaCl";
39 return -1; 39 return -1;
40 #else // __native_client__ 40 #else // __native_client__
41 if (!addresses) { 41 if (!addresses) {
42 return -1; 42 return -1;
43 } 43 }
44 addresses->clear(); 44 addresses->clear();
45 struct addrinfo* result = NULL; 45 struct addrinfo* result = NULL;
46 struct addrinfo hints = {0}; 46 struct addrinfo hints = {0};
47 // TODO(djw): For now this is IPv4 only so existing users remain unaffected. 47 hints.ai_family = family;
48 hints.ai_family = AF_INET; 48 // |family| here will almost always be AF_UNSPEC, because |family| comes from
49 // AsyncResolver::addr_.family(), which comes from a SocketAddress constructed
50 // with a hostname. When a SocketAddress is constructed with a hostname, its
51 // family is AF_UNSPEC. However, if someday in the future we construct
52 // a SocketAddress with both a hostname and a family other than AF_UNSPEC,
53 // then it would be possible to get a specific family value here.
54
55 // The behavior of AF_UNSPEC is roughly "get both ipv4 and ipv6", as
56 // documented by the various operating systems:
57 // Linux: http://man7.org/linux/man-pages/man3/getaddrinfo.3.html
58 // Windows: https://msdn.microsoft.com/en-us/library/windows/desktop/
59 // ms738520(v=vs.85).aspx
60 // Mac: https://developer.apple.com/legacy/library/documentation/Darwin/
61 // Reference/ManPages/man3/getaddrinfo.3.html
62 // Android (source code, not documentation):
63 // https://android.googlesource.com/platform/bionic/+/
64 // 7e0bfb511e85834d7c6cb9631206b62f82701d60/libc/netbsd/net/getaddrinfo.c#1657
49 hints.ai_flags = AI_ADDRCONFIG; 65 hints.ai_flags = AI_ADDRCONFIG;
50 int ret = getaddrinfo(hostname.c_str(), NULL, &hints, &result); 66 int ret = getaddrinfo(hostname.c_str(), NULL, &hints, &result);
51 if (ret != 0) { 67 if (ret != 0) {
52 return ret; 68 return ret;
53 } 69 }
54 struct addrinfo* cursor = result; 70 struct addrinfo* cursor = result;
55 for (; cursor; cursor = cursor->ai_next) { 71 for (; cursor; cursor = cursor->ai_next) {
56 if (family == AF_UNSPEC || cursor->ai_family == family) { 72 if (family == AF_UNSPEC || cursor->ai_family == family) {
57 IPAddress ip; 73 IPAddress ip;
58 if (IPFromAddrInfo(cursor, &ip)) { 74 if (IPFromAddrInfo(cursor, &ip)) {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 break; 189 break;
174 } 190 }
175 } 191 }
176 freeifaddrs(ifa); 192 freeifaddrs(ifa);
177 return has_ipv6; 193 return has_ipv6;
178 #else 194 #else
179 return true; 195 return true;
180 #endif 196 #endif
181 } 197 }
182 } // namespace rtc 198 } // namespace rtc
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698