| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/base/host_resolver_proc.h" | 5 #include "net/base/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 "net/base/address_list.h" | 10 #include "net/base/address_list.h" |
| 11 #include "net/base/dns_reload_timer.h" | 11 #include "net/base/dns_reloader.h" |
| 12 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
| 13 #include "net/base/sys_addrinfo.h" | 13 #include "net/base/sys_addrinfo.h" |
| 14 | 14 |
| 15 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 15 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 16 #include <resolv.h> | 16 #include <resolv.h> |
| 17 #endif | 17 #endif |
| 18 | 18 |
| 19 namespace net { | 19 namespace net { |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 // loopback addresses. | 176 // loopback addresses. |
| 177 if (host_resolver_flags & HOST_RESOLVER_LOOPBACK_ONLY) | 177 if (host_resolver_flags & HOST_RESOLVER_LOOPBACK_ONLY) |
| 178 hints.ai_flags &= ~AI_ADDRCONFIG; | 178 hints.ai_flags &= ~AI_ADDRCONFIG; |
| 179 | 179 |
| 180 if (host_resolver_flags & HOST_RESOLVER_CANONNAME) | 180 if (host_resolver_flags & HOST_RESOLVER_CANONNAME) |
| 181 hints.ai_flags |= AI_CANONNAME; | 181 hints.ai_flags |= AI_CANONNAME; |
| 182 | 182 |
| 183 // Restrict result set to only this socket type to avoid duplicates. | 183 // Restrict result set to only this socket type to avoid duplicates. |
| 184 hints.ai_socktype = SOCK_STREAM; | 184 hints.ai_socktype = SOCK_STREAM; |
| 185 | 185 |
| 186 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) && \ |
| 187 !defined(OS_ANDROID) |
| 188 DnsReloaderMaybeReload(); |
| 189 #endif |
| 186 int err = getaddrinfo(host.c_str(), NULL, &hints, &ai); | 190 int err = getaddrinfo(host.c_str(), NULL, &hints, &ai); |
| 187 bool should_retry = false; | 191 bool should_retry = false; |
| 188 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) && \ | |
| 189 !defined(OS_ANDROID) | |
| 190 // If we fail, re-initialise the resolver just in case there have been any | |
| 191 // changes to /etc/resolv.conf and retry. See http://crbug.com/11380 for info. | |
| 192 if (err && DnsReloadTimerHasExpired()) { | |
| 193 // When there's no network connection, _res may not be initialized by | |
| 194 // getaddrinfo. Therefore, we call res_nclose only when there are ns | |
| 195 // entries. | |
| 196 if (_res.nscount > 0) | |
| 197 res_nclose(&_res); | |
| 198 if (!res_ninit(&_res)) | |
| 199 should_retry = true; | |
| 200 } | |
| 201 #endif | |
| 202 // If the lookup was restricted (either by address family, or address | 192 // If the lookup was restricted (either by address family, or address |
| 203 // detection), and the results where all localhost of a single family, | 193 // detection), and the results where all localhost of a single family, |
| 204 // maybe we should retry. There were several bugs related to these | 194 // maybe we should retry. There were several bugs related to these |
| 205 // issues, for example http://crbug.com/42058 and http://crbug.com/49024 | 195 // issues, for example http://crbug.com/42058 and http://crbug.com/49024 |
| 206 if ((hints.ai_family != AF_UNSPEC || hints.ai_flags & AI_ADDRCONFIG) && | 196 if ((hints.ai_family != AF_UNSPEC || hints.ai_flags & AI_ADDRCONFIG) && |
| 207 err == 0 && IsAllLocalhostOfOneFamily(ai)) { | 197 err == 0 && IsAllLocalhostOfOneFamily(ai)) { |
| 208 if (host_resolver_flags & HOST_RESOLVER_DEFAULT_FAMILY_SET_DUE_TO_NO_IPV6) { | 198 if (host_resolver_flags & HOST_RESOLVER_DEFAULT_FAMILY_SET_DUE_TO_NO_IPV6) { |
| 209 hints.ai_family = AF_UNSPEC; | 199 hints.ai_family = AF_UNSPEC; |
| 210 should_retry = true; | 200 should_retry = true; |
| 211 } | 201 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 242 #endif | 232 #endif |
| 243 | 233 |
| 244 return ERR_NAME_NOT_RESOLVED; | 234 return ERR_NAME_NOT_RESOLVED; |
| 245 } | 235 } |
| 246 | 236 |
| 247 *addrlist = AddressList::CreateByAdoptingFromSystem(ai); | 237 *addrlist = AddressList::CreateByAdoptingFromSystem(ai); |
| 248 return OK; | 238 return OK; |
| 249 } | 239 } |
| 250 | 240 |
| 251 } // namespace net | 241 } // namespace net |
| OLD | NEW |