Chromium Code Reviews| Index: net/base/net_util.cc |
| diff --git a/net/base/net_util.cc b/net/base/net_util.cc |
| index 941dca9ab53ba1a4cb3214712a4ae7e16cf7ee62..7edd8ad2333a7a91af4248e045e98dc096fd2819 100644 |
| --- a/net/base/net_util.cc |
| +++ b/net/base/net_util.cc |
| @@ -799,6 +799,27 @@ int ConvertAddressFamily(AddressFamily address_family) { |
| return AF_UNSPEC; |
| } |
| +bool ParseURLHostnameToNumber(const std::string& hostname, |
| + IPAddressNumber* ip_number) { |
| + // |hostname| must be a canonicalized hostname with brackets and everything. |
|
Ryan Sleevi
2014/08/06 19:42:12
"with brackets and everything" is a bit too colloq
Mike West
2014/08/08 08:15:03
Done.
|
| + // Otherwise, explosions. |
| + 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 |