Chromium Code Reviews| Index: net/base/net_util.cc |
| diff --git a/net/base/net_util.cc b/net/base/net_util.cc |
| index 1a8aa8962ffac5393f49848a33a0db768100ef46..4ed2e528e605feaff218533c261806f8023fad52 100644 |
| --- a/net/base/net_util.cc |
| +++ b/net/base/net_util.cc |
| @@ -2111,6 +2111,46 @@ int GetPortFromSockaddr(const struct sockaddr* address, socklen_t address_len) { |
| return ntohs(*port_field); |
| } |
| +bool IsLocalhost(const std::string& host) { |
| + if (host == "localhost" || |
| + host == "localhost.localdomain" || |
| + host == "localhost6" || |
| + host == "localhost6.localdomain6") |
|
yzshen1
2011/03/24 20:06:37
[minor, optional] might be good to change the comm
Jói
2011/03/24 22:03:45
Done.
|
| + return true; |
| + |
| + IPAddressNumber ip_number; |
| + if (ParseIPLiteralToNumber(host, &ip_number)) { |
| + size_t size = ip_number.size(); |
| + switch (size) { |
| + case kIPv4AddressSize: { |
| + IPAddressNumber localhost_prefix; |
| + localhost_prefix.push_back(127); |
| + for (int i = 0; i < 3; ++i) { |
| + localhost_prefix.push_back(0); |
| + } |
| + return IPNumberMatchesPrefix(ip_number, localhost_prefix, 8); |
| + } |
| + |
| + case kIPv6AddressSize: { |
| + if (ip_number[15] != 1) |
| + return false; |
| + |
| + for (int i = 0; i < 15; ++i) { |
| + if (ip_number[i] != 0) |
| + return false; |
| + } |
| + |
| + return true; |
| + } |
| + |
| + default: |
| + NOTREACHED(); |
| + } |
| + } |
| + |
| + return false; |
| +} |
| + |
| NetworkInterface::NetworkInterface() { |
| } |