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

Unified Diff: net/base/net_util.cc

Issue 430193002: Wire 'blink::Platform::isHostnameReservedIPAddress()' to 'net::IsReservedIPAddress()'. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Layering. Created 6 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
Index: net/base/net_util.cc
diff --git a/net/base/net_util.cc b/net/base/net_util.cc
index 941dca9ab53ba1a4cb3214712a4ae7e16cf7ee62..7edd8ad2333a7a91af4248e045e98dc096fd2819 100644
--- a/net/base/net_util.cc
+++ b/net/base/net_util.cc
@@ -799,6 +799,27 @@ int ConvertAddressFamily(AddressFamily address_family) {
return AF_UNSPEC;
}
+bool ParseURLHostnameToNumber(const std::string& hostname,
+ IPAddressNumber* ip_number) {
+ // |hostname| must be a canonicalized hostname with brackets and everything.
Ryan Sleevi 2014/08/06 19:42:12 "with brackets and everything" is a bit too colloq
Mike West 2014/08/08 08:15:03 Done.
+ // Otherwise, explosions.
+ url::Component host_comp(0, hostname.size());
+
+ // If it has a bracket, try parsing it as an IPv6 address.
+ if (hostname[0] == '[') {
+ ip_number->resize(16); // 128 bits.
+ return url::IPv6AddressToNumber(
+ hostname.data(), host_comp, &(*ip_number)[0]);
+ }
+
+ // Otherwise, try IPv4.
+ ip_number->resize(4); // 32 bits.
+ int num_components;
+ url::CanonHostInfo::Family family = url::IPv4AddressToNumber(
+ hostname.data(), host_comp, &(*ip_number)[0], &num_components);
+ return family == url::CanonHostInfo::IPV4;
+}
+
bool ParseIPLiteralToNumber(const std::string& ip_literal,
IPAddressNumber* ip_number) {
// |ip_literal| could be either a IPv4 or an IPv6 literal. If it contains
« net/base/net_util.h ('K') | « net/base/net_util.h ('k') | net/base/net_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698