Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef NET_BASE_NET_UTIL_H_ | 5 #ifndef NET_BASE_NET_UTIL_H_ |
| 6 #define NET_BASE_NET_UTIL_H_ | 6 #define NET_BASE_NET_UTIL_H_ |
| 7 | 7 |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 | 9 |
| 10 #if defined(OS_WIN) | 10 #if defined(OS_WIN) |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 int* port); | 105 int* port); |
| 106 | 106 |
| 107 // Returns a host:port string for the given URL. | 107 // Returns a host:port string for the given URL. |
| 108 NET_EXPORT std::string GetHostAndPort(const GURL& url); | 108 NET_EXPORT std::string GetHostAndPort(const GURL& url); |
| 109 | 109 |
| 110 // Returns a host[:port] string for the given URL, where the port is omitted | 110 // Returns a host[:port] string for the given URL, where the port is omitted |
| 111 // if it is the default for the URL's scheme. | 111 // if it is the default for the URL's scheme. |
| 112 NET_EXPORT_PRIVATE std::string GetHostAndOptionalPort(const GURL& url); | 112 NET_EXPORT_PRIVATE std::string GetHostAndOptionalPort(const GURL& url); |
| 113 | 113 |
| 114 // Returns true if |hostname| contains a non-registerable or non-assignable | 114 // Returns true if |hostname| contains a non-registerable or non-assignable |
| 115 // domain name (eg: a gTLD that has not been assigned by IANA) | 115 // domain name (eg: a gTLD that has not been assigned by IANA) or an IP address |
| 116 // | 116 // that falls in an IANA-reserved range. |
| 117 // TODO(rsleevi): http://crbug.com/119212 - Also match internal IP | |
| 118 // address ranges. | |
| 119 NET_EXPORT bool IsHostnameNonUnique(const std::string& hostname); | 117 NET_EXPORT bool IsHostnameNonUnique(const std::string& hostname); |
| 120 | 118 |
| 119 // Returns true if an IP address hostname is in a range reserved by the IANA. | |
| 120 // Works with both IPv4 and IPv6 addresses, and only compares against a given | |
| 121 // protocols's reserved ranges. | |
| 122 NET_EXPORT bool IsIPAddressReserved(const IPAddressNumber& address); | |
| 123 | |
| 121 // Convenience struct for when you need a |struct sockaddr|. | 124 // Convenience struct for when you need a |struct sockaddr|. |
| 122 struct SockaddrStorage { | 125 struct SockaddrStorage { |
| 123 SockaddrStorage() : addr_len(sizeof(addr_storage)), | 126 SockaddrStorage() : addr_len(sizeof(addr_storage)), |
| 124 addr(reinterpret_cast<struct sockaddr*>(&addr_storage)) {} | 127 addr(reinterpret_cast<struct sockaddr*>(&addr_storage)) {} |
| 125 struct sockaddr_storage addr_storage; | 128 struct sockaddr_storage addr_storage; |
| 126 socklen_t addr_len; | 129 socklen_t addr_len; |
| 127 struct sockaddr* const addr; | 130 struct sockaddr* const addr; |
| 128 }; | 131 }; |
| 129 | 132 |
| 130 // Extracts the IP address and port portions of a sockaddr. |port| is optional, | 133 // Extracts the IP address and port portions of a sockaddr. |port| is optional, |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 474 // IP address whose |prefix_length_in_bits| most significant bits match | 477 // IP address whose |prefix_length_in_bits| most significant bits match |
| 475 // |ip_prefix| will be matched. | 478 // |ip_prefix| will be matched. |
| 476 // | 479 // |
| 477 // In cases when an IPv4 address is being compared to an IPv6 address prefix | 480 // In cases when an IPv4 address is being compared to an IPv6 address prefix |
| 478 // and vice versa, the IPv4 addresses will be converted to IPv4-mapped | 481 // and vice versa, the IPv4 addresses will be converted to IPv4-mapped |
| 479 // (IPv6) addresses. | 482 // (IPv6) addresses. |
| 480 NET_EXPORT_PRIVATE bool IPNumberMatchesPrefix(const IPAddressNumber& ip_number, | 483 NET_EXPORT_PRIVATE bool IPNumberMatchesPrefix(const IPAddressNumber& ip_number, |
| 481 const IPAddressNumber& ip_prefix, | 484 const IPAddressNumber& ip_prefix, |
| 482 size_t prefix_length_in_bits); | 485 size_t prefix_length_in_bits); |
| 483 | 486 |
| 487 // This is a helper method for IPNumberMatchesPrefix and IsIPAddressReserved. | |
| 488 // The |ip_prefix| should be a vector or an array. The |prefix_length_in_bits| | |
| 489 // should be a size_t, unsigned char, int, etc. | |
| 490 // We assume that the |ip_number| and |ip_prefix| are both IPv4 or both IPv6. | |
| 491 template<typename Arr, typename Length> | |
|
Ryan Sleevi
2013/08/09 22:50:12
style nit: "template<" -> "template <"
felt
2013/08/10 03:04:33
Done.
| |
| 492 NET_EXPORT_PRIVATE bool IPNumberPrefixCheck( | |
| 493 const IPAddressNumber& ip_number, | |
| 494 const Arr ip_prefix, | |
| 495 const Length prefix_length_in_bits); | |
|
Ryan Sleevi
2013/08/09 22:50:12
You can't (safely) forward declare the template li
felt
2013/08/10 03:04:33
Done.
| |
| 496 | |
| 484 // Retuns the port field of the |sockaddr|. | 497 // Retuns the port field of the |sockaddr|. |
| 485 const uint16* GetPortFieldFromSockaddr(const struct sockaddr* address, | 498 const uint16* GetPortFieldFromSockaddr(const struct sockaddr* address, |
| 486 socklen_t address_len); | 499 socklen_t address_len); |
| 487 // Returns the value of port in |sockaddr| (in host byte ordering). | 500 // Returns the value of port in |sockaddr| (in host byte ordering). |
| 488 NET_EXPORT_PRIVATE int GetPortFromSockaddr(const struct sockaddr* address, | 501 NET_EXPORT_PRIVATE int GetPortFromSockaddr(const struct sockaddr* address, |
| 489 socklen_t address_len); | 502 socklen_t address_len); |
| 490 | 503 |
| 491 // Returns true if |host| is one of the names (e.g. "localhost") or IP | 504 // Returns true if |host| is one of the names (e.g. "localhost") or IP |
| 492 // addresses (IPv4 127.0.0.0/8 or IPv6 ::1) that indicate a loopback. | 505 // addresses (IPv4 127.0.0.0/8 or IPv6 ::1) that indicate a loopback. |
| 493 // | 506 // |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 533 WIFI_PHY_LAYER_PROTOCOL_UNKNOWN | 546 WIFI_PHY_LAYER_PROTOCOL_UNKNOWN |
| 534 }; | 547 }; |
| 535 | 548 |
| 536 // Characterize the PHY mode of the currently associated access point. | 549 // Characterize the PHY mode of the currently associated access point. |
| 537 // Currently only available on OS_WIN. | 550 // Currently only available on OS_WIN. |
| 538 NET_EXPORT WifiPHYLayerProtocol GetWifiPHYLayerProtocol(); | 551 NET_EXPORT WifiPHYLayerProtocol GetWifiPHYLayerProtocol(); |
| 539 | 552 |
| 540 } // namespace net | 553 } // namespace net |
| 541 | 554 |
| 542 #endif // NET_BASE_NET_UTIL_H_ | 555 #endif // NET_BASE_NET_UTIL_H_ |
| OLD | NEW |