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

Side by Side Diff: net/base/host_resolver_proc.cc

Issue 302010: Add a mechanism to disable IPv6.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Address darin's comments Created 11 years, 2 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 | Annotate | Revision Log
OLDNEW
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 default_proc_ = proc; 45 default_proc_ = proc;
46 return old; 46 return old;
47 } 47 }
48 48
49 // static 49 // static
50 HostResolverProc* HostResolverProc::GetDefault() { 50 HostResolverProc* HostResolverProc::GetDefault() {
51 return default_proc_; 51 return default_proc_;
52 } 52 }
53 53
54 int HostResolverProc::ResolveUsingPrevious(const std::string& host, 54 int HostResolverProc::ResolveUsingPrevious(const std::string& host,
55 AddressFamily address_family,
55 AddressList* addrlist) { 56 AddressList* addrlist) {
56 if (previous_proc_) 57 if (previous_proc_)
57 return previous_proc_->Resolve(host, addrlist); 58 return previous_proc_->Resolve(host, address_family, addrlist);
58 59
59 // Final fallback is the system resolver. 60 // Final fallback is the system resolver.
60 return SystemHostResolverProc(host, addrlist); 61 return SystemHostResolverProc(host, address_family, addrlist);
61 } 62 }
62 63
63 #if defined(OS_LINUX) 64 #if defined(OS_LINUX)
64 // On Linux changes to /etc/resolv.conf can go unnoticed thus resulting in 65 // On Linux changes to /etc/resolv.conf can go unnoticed thus resulting in
65 // DNS queries failing either because nameservers are unknown on startup 66 // DNS queries failing either because nameservers are unknown on startup
66 // or because nameserver info has changed as a result of e.g. connecting to 67 // or because nameserver info has changed as a result of e.g. connecting to
67 // a new network. Some distributions patch glibc to stat /etc/resolv.conf 68 // a new network. Some distributions patch glibc to stat /etc/resolv.conf
68 // to try to automatically detect such changes but these patches are not 69 // to try to automatically detect such changes but these patches are not
69 // universal and even patched systems such as Jaunty appear to need calls 70 // universal and even patched systems such as Jaunty appear to need calls
70 // to res_ninit to reload the nameserver information in different threads. 71 // to res_ninit to reload the nameserver information in different threads.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 118
118 DISALLOW_COPY_AND_ASSIGN(DnsReloadTimer); 119 DISALLOW_COPY_AND_ASSIGN(DnsReloadTimer);
119 }; 120 };
120 121
121 // A TLS slot to the TimeTicks for the current thread. 122 // A TLS slot to the TimeTicks for the current thread.
122 // static 123 // static
123 ThreadLocalStorage::Slot DnsReloadTimer::tls_index_(base::LINKER_INITIALIZED); 124 ThreadLocalStorage::Slot DnsReloadTimer::tls_index_(base::LINKER_INITIALIZED);
124 125
125 #endif // defined(OS_LINUX) 126 #endif // defined(OS_LINUX)
126 127
127 int SystemHostResolverProc(const std::string& host, AddressList* addrlist) { 128 int SystemHostResolverProc(const std::string& host,
129 AddressFamily address_family,
130 AddressList* addrlist) {
128 // The result of |getaddrinfo| for empty hosts is inconsistent across systems. 131 // The result of |getaddrinfo| for empty hosts is inconsistent across systems.
129 // On Windows it gives the default interface's address, whereas on Linux it 132 // On Windows it gives the default interface's address, whereas on Linux it
130 // gives an error. We will make it fail on all platforms for consistency. 133 // gives an error. We will make it fail on all platforms for consistency.
131 if (host.empty()) 134 if (host.empty())
132 return ERR_NAME_NOT_RESOLVED; 135 return ERR_NAME_NOT_RESOLVED;
133 136
134 struct addrinfo* ai = NULL; 137 struct addrinfo* ai = NULL;
135 struct addrinfo hints = {0}; 138 struct addrinfo hints = {0};
136 hints.ai_family = AF_UNSPEC; 139
140 switch (address_family) {
141 case ADDRESS_FAMILY_IPV4_ONLY:
142 hints.ai_family = AF_INET;
143 break;
144 default:
145 hints.ai_family = AF_UNSPEC;
146 }
137 147
138 #if defined(OS_WIN) 148 #if defined(OS_WIN)
139 // DO NOT USE AI_ADDRCONFIG ON WINDOWS. 149 // DO NOT USE AI_ADDRCONFIG ON WINDOWS.
140 // 150 //
141 // The following comment in <winsock2.h> is the best documentation I found 151 // The following comment in <winsock2.h> is the best documentation I found
142 // on AI_ADDRCONFIG for Windows: 152 // on AI_ADDRCONFIG for Windows:
143 // Flags used in "hints" argument to getaddrinfo() 153 // Flags used in "hints" argument to getaddrinfo()
144 // - AI_ADDRCONFIG is supported starting with Vista 154 // - AI_ADDRCONFIG is supported starting with Vista
145 // - default is AI_ADDRCONFIG ON whether the flag is set or not 155 // - default is AI_ADDRCONFIG ON whether the flag is set or not
146 // because the performance penalty in not having ADDRCONFIG in 156 // because the performance penalty in not having ADDRCONFIG in
(...skipping 30 matching lines...) Expand all
177 #endif 187 #endif
178 188
179 if (err) 189 if (err)
180 return ERR_NAME_NOT_RESOLVED; 190 return ERR_NAME_NOT_RESOLVED;
181 191
182 addrlist->Adopt(ai); 192 addrlist->Adopt(ai);
183 return OK; 193 return OK;
184 } 194 }
185 195
186 } // namespace net 196 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698