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

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: Comments. 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
« no previous file with comments | « net/base/net_util.h ('k') | net/base/net_util_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/net_util.cc
diff --git a/net/base/net_util.cc b/net/base/net_util.cc
index 941dca9ab53ba1a4cb3214712a4ae7e16cf7ee62..1b65c6b10e4bbf0edf2082ef14970e4747a603f4 100644
--- a/net/base/net_util.cc
+++ b/net/base/net_util.cc
@@ -799,6 +799,28 @@ int ConvertAddressFamily(AddressFamily address_family) {
return AF_UNSPEC;
}
+bool ParseURLHostnameToNumber(const std::string& hostname,
+ IPAddressNumber* ip_number) {
+ // |hostname| is an already canoncalized hostname, conforming to RFC 3986.
+ // For an IP address, this is defined in Section 3.2.2 of RFC 3986, with
+ // the canonical form for IPv6 addresses defined in Section 4 of RFC 5952.
+ 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
« no previous file with comments | « 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