Chromium Code Reviews| Index: net/base/net_util.cc |
| diff --git a/net/base/net_util.cc b/net/base/net_util.cc |
| index b9cf59f1789a910bed6242794417f5592f0694f1..79d0be7fade3a73e6ac6c15a5e842b00ad1d3fd9 100644 |
| --- a/net/base/net_util.cc |
| +++ b/net/base/net_util.cc |
| @@ -68,79 +68,79 @@ namespace { |
| // The general list of blocked ports. Will be blocked unless a specific |
| // protocol overrides it. (Ex: ftp can use ports 20 and 21) |
| static const int kRestrictedPorts[] = { |
| - 1, // tcpmux |
| - 7, // echo |
| - 9, // discard |
| - 11, // systat |
| - 13, // daytime |
| - 15, // netstat |
| - 17, // qotd |
| - 19, // chargen |
| - 20, // ftp data |
| - 21, // ftp access |
| - 22, // ssh |
| - 23, // telnet |
| - 25, // smtp |
| - 37, // time |
| - 42, // name |
| - 43, // nicname |
| - 53, // domain |
| - 77, // priv-rjs |
| - 79, // finger |
| - 87, // ttylink |
| - 95, // supdup |
| - 101, // hostriame |
| - 102, // iso-tsap |
| - 103, // gppitnp |
| - 104, // acr-nema |
| - 109, // pop2 |
| - 110, // pop3 |
| - 111, // sunrpc |
| - 113, // auth |
| - 115, // sftp |
| - 117, // uucp-path |
| - 119, // nntp |
| - 123, // NTP |
| - 135, // loc-srv /epmap |
| - 139, // netbios |
| - 143, // imap2 |
| - 179, // BGP |
| - 389, // ldap |
| - 465, // smtp+ssl |
| - 512, // print / exec |
| - 513, // login |
| - 514, // shell |
| - 515, // printer |
| - 526, // tempo |
| - 530, // courier |
| - 531, // chat |
| - 532, // netnews |
| - 540, // uucp |
| - 556, // remotefs |
| - 563, // nntp+ssl |
| - 587, // stmp? |
| - 601, // ?? |
| - 636, // ldap+ssl |
| - 993, // ldap+ssl |
| - 995, // pop3+ssl |
| - 2049, // nfs |
| - 3659, // apple-sasl / PasswordServer |
| - 4045, // lockd |
| - 6000, // X11 |
| - 6665, // Alternate IRC [Apple addition] |
| - 6666, // Alternate IRC [Apple addition] |
| - 6667, // Standard IRC [Apple addition] |
| - 6668, // Alternate IRC [Apple addition] |
| - 6669, // Alternate IRC [Apple addition] |
| - 0xFFFF, // Used to block all invalid port numbers (see |
| - // third_party/WebKit/Source/platform/weborigin/KURL.cpp, |
| - // KURL::port()) |
| + 1, // tcpmux |
| + 7, // echo |
| + 9, // discard |
| + 11, // systat |
| + 13, // daytime |
| + 15, // netstat |
| + 17, // qotd |
| + 19, // chargen |
| + 20, // ftp data |
| + 21, // ftp access |
| + 22, // ssh |
| + 23, // telnet |
| + 25, // smtp |
| + 37, // time |
| + 42, // name |
| + 43, // nicname |
| + 53, // domain |
| + 77, // priv-rjs |
| + 79, // finger |
| + 87, // ttylink |
| + 95, // supdup |
| + 101, // hostriame |
| + 102, // iso-tsap |
| + 103, // gppitnp |
| + 104, // acr-nema |
| + 109, // pop2 |
| + 110, // pop3 |
| + 111, // sunrpc |
| + 113, // auth |
| + 115, // sftp |
| + 117, // uucp-path |
| + 119, // nntp |
| + 123, // NTP |
| + 135, // loc-srv /epmap |
| + 139, // netbios |
| + 143, // imap2 |
| + 179, // BGP |
| + 389, // ldap |
| + 465, // smtp+ssl |
| + 512, // print / exec |
| + 513, // login |
| + 514, // shell |
| + 515, // printer |
| + 526, // tempo |
| + 530, // courier |
| + 531, // chat |
| + 532, // netnews |
| + 540, // uucp |
| + 556, // remotefs |
| + 563, // nntp+ssl |
| + 587, // stmp? |
| + 601, // ?? |
| + 636, // ldap+ssl |
| + 993, // ldap+ssl |
| + 995, // pop3+ssl |
| + 2049, // nfs |
| + 3659, // apple-sasl / PasswordServer |
| + 4045, // lockd |
| + 6000, // X11 |
| + 6665, // Alternate IRC [Apple addition] |
| + 6666, // Alternate IRC [Apple addition] |
| + 6667, // Standard IRC [Apple addition] |
| + 6668, // Alternate IRC [Apple addition] |
| + 6669, // Alternate IRC [Apple addition] |
| + 0xFFFF, // Used to block all invalid port numbers (see |
| + // third_party/WebKit/Source/platform/weborigin/KURL.cpp, |
| + // KURL::port()) |
| }; |
| // FTP overrides the following restricted ports. |
| static const int kAllowedFtpPorts[] = { |
| - 21, // ftp data |
| - 22, // ssh |
| + 21, // ftp data |
| + 22, // ssh |
| }; |
| bool IPNumberPrefixCheck(const IPAddressNumber& ip_number, |
| @@ -190,8 +190,11 @@ std::string GetSpecificHeader(const std::string& headers, |
| std::string match('\n' + name + ':'); |
| std::string::const_iterator begin = |
| - std::search(headers.begin(), headers.end(), match.begin(), match.end(), |
| - base::CaseInsensitiveCompareASCII<char>()); |
| + std::search(headers.begin(), |
| + headers.end(), |
| + match.begin(), |
| + match.end(), |
| + base::CaseInsensitiveCompareASCII<char>()); |
| if (begin == headers.end()) |
| return std::string(); |
| @@ -199,9 +202,10 @@ std::string GetSpecificHeader(const std::string& headers, |
| begin += match.length(); |
| std::string ret; |
| - base::TrimWhitespace(std::string(begin, |
| - std::find(begin, headers.end(), '\n')), |
| - base::TRIM_ALL, &ret); |
| + base::TrimWhitespace( |
| + std::string(begin, std::find(begin, headers.end(), '\n')), |
| + base::TRIM_ALL, |
| + &ret); |
| return ret; |
| } |
| @@ -211,8 +215,8 @@ std::string CanonicalizeHost(const std::string& host, |
| const url::Component raw_host_component(0, static_cast<int>(host.length())); |
| std::string canon_host; |
| url::StdStringCanonOutput canon_host_output(&canon_host); |
| - url::CanonicalizeHostVerbose(host.c_str(), raw_host_component, |
| - &canon_host_output, host_info); |
| + url::CanonicalizeHostVerbose( |
| + host.c_str(), raw_host_component, &canon_host_output, host_info); |
| if (host_info->out_host.is_nonempty() && |
| host_info->family != url::CanonHostInfo::BROKEN) { |
| @@ -231,8 +235,8 @@ std::string GetDirectoryListingHeader(const base::string16& title) { |
| static const base::StringPiece header( |
| NetModule::GetResource(IDR_DIR_HEADER_HTML)); |
| // This can be null in unit tests. |
| - DLOG_IF(WARNING, header.empty()) << |
| - "Missing resource: directory listing header"; |
| + DLOG_IF(WARNING, header.empty()) |
| + << "Missing resource: directory listing header"; |
| std::string result; |
| if (!header.empty()) |
| @@ -308,7 +312,7 @@ bool IsPortAllowedByFtp(int port) { |
| int array_size = arraysize(kAllowedFtpPorts); |
| for (int i = 0; i < array_size; i++) { |
| if (kAllowedFtpPorts[i] == port) { |
| - return true; |
| + return true; |
| } |
| } |
| // Port not explicitly allowed by FTP, so return the default restrictions. |
| @@ -351,8 +355,12 @@ bool ParseHostAndPort(std::string::const_iterator host_and_port_begin, |
| url::Component hostname_component; |
| url::Component port_component; |
| - url::ParseAuthority(auth_begin, auth_component, &username_component, |
| - &password_component, &hostname_component, &port_component); |
| + url::ParseAuthority(auth_begin, |
| + auth_component, |
| + &username_component, |
| + &password_component, |
| + &hostname_component, |
| + &port_component); |
| // There shouldn't be a username/password. |
| if (username_component.is_valid() || password_component.is_valid()) |
| @@ -408,8 +416,8 @@ bool ParseHostAndPort(const std::string& host_and_port, |
| std::string GetHostAndPort(const GURL& url) { |
| // For IPv6 literals, GURL::host() already includes the brackets so it is |
| // safe to just append a colon. |
| - return base::StringPrintf("%s:%d", url.host().c_str(), |
| - url.EffectiveIntPort()); |
| + return base::StringPrintf( |
| + "%s:%d", url.host().c_str(), url.EffectiveIntPort()); |
| } |
| std::string GetHostAndOptionalPort(const GURL& url) { |
| @@ -422,8 +430,8 @@ std::string GetHostAndOptionalPort(const GURL& url) { |
| bool IsHostnameNonUnique(const std::string& hostname) { |
| // CanonicalizeHost requires surrounding brackets to parse an IPv6 address. |
| - const std::string host_or_ip = hostname.find(':') != std::string::npos ? |
| - "[" + hostname + "]" : hostname; |
| + const std::string host_or_ip = |
| + hostname.find(':') != std::string::npos ? "[" + hostname + "]" : hostname; |
| url::CanonHostInfo host_info; |
| std::string canonical_name = CanonicalizeHost(host_or_ip, &host_info); |
| @@ -436,9 +444,9 @@ bool IsHostnameNonUnique(const std::string& hostname) { |
| // range. |
| if (host_info.IsIPAddress()) { |
| IPAddressNumber host_addr; |
| - if (!ParseIPLiteralToNumber(hostname.substr(host_info.out_host.begin, |
| - host_info.out_host.len), |
| - &host_addr)) { |
| + if (!ParseIPLiteralToNumber( |
| + hostname.substr(host_info.out_host.begin, host_info.out_host.len), |
| + &host_addr)) { |
| return false; |
| } |
| switch (host_info.family) { |
| @@ -476,24 +484,31 @@ bool IsHostnameNonUnique(const std::string& hostname) { |
| // They're formatted here with the prefix as the last element. For example: |
| // 10.0.0.0/8 becomes 10,0,0,0,8 and fec0::/10 becomes 0xfe,0xc0,0,0,0...,10. |
| bool IsIPAddressReserved(const IPAddressNumber& host_addr) { |
| - static const unsigned char kReservedIPv4[][5] = { |
| - { 0,0,0,0,8 }, { 10,0,0,0,8 }, { 100,64,0,0,10 }, { 127,0,0,0,8 }, |
| - { 169,254,0,0,16 }, { 172,16,0,0,12 }, { 192,0,2,0,24 }, |
| - { 192,88,99,0,24 }, { 192,168,0,0,16 }, { 198,18,0,0,15 }, |
| - { 198,51,100,0,24 }, { 203,0,113,0,24 }, { 224,0,0,0,3 } |
| - }; |
| + static const unsigned char kReservedIPv4[][5] = {{0, 0, 0, 0, 8}, |
| + {10, 0, 0, 0, 8}, |
| + {100, 64, 0, 0, 10}, |
| + {127, 0, 0, 0, 8}, |
| + {169, 254, 0, 0, 16}, |
| + {172, 16, 0, 0, 12}, |
| + {192, 0, 2, 0, 24}, |
| + {192, 88, 99, 0, 24}, |
| + {192, 168, 0, 0, 16}, |
| + {198, 18, 0, 0, 15}, |
| + {198, 51, 100, 0, 24}, |
| + {203, 0, 113, 0, 24}, |
| + {224, 0, 0, 0, 3}}; |
|
Ryan Sleevi
2014/10/11 02:04:47
Another weird formatting
jkarlin
2014/10/16 00:19:32
Issued: https://code.google.com/p/chromium/issues/
jkarlin
2014/11/11 19:01:44
Feedback on the bug was that this one really could
|
| static const unsigned char kReservedIPv6[][17] = { |
| - { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8 }, |
| - { 0x40,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2 }, |
| - { 0x80,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2 }, |
| - { 0xc0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3 }, |
| - { 0xe0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4 }, |
| - { 0xf0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5 }, |
| - { 0xf8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6 }, |
| - { 0xfc,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7 }, |
| - { 0xfe,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9 }, |
| - { 0xfe,0x80,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10 }, |
| - { 0xfe,0xc0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10 }, |
| + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8}, |
| + {0x40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2}, |
| + {0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2}, |
| + {0xc0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3}, |
| + {0xe0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4}, |
| + {0xf0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5}, |
| + {0xf8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6}, |
| + {0xfc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7}, |
| + {0xfe, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9}, |
| + {0xfe, 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10}, |
| + {0xfe, 0xc0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10}, |
| }; |
| size_t array_size = 0; |
| const unsigned char* array = NULL; |
| @@ -511,7 +526,7 @@ bool IsIPAddressReserved(const IPAddressNumber& host_addr) { |
| return false; |
| size_t width = host_addr.size() + 1; |
| for (size_t i = 0; i < array_size; ++i, array += width) { |
| - if (IPNumberPrefixCheck(host_addr, array, array[width-1])) |
| + if (IPNumberPrefixCheck(host_addr, array, array[width - 1])) |
| return true; |
| } |
| return false; |
| @@ -563,8 +578,7 @@ bool GetIPAddressFromSockAddr(const struct sockaddr* sock_addr, |
| if (sock_addr->sa_family == AF_BTH) { |
| if (sock_addr_len < static_cast<socklen_t>(sizeof(SOCKADDR_BTH))) |
| return false; |
| - const SOCKADDR_BTH* addr = |
| - reinterpret_cast<const SOCKADDR_BTH*>(sock_addr); |
| + const SOCKADDR_BTH* addr = reinterpret_cast<const SOCKADDR_BTH*>(sock_addr); |
| *address = reinterpret_cast<const uint8*>(&addr->btAddr); |
| *address_len = kBluetoothAddressSize; |
| if (port) |
| @@ -576,8 +590,7 @@ bool GetIPAddressFromSockAddr(const struct sockaddr* sock_addr, |
| return false; // Unrecognized |sa_family|. |
| } |
| -std::string IPAddressToString(const uint8* address, |
| - size_t address_len) { |
| +std::string IPAddressToString(const uint8* address, size_t address_len) { |
| std::string str; |
| url::StdStringCanonOutput output(&str); |
| @@ -609,8 +622,8 @@ std::string NetAddressToString(const struct sockaddr* sa, |
| socklen_t sock_addr_len) { |
| const uint8* address; |
| size_t address_len; |
| - if (!GetIPAddressFromSockAddr(sa, sock_addr_len, &address, |
| - &address_len, NULL)) { |
| + if (!GetIPAddressFromSockAddr( |
| + sa, sock_addr_len, &address, &address_len, NULL)) { |
| NOTREACHED(); |
| return std::string(); |
| } |
| @@ -622,8 +635,8 @@ std::string NetAddressToStringWithPort(const struct sockaddr* sa, |
| const uint8* address; |
| size_t address_len; |
| uint16 port; |
| - if (!GetIPAddressFromSockAddr(sa, sock_addr_len, &address, |
| - &address_len, &port)) { |
| + if (!GetIPAddressFromSockAddr( |
| + sa, sock_addr_len, &address, &address_len, &port)) { |
| NOTREACHED(); |
| return std::string(); |
| } |
| @@ -640,8 +653,7 @@ std::string IPAddressToStringWithPort(const IPAddressNumber& addr, |
| } |
| std::string IPAddressToPackedString(const IPAddressNumber& addr) { |
| - return std::string(reinterpret_cast<const char *>(&addr.front()), |
| - addr.size()); |
| + return std::string(reinterpret_cast<const char*>(&addr.front()), addr.size()); |
| } |
| std::string GetHostName() { |
| @@ -680,9 +692,8 @@ std::string GetHostOrSpecFromURL(const GURL& url) { |
| bool CanStripTrailingSlash(const GURL& url) { |
| // Omit the path only for standard, non-file URLs with nothing but "/" after |
| // the hostname. |
| - return url.IsStandard() && !url.SchemeIsFile() && |
| - !url.SchemeIsFileSystem() && !url.has_query() && !url.has_ref() |
| - && url.path() == "/"; |
| + return url.IsStandard() && !url.SchemeIsFile() && !url.SchemeIsFileSystem() && |
| + !url.has_query() && !url.has_ref() && url.path() == "/"; |
| } |
| GURL SimplifyUrlForRequest(const GURL& url) { |
| @@ -754,8 +765,7 @@ bool HaveOnlyLoopbackAddresses() { |
| } |
| bool result = true; |
| - for (struct ifaddrs* interface = interface_addr; |
| - interface != NULL; |
| + for (struct ifaddrs* interface = interface_addr; interface != NULL; |
| interface = interface->ifa_next) { |
| if (!(IFF_UP & interface->ifa_flags)) |
| continue; |
| @@ -847,8 +857,8 @@ bool ParseIPLiteralToNumber(const std::string& ip_literal, |
| // Try parsing the hostname as an IPv6 literal. |
| ip_number->resize(16); // 128 bits. |
| - return url::IPv6AddressToNumber(host_brackets.data(), host_comp, |
| - &(*ip_number)[0]); |
| + return url::IPv6AddressToNumber( |
| + host_brackets.data(), host_comp, &(*ip_number)[0]); |
| } |
| // Otherwise the string is an IPv4 address. |
| @@ -863,7 +873,7 @@ bool ParseIPLiteralToNumber(const std::string& ip_literal, |
| namespace { |
| const unsigned char kIPv4MappedPrefix[] = |
| - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF }; |
| + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF}; |
| } |
| IPAddressNumber ConvertIPv4NumberToIPv6Number( |
| @@ -940,7 +950,8 @@ bool IPNumberMatchesPrefix(const IPAddressNumber& ip_number, |
| if (ip_number.size() != ip_prefix.size()) { |
| if (ip_number.size() == 4) { |
| return IPNumberMatchesPrefix(ConvertIPv4NumberToIPv6Number(ip_number), |
| - ip_prefix, prefix_length_in_bits); |
| + ip_prefix, |
| + prefix_length_in_bits); |
| } |
| return IPNumberMatchesPrefix(ip_number, |
| ConvertIPv4NumberToIPv6Number(ip_prefix), |
| @@ -976,10 +987,8 @@ 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") |
| return true; |
| IPAddressNumber ip_number; |
| @@ -1010,8 +1019,7 @@ bool IsLocalhost(const std::string& host) { |
| } |
| NetworkInterface::NetworkInterface() |
| - : type(NetworkChangeNotifier::CONNECTION_UNKNOWN), |
| - network_prefix(0) { |
| + : type(NetworkChangeNotifier::CONNECTION_UNKNOWN), network_prefix(0) { |
| } |
| NetworkInterface::NetworkInterface(const std::string& name, |