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_IP_ADDRESS_NUMBER_H_ | 5 #ifndef NET_BASE_IP_ADDRESS_NUMBER_H_ |
6 #define NET_BASE_IP_ADDRESS_NUMBER_H_ | 6 #define NET_BASE_IP_ADDRESS_NUMBER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 static const size_t kIPv4AddressSize = 4; | 31 static const size_t kIPv4AddressSize = 4; |
32 static const size_t kIPv6AddressSize = 16; | 32 static const size_t kIPv6AddressSize = 16; |
33 | 33 |
34 // Returns true if an IP address hostname is in a range reserved by the IANA. | 34 // Returns true if an IP address hostname is in a range reserved by the IANA. |
35 // Works with both IPv4 and IPv6 addresses, and only compares against a given | 35 // Works with both IPv4 and IPv6 addresses, and only compares against a given |
36 // protocols's reserved ranges. | 36 // protocols's reserved ranges. |
37 NET_EXPORT bool IsIPAddressReserved(const IPAddressNumber& address); | 37 NET_EXPORT bool IsIPAddressReserved(const IPAddressNumber& address); |
38 | 38 |
39 // Returns the string representation of an IP address. | 39 // Returns the string representation of an IP address. |
40 // For example: "192.168.0.1" or "::1". | 40 // For example: "192.168.0.1" or "::1". Returns the empty string when |address| |
| 41 // is invalid. |
41 NET_EXPORT std::string IPAddressToString(const uint8_t* address, | 42 NET_EXPORT std::string IPAddressToString(const uint8_t* address, |
42 size_t address_len); | 43 size_t address_len); |
43 | 44 |
44 // Returns the string representation of an IP address along with its port. | 45 // Returns the string representation of an IP address along with its port. |
45 // For example: "192.168.0.1:99" or "[::1]:80". | 46 // For example: "192.168.0.1:99" or "[::1]:80". Returns the empty string when |
| 47 // |address| is invalid (the port will be ignored). |
46 NET_EXPORT std::string IPAddressToStringWithPort(const uint8_t* address, | 48 NET_EXPORT std::string IPAddressToStringWithPort(const uint8_t* address, |
47 size_t address_len, | 49 size_t address_len, |
48 uint16_t port); | 50 uint16_t port); |
49 | 51 |
50 // Same as IPAddressToString() but for an IPAddressNumber. | 52 // Same as IPAddressToString() but for an IPAddressNumber. |
51 NET_EXPORT std::string IPAddressToString(const IPAddressNumber& addr); | 53 NET_EXPORT std::string IPAddressToString(const IPAddressNumber& addr); |
52 | 54 |
53 // Same as IPAddressToStringWithPort() but for an IPAddressNumber. | 55 // Same as IPAddressToStringWithPort() but for an IPAddressNumber. |
54 NET_EXPORT std::string IPAddressToStringWithPort(const IPAddressNumber& addr, | 56 NET_EXPORT std::string IPAddressToStringWithPort(const IPAddressNumber& addr, |
55 uint16_t port); | 57 uint16_t port); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 // Returns number of matching initial bits between the addresses |a1| and |a2|. | 113 // Returns number of matching initial bits between the addresses |a1| and |a2|. |
112 unsigned CommonPrefixLength(const IPAddressNumber& a1, | 114 unsigned CommonPrefixLength(const IPAddressNumber& a1, |
113 const IPAddressNumber& a2); | 115 const IPAddressNumber& a2); |
114 | 116 |
115 // Computes the number of leading 1-bits in |mask|. | 117 // Computes the number of leading 1-bits in |mask|. |
116 unsigned MaskPrefixLength(const IPAddressNumber& mask); | 118 unsigned MaskPrefixLength(const IPAddressNumber& mask); |
117 | 119 |
118 } // namespace net | 120 } // namespace net |
119 | 121 |
120 #endif // NET_BASE_IP_ADDRESS_NUMBER_H_ | 122 #endif // NET_BASE_IP_ADDRESS_NUMBER_H_ |
OLD | NEW |