Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/base/net_util.h" | 5 #include "net/base/net_util.h" |
| 6 | 6 |
| 7 #include <unicode/regex.h> | 7 #include <unicode/regex.h> |
| 8 #include <unicode/ucnv.h> | 8 #include <unicode/ucnv.h> |
| 9 #include <unicode/uidna.h> | 9 #include <unicode/uidna.h> |
| 10 #include <unicode/ulocdata.h> | 10 #include <unicode/ulocdata.h> |
| (...skipping 2093 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2104 } | 2104 } |
| 2105 } | 2105 } |
| 2106 | 2106 |
| 2107 int GetPortFromSockaddr(const struct sockaddr* address, socklen_t address_len) { | 2107 int GetPortFromSockaddr(const struct sockaddr* address, socklen_t address_len) { |
| 2108 const uint16* port_field = GetPortFieldFromSockaddr(address, address_len); | 2108 const uint16* port_field = GetPortFieldFromSockaddr(address, address_len); |
| 2109 if (!port_field) | 2109 if (!port_field) |
| 2110 return -1; | 2110 return -1; |
| 2111 return ntohs(*port_field); | 2111 return ntohs(*port_field); |
| 2112 } | 2112 } |
| 2113 | 2113 |
| 2114 bool IsLocalhost(const std::string& host) { | |
| 2115 if (host == "localhost" || | |
| 2116 host == "localhost.localdomain" || | |
| 2117 host == "localhost6" || | |
| 2118 host == "localhost6.localdomain6") | |
| 2119 return true; | |
| 2120 | |
| 2121 IPAddressNumber ip_number; | |
| 2122 if (ParseIPLiteralToNumber(host, &ip_number)) { | |
| 2123 size_t size = ip_number.size(); | |
| 2124 switch (size) { | |
| 2125 case kIPv4AddressSize: { | |
| 2126 IPAddressNumber localhost_prefix; | |
| 2127 localhost_prefix.push_back(127); | |
| 2128 for (int i = 0; i < 3; ++i) { | |
| 2129 localhost_prefix.push_back(0); | |
| 2130 } | |
| 2131 return IPNumberMatchesPrefix(ip_number, localhost_prefix, 8); | |
| 2132 } | |
| 2133 | |
| 2134 case kIPv6AddressSize: { | |
| 2135 struct in6_addr sin6_addr; | |
| 2136 memcpy(&sin6_addr, &ip_number[0], kIPv6AddressSize); | |
| 2137 return IN6_IS_ADDR_LOOPBACK(&sin6_addr) != FALSE; | |
|
wtc
2011/03/28 22:08:19
The != FALSE part should be unnecessary. I know w
| |
| 2138 } | |
| 2139 | |
| 2140 default: | |
| 2141 NOTREACHED(); | |
| 2142 } | |
| 2143 } | |
| 2144 | |
| 2145 return false; | |
| 2146 } | |
| 2147 | |
| 2114 NetworkInterface::NetworkInterface() { | 2148 NetworkInterface::NetworkInterface() { |
| 2115 } | 2149 } |
| 2116 | 2150 |
| 2117 NetworkInterface::NetworkInterface(const std::string& name, | 2151 NetworkInterface::NetworkInterface(const std::string& name, |
| 2118 const IPAddressNumber& address) | 2152 const IPAddressNumber& address) |
| 2119 : name(name), address(address) { | 2153 : name(name), address(address) { |
| 2120 } | 2154 } |
| 2121 | 2155 |
| 2122 NetworkInterface::~NetworkInterface() { | 2156 NetworkInterface::~NetworkInterface() { |
| 2123 } | 2157 } |
| 2124 | 2158 |
| 2125 } // namespace net | 2159 } // namespace net |
| OLD | NEW |