OLD | NEW |
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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_NET_H_ | 5 #ifndef NET_BASE_IP_ADDRESS_NET_H_ |
6 #define NET_BASE_IP_ADDRESS_NET_H_ | 6 #define NET_BASE_IP_ADDRESS_NET_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 // Returns true if |ip_address_| is an IPv4-mapped IPv6 address. | 62 // Returns true if |ip_address_| is an IPv4-mapped IPv6 address. |
63 bool IsIPv4MappedIPv6() const; | 63 bool IsIPv4MappedIPv6() const; |
64 | 64 |
65 // The size in bytes of |ip_address_|. | 65 // The size in bytes of |ip_address_|. |
66 size_t size() const { return ip_address_.size(); } | 66 size_t size() const { return ip_address_.size(); } |
67 | 67 |
68 // Returns true if the IP is an empty, zero-sized (invalid) address. | 68 // Returns true if the IP is an empty, zero-sized (invalid) address. |
69 bool empty() const { return ip_address_.empty(); } | 69 bool empty() const { return ip_address_.empty(); } |
70 | 70 |
71 // Returns the canonical string representation of an IP address. | 71 // Returns the canonical string representation of an IP address. |
72 // For example: "192.168.0.1" or "::1". Returns the empty string when | 72 // For example: "192.168.0.1" or "::1". The IP address must be |
73 // |ip_address_| is invalid. | 73 // valid, calling this on an invalid address will result in a crash. |
74 std::string ToString() const; | 74 std::string ToString() const; |
75 | 75 |
76 // Parses an IP address literal (either IPv4 or IPv6) to its numeric value. | 76 // Parses an IP address literal (either IPv4 or IPv6) to its numeric value. |
77 // Returns true on success and fills |ip_address_| with the numeric value. | 77 // Returns true on success and fills |ip_address_| with the numeric value. |
78 bool AssignFromIPLiteral(const base::StringPiece& ip_literal) | 78 bool AssignFromIPLiteral(const base::StringPiece& ip_literal) |
79 WARN_UNUSED_RESULT; | 79 WARN_UNUSED_RESULT; |
80 | 80 |
81 // Returns the underlying byte vector. | 81 // Returns the underlying byte vector. |
82 const std::vector<uint8_t>& bytes() const { return ip_address_; }; | 82 const std::vector<uint8_t>& bytes() const { return ip_address_; }; |
83 | 83 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 // In cases when an IPv4 address is being compared to an IPv6 address prefix | 123 // In cases when an IPv4 address is being compared to an IPv6 address prefix |
124 // and vice versa, the IPv4 addresses will be converted to IPv4-mapped | 124 // and vice versa, the IPv4 addresses will be converted to IPv4-mapped |
125 // (IPv6) addresses. | 125 // (IPv6) addresses. |
126 NET_EXPORT bool IPAddressMatchesPrefix(const IPAddress& ip_address, | 126 NET_EXPORT bool IPAddressMatchesPrefix(const IPAddress& ip_address, |
127 const IPAddress& ip_prefix, | 127 const IPAddress& ip_prefix, |
128 size_t prefix_length_in_bits); | 128 size_t prefix_length_in_bits); |
129 | 129 |
130 } // namespace net | 130 } // namespace net |
131 | 131 |
132 #endif // NET_BASE_IP_ADDRESS_NET_H_ | 132 #endif // NET_BASE_IP_ADDRESS_NET_H_ |
OLD | NEW |