diff options
author | vandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-18 23:26:51 +0000 |
---|---|---|
committer | vandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-18 23:26:51 +0000 |
commit | de114d6a8a223904bc5988c36c22518dd59e1b3a (patch) | |
tree | c5f21c96501172b8dd9dc3a7871ae89fa16cacdc /net/base/mock_host_resolver.cc | |
parent | 4067f4a5f0c7ace27a9631cfbf261e42e1ecc8e6 (diff) | |
download | chromium_src-de114d6a8a223904bc5988c36c22518dd59e1b3a.zip chromium_src-de114d6a8a223904bc5988c36c22518dd59e1b3a.tar.gz chromium_src-de114d6a8a223904bc5988c36c22518dd59e1b3a.tar.bz2 |
Don't resolve IP literals.
For each resolution request this checks to see if this 'host' is a literal ip address. If so, it synthesises a struct addrinfo and returns it without adding it to the cache.
BUG=39830
TEST=unit tests, new and old
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=56384
Review URL: http://codereview.chromium.org/3023048
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@56615 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/mock_host_resolver.cc')
-rw-r--r-- | net/base/mock_host_resolver.cc | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/net/base/mock_host_resolver.cc b/net/base/mock_host_resolver.cc index 8d1fd89..a9fc754 100644 --- a/net/base/mock_host_resolver.cc +++ b/net/base/mock_host_resolver.cc @@ -9,11 +9,20 @@ #include "base/ref_counted.h" #include "net/base/net_errors.h" #include "net/base/net_util.h" +#include "net/base/sys_addrinfo.h" namespace net { namespace { +char* do_strdup(const char* src) { +#if defined(OS_WIN) + return _strdup(src); +#else + return strdup(src); +#endif +} + // Fills |*addrlist| with a socket address for |host| which should be an // IPv4 or IPv6 literal without enclosing brackets. If |canonical_name| is // non-empty it is used as the DNS canonical name for the host. Returns OK on @@ -27,15 +36,10 @@ int CreateIPAddress(const std::string& host, return ERR_UNEXPECTED; } - if (ip_number.size() == 4) { - *addrlist = AddressList::CreateIPv4Address(&ip_number[0], canonical_name); - } else if (ip_number.size() == 16) { - *addrlist = AddressList::CreateIPv6Address(&ip_number[0], canonical_name); - } else { - NOTREACHED(); - return ERR_UNEXPECTED; - } - + AddressList result(ip_number, -1, false); + struct addrinfo* ai = const_cast<struct addrinfo*>(result.head()); + ai->ai_canonname = do_strdup(canonical_name.c_str()); + *addrlist = result; return OK; } @@ -161,6 +165,10 @@ void RuleBasedHostResolverProc::AddIPLiteralRule( const std::string& host_pattern, const std::string& ip_literal, const std::string& canonical_name) { + // Literals are always resolved to themselves by HostResolverImpl, + // consequently we do not support remapping them. + IPAddressNumber ip_number; + DCHECK(!ParseIPLiteralToNumber(host_pattern, &ip_number)); Rule rule(Rule::kResolverTypeIPLiteral, host_pattern, ADDRESS_FAMILY_UNSPECIFIED, |