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". Returns the empty string when |address| | 40 // For example: "192.168.0.1" or "::1". |
41 // is invalid. | |
42 NET_EXPORT std::string IPAddressToString(const uint8_t* address, | 41 NET_EXPORT std::string IPAddressToString(const uint8_t* address, |
43 size_t address_len); | 42 size_t address_len); |
44 | 43 |
45 // Returns the string representation of an IP address along with its port. | 44 // Returns the string representation of an IP address along with its port. |
46 // For example: "192.168.0.1:99" or "[::1]:80". Returns the empty string when | 45 // For example: "192.168.0.1:99" or "[::1]:80". |
47 // |address| is invalid (the port will be ignored). | |
48 NET_EXPORT std::string IPAddressToStringWithPort(const uint8_t* address, | 46 NET_EXPORT std::string IPAddressToStringWithPort(const uint8_t* address, |
49 size_t address_len, | 47 size_t address_len, |
50 uint16_t port); | 48 uint16_t port); |
51 | 49 |
52 // Same as IPAddressToString() but for an IPAddressNumber. | 50 // Same as IPAddressToString() but for an IPAddressNumber. |
53 NET_EXPORT std::string IPAddressToString(const IPAddressNumber& addr); | 51 NET_EXPORT std::string IPAddressToString(const IPAddressNumber& addr); |
54 | 52 |
55 // Same as IPAddressToStringWithPort() but for an IPAddressNumber. | 53 // Same as IPAddressToStringWithPort() but for an IPAddressNumber. |
56 NET_EXPORT std::string IPAddressToStringWithPort(const IPAddressNumber& addr, | 54 NET_EXPORT std::string IPAddressToStringWithPort(const IPAddressNumber& addr, |
57 uint16_t port); | 55 uint16_t port); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 // Returns number of matching initial bits between the addresses |a1| and |a2|. | 111 // Returns number of matching initial bits between the addresses |a1| and |a2|. |
114 unsigned CommonPrefixLength(const IPAddressNumber& a1, | 112 unsigned CommonPrefixLength(const IPAddressNumber& a1, |
115 const IPAddressNumber& a2); | 113 const IPAddressNumber& a2); |
116 | 114 |
117 // Computes the number of leading 1-bits in |mask|. | 115 // Computes the number of leading 1-bits in |mask|. |
118 unsigned MaskPrefixLength(const IPAddressNumber& mask); | 116 unsigned MaskPrefixLength(const IPAddressNumber& mask); |
119 | 117 |
120 } // namespace net | 118 } // namespace net |
121 | 119 |
122 #endif // NET_BASE_IP_ADDRESS_NUMBER_H_ | 120 #endif // NET_BASE_IP_ADDRESS_NUMBER_H_ |
OLD | NEW |