| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/dns/host_resolver_proc.h" | 5 #include "net/dns/host_resolver_proc.h" |
| 6 | 6 |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/sys_byteorder.h" | 10 #include "base/sys_byteorder.h" |
| 11 #include "net/base/address_list.h" | 11 #include "net/base/address_list.h" |
| 12 #include "net/base/dns_reloader.h" | 12 #include "net/base/dns_reloader.h" |
| 13 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
| 14 #include "net/base/net_util.h" |
| 14 #include "net/base/sys_addrinfo.h" | 15 #include "net/base/sys_addrinfo.h" |
| 15 | 16 |
| 16 #if defined(OS_OPENBSD) | 17 #if defined(OS_OPENBSD) |
| 17 #define AI_ADDRCONFIG 0 | 18 #define AI_ADDRCONFIG 0 |
| 18 #endif | 19 #endif |
| 19 | 20 |
| 20 namespace net { | 21 namespace net { |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 if (host_resolver_flags & HOST_RESOLVER_CANONNAME) | 183 if (host_resolver_flags & HOST_RESOLVER_CANONNAME) |
| 183 hints.ai_flags |= AI_CANONNAME; | 184 hints.ai_flags |= AI_CANONNAME; |
| 184 | 185 |
| 185 // Restrict result set to only this socket type to avoid duplicates. | 186 // Restrict result set to only this socket type to avoid duplicates. |
| 186 hints.ai_socktype = SOCK_STREAM; | 187 hints.ai_socktype = SOCK_STREAM; |
| 187 | 188 |
| 188 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) && \ | 189 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) && \ |
| 189 !defined(OS_ANDROID) | 190 !defined(OS_ANDROID) |
| 190 DnsReloaderMaybeReload(); | 191 DnsReloaderMaybeReload(); |
| 191 #endif | 192 #endif |
| 192 int err = getaddrinfo(host.c_str(), NULL, &hints, &ai); | 193 |
| 194 // Redirect .localhost queries to localhost to make sure that they are |
| 195 // never sent out on the network, per RFC 6761. |
| 196 int err = getaddrinfo(IsLocalhostTLD(host) ? "localhost" : host.c_str(), NULL, |
| 197 &hints, &ai); |
| 193 bool should_retry = false; | 198 bool should_retry = false; |
| 194 // If the lookup was restricted (either by address family, or address | 199 // If the lookup was restricted (either by address family, or address |
| 195 // detection), and the results where all localhost of a single family, | 200 // detection), and the results where all localhost of a single family, |
| 196 // maybe we should retry. There were several bugs related to these | 201 // maybe we should retry. There were several bugs related to these |
| 197 // issues, for example http://crbug.com/42058 and http://crbug.com/49024 | 202 // issues, for example http://crbug.com/42058 and http://crbug.com/49024 |
| 198 if ((hints.ai_family != AF_UNSPEC || hints.ai_flags & AI_ADDRCONFIG) && | 203 if ((hints.ai_family != AF_UNSPEC || hints.ai_flags & AI_ADDRCONFIG) && |
| 199 err == 0 && IsAllLocalhostOfOneFamily(ai)) { | 204 err == 0 && IsAllLocalhostOfOneFamily(ai)) { |
| 200 if (host_resolver_flags & HOST_RESOLVER_DEFAULT_FAMILY_SET_DUE_TO_NO_IPV6) { | 205 if (host_resolver_flags & HOST_RESOLVER_DEFAULT_FAMILY_SET_DUE_TO_NO_IPV6) { |
| 201 hints.ai_family = AF_UNSPEC; | 206 hints.ai_family = AF_UNSPEC; |
| 202 should_retry = true; | 207 should_retry = true; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 return SystemHostResolverCall(hostname, | 263 return SystemHostResolverCall(hostname, |
| 259 address_family, | 264 address_family, |
| 260 host_resolver_flags, | 265 host_resolver_flags, |
| 261 addr_list, | 266 addr_list, |
| 262 os_error); | 267 os_error); |
| 263 } | 268 } |
| 264 | 269 |
| 265 SystemHostResolverProc::~SystemHostResolverProc() {} | 270 SystemHostResolverProc::~SystemHostResolverProc() {} |
| 266 | 271 |
| 267 } // namespace net | 272 } // namespace net |
| OLD | NEW |