Index: net/base/net_util.cc |
diff --git a/net/base/net_util.cc b/net/base/net_util.cc |
index 3b49dffb5c20d889003a09755276ddaa8e41542d..c893e6164d0301196d9dcff4709bd977baa4a130 100644 |
--- a/net/base/net_util.cc |
+++ b/net/base/net_util.cc |
@@ -981,10 +981,9 @@ int GetPortFromSockaddr(const struct sockaddr* address, socklen_t address_len) { |
} |
bool IsLocalhost(const std::string& host) { |
- if (host == "localhost" || |
- host == "localhost.localdomain" || |
- host == "localhost6" || |
- host == "localhost6.localdomain6") |
+ if (host == "localhost" || host == "localhost.localdomain" || |
+ host == "localhost6" || host == "localhost6.localdomain6" || |
+ IsLocalhostTLD(host)) |
return true; |
IPAddressNumber ip_number; |
@@ -1014,6 +1013,24 @@ bool IsLocalhost(const std::string& host) { |
return false; |
} |
+bool IsLocalhostTLD(const std::string& host) { |
+ const char kLocalhostTLD[] = ".localhost"; |
+ const size_t kLocalhostTLDLength = arraysize(kLocalhostTLD) - 1; |
+ |
+ if (host.empty()) |
+ return false; |
+ |
+ size_t host_len = host.size(); |
+ if (*host.rbegin() == '.') |
Deprecated (see juliatuttle)
2015/03/26 17:04:36
Nit: host.back()? I think we're using C++11 now, s
Ryan Sleevi
2015/03/26 17:10:56
language, not library, so rbegin is needed
|
+ --host_len; |
+ if (host_len < kLocalhostTLDLength) |
+ return false; |
+ |
+ const char* host_suffix = host.data() + host_len - kLocalhostTLDLength; |
+ return base::strncasecmp(host_suffix, kLocalhostTLD, kLocalhostTLDLength) == |
+ 0; |
+} |
+ |
NetworkInterface::NetworkInterface() |
: type(NetworkChangeNotifier::CONNECTION_UNKNOWN), prefix_length(0) { |
} |