Index: url/gurl.cc |
diff --git a/url/gurl.cc b/url/gurl.cc |
index 46ca408da9c9c55f1e919365dab03db5038aedff..a826a779a15def7728a6bf3eb3ebbf3020047d00 100644 |
--- a/url/gurl.cc |
+++ b/url/gurl.cc |
@@ -458,6 +458,29 @@ bool GURL::HostIsIPAddress() const { |
return host_info.IsIPAddress(); |
} |
+bool GURL::HostIsLocal() const { |
+ if (!is_valid_ || spec_.empty()) |
+ return false; |
+ |
+ if (HostNoBrackets() == "localhost") |
+ return true; |
+ |
+ url::RawCanonOutputT<char, 128> ignored; |
+ url::CanonHostInfo host_info; |
+ url::CanonicalizeIPAddress(spec_.c_str(), parsed_.host, &ignored, &host_info); |
+ |
+ static const unsigned char v4_localhost = 0x7F; |
+ if (host_info.family == url::CanonHostInfo::IPV4) |
+ return host_info.address[0] == v4_localhost; |
+ |
+ static const unsigned char v6_localhost[] = |
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }; |
+ if (host_info.family == url::CanonHostInfo::IPV6) |
+ return memcmp(host_info.address, v6_localhost, sizeof(v6_localhost)) == 0; |
+ |
+ return false; |
+} |
+ |
#ifdef WIN32 |
const GURL& GURL::EmptyGURL() { |