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

Unified Diff: net/base/mock_host_resolver.cc

Issue 3023048: Don't resolve IP literals. (Closed)
Patch Set: Rebase again Created 10 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/base/host_resolver_impl_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/mock_host_resolver.cc
diff --git a/net/base/mock_host_resolver.cc b/net/base/mock_host_resolver.cc
index 8d1fd89b1002e1aac5413f7fa8e687deb46020f5..a9fc75425e7c2f6d28e392155377185f43221975 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,
« no previous file with comments | « net/base/host_resolver_impl_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698