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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
189 // loopback addresses. | 189 // loopback addresses. |
190 if (host_resolver_flags & HOST_RESOLVER_LOOPBACK_ONLY) | 190 if (host_resolver_flags & HOST_RESOLVER_LOOPBACK_ONLY) |
191 hints.ai_flags &= ~AI_ADDRCONFIG; | 191 hints.ai_flags &= ~AI_ADDRCONFIG; |
192 | 192 |
193 if (host_resolver_flags & HOST_RESOLVER_CANONNAME) | 193 if (host_resolver_flags & HOST_RESOLVER_CANONNAME) |
194 hints.ai_flags |= AI_CANONNAME; | 194 hints.ai_flags |= AI_CANONNAME; |
195 | 195 |
196 // Restrict result set to only this socket type to avoid duplicates. | 196 // Restrict result set to only this socket type to avoid duplicates. |
197 hints.ai_socktype = SOCK_STREAM; | 197 hints.ai_socktype = SOCK_STREAM; |
198 | 198 |
199 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) && \ | |
eroman
2011/07/25 20:13:03
nit: I wander if it would be cleaner to internaliz
Craig
2011/08/03 19:30:58
I'll do this but I'm going to chase the symlink st
| |
200 !defined(OS_ANDROID) | |
201 DnsReloaderMaybeReload(); | |
202 #endif | |
199 int err = getaddrinfo(host.c_str(), NULL, &hints, &ai); | 203 int err = getaddrinfo(host.c_str(), NULL, &hints, &ai); |
200 bool should_retry = false; | 204 bool should_retry = false; |
201 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) && \ | |
202 !defined(OS_ANDROID) | |
203 // If we fail, re-initialise the resolver just in case there have been any | |
204 // changes to /etc/resolv.conf and retry. See http://crbug.com/11380 for info. | |
205 if (err && DnsReloadTimerHasExpired()) { | |
206 // When there's no network connection, _res may not be initialized by | |
207 // getaddrinfo. Therefore, we call res_nclose only when there are ns | |
208 // entries. | |
209 if (_res.nscount > 0) | |
210 res_nclose(&_res); | |
211 if (!res_ninit(&_res)) | |
212 should_retry = true; | |
213 } | |
214 #endif | |
215 // If the lookup was restricted (either by address family, or address | 205 // If the lookup was restricted (either by address family, or address |
216 // detection), and the results where all localhost of a single family, | 206 // detection), and the results where all localhost of a single family, |
217 // maybe we should retry. There were several bugs related to these | 207 // maybe we should retry. There were several bugs related to these |
218 // issues, for example http://crbug.com/42058 and http://crbug.com/49024 | 208 // issues, for example http://crbug.com/42058 and http://crbug.com/49024 |
219 if ((hints.ai_family != AF_UNSPEC || hints.ai_flags & AI_ADDRCONFIG) && | 209 if ((hints.ai_family != AF_UNSPEC || hints.ai_flags & AI_ADDRCONFIG) && |
220 err == 0 && IsAllLocalhostOfOneFamily(ai)) { | 210 err == 0 && IsAllLocalhostOfOneFamily(ai)) { |
221 if (host_resolver_flags & HOST_RESOLVER_DEFAULT_FAMILY_SET_DUE_TO_NO_IPV6) { | 211 if (host_resolver_flags & HOST_RESOLVER_DEFAULT_FAMILY_SET_DUE_TO_NO_IPV6) { |
222 hints.ai_family = AF_UNSPEC; | 212 hints.ai_family = AF_UNSPEC; |
223 should_retry = true; | 213 should_retry = true; |
224 } | 214 } |
(...skipping 30 matching lines...) Expand all Loading... | |
255 #endif | 245 #endif |
256 | 246 |
257 return ERR_NAME_NOT_RESOLVED; | 247 return ERR_NAME_NOT_RESOLVED; |
258 } | 248 } |
259 | 249 |
260 *addrlist = AddressList::CreateByAdoptingFromSystem(ai); | 250 *addrlist = AddressList::CreateByAdoptingFromSystem(ai); |
261 return OK; | 251 return OK; |
262 } | 252 } |
263 | 253 |
264 } // namespace net | 254 } // namespace net |
OLD | NEW |