OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
10 #include <ws2tcpip.h> | 10 #include <ws2tcpip.h> |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 // enable ADDRCONFIG behavior | 150 // enable ADDRCONFIG behavior |
151 // | 151 // |
152 // Not only is AI_ADDRCONFIG unnecessary, but it can be harmful. If the | 152 // Not only is AI_ADDRCONFIG unnecessary, but it can be harmful. If the |
153 // computer is not connected to a network, AI_ADDRCONFIG causes getaddrinfo | 153 // computer is not connected to a network, AI_ADDRCONFIG causes getaddrinfo |
154 // to fail with WSANO_DATA (11004) for "localhost", probably because of the | 154 // to fail with WSANO_DATA (11004) for "localhost", probably because of the |
155 // following note on AI_ADDRCONFIG in the MSDN getaddrinfo page: | 155 // following note on AI_ADDRCONFIG in the MSDN getaddrinfo page: |
156 // The IPv4 or IPv6 loopback address is not considered a valid global | 156 // The IPv4 or IPv6 loopback address is not considered a valid global |
157 // address. | 157 // address. |
158 // See http://crbug.com/5234. | 158 // See http://crbug.com/5234. |
159 hints.ai_flags = 0; | 159 hints.ai_flags = 0; |
160 #elif defined(OS_MACOSX) | |
161 // We don't need to use AI_ADDRCONFIG on Mac OS X. There are two evidences: | |
162 // | |
163 // 1. The getaddrinfo man page on Mac OS X documents only three flags: | |
164 // AI_CANONNAME, AI_NUMERICHOST, and AI_PASSIVE, and shows an example that | |
165 // sets hints.ai_flags to 0. | |
166 // 2. The <netdb.h> header lists only those three flags in the comment after | |
167 // the ai_flags field of struct addrinfo, and defines an AI_MASK macro as | |
168 // the bitwise-OR of those three flags with the comment "valid flags for | |
169 // addrinfo". | |
170 // | |
171 // But is it harmful to use AI_ADDRCONFIG? Unfortunately I can't find a | |
172 // definitive answer by browsing the getaddrinfo source code in Darwin (in | |
173 // the Libinfo project). | |
174 // | |
175 // See http://crbug.com/12711. | |
176 hints.ai_flags = 0; | |
177 #else | 160 #else |
178 hints.ai_flags = AI_ADDRCONFIG; | 161 hints.ai_flags = AI_ADDRCONFIG; |
179 #endif | 162 #endif |
180 | 163 |
181 // Restrict result set to only this socket type to avoid duplicates. | 164 // Restrict result set to only this socket type to avoid duplicates. |
182 hints.ai_socktype = SOCK_STREAM; | 165 hints.ai_socktype = SOCK_STREAM; |
183 | 166 |
184 int err = getaddrinfo(host.c_str(), NULL, &hints, &ai); | 167 int err = getaddrinfo(host.c_str(), NULL, &hints, &ai); |
185 #if defined(OS_LINUX) | 168 #if defined(OS_LINUX) |
186 net::DnsReloadTimer* dns_timer = Singleton<net::DnsReloadTimer>::get(); | 169 net::DnsReloadTimer* dns_timer = Singleton<net::DnsReloadTimer>::get(); |
187 // If we fail, re-initialise the resolver just in case there have been any | 170 // If we fail, re-initialise the resolver just in case there have been any |
188 // changes to /etc/resolv.conf and retry. See http://crbug.com/11380 for info. | 171 // changes to /etc/resolv.conf and retry. See http://crbug.com/11380 for info. |
189 if (err && dns_timer->Expired()) { | 172 if (err && dns_timer->Expired()) { |
190 res_nclose(&_res); | 173 res_nclose(&_res); |
191 if (!res_ninit(&_res)) | 174 if (!res_ninit(&_res)) |
192 err = getaddrinfo(host.c_str(), NULL, &hints, &ai); | 175 err = getaddrinfo(host.c_str(), NULL, &hints, &ai); |
193 } | 176 } |
194 #endif | 177 #endif |
195 | 178 |
196 if (err) | 179 if (err) |
197 return ERR_NAME_NOT_RESOLVED; | 180 return ERR_NAME_NOT_RESOLVED; |
198 | 181 |
199 addrlist->Adopt(ai); | 182 addrlist->Adopt(ai); |
200 return OK; | 183 return OK; |
201 } | 184 } |
202 | 185 |
203 } // namespace net | 186 } // namespace net |
OLD | NEW |