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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 bool operator<(const IPAddress& that) const; | 98 bool operator<(const IPAddress& that) const; |
99 | 99 |
100 private: | 100 private: |
101 // IPv4 addresses will have length kIPv4AddressSize, whereas IPv6 address | 101 // IPv4 addresses will have length kIPv4AddressSize, whereas IPv6 address |
102 // will have length kIPv6AddressSize. | 102 // will have length kIPv6AddressSize. |
103 std::vector<uint8_t> ip_address_; | 103 std::vector<uint8_t> ip_address_; |
104 | 104 |
105 // This class is copyable and assignable. | 105 // This class is copyable and assignable. |
106 }; | 106 }; |
107 | 107 |
| 108 using IPAddressList = std::vector<IPAddress>; |
| 109 |
108 // TODO(Martijnc): These utility functions currently forward the calls to | 110 // TODO(Martijnc): These utility functions currently forward the calls to |
109 // the IPAddressNumber implementations. Move the implementations over when | 111 // the IPAddressNumber implementations. Move the implementations over when |
110 // the IPAddressNumber migration is complete. https://crbug.com/496258. | 112 // the IPAddressNumber migration is complete. https://crbug.com/496258. |
111 | 113 |
112 // Returns the canonical string representation of an IP address along with its | 114 // Returns the canonical string representation of an IP address along with its |
113 // port. For example: "192.168.0.1:99" or "[::1]:80". | 115 // port. For example: "192.168.0.1:99" or "[::1]:80". |
114 NET_EXPORT std::string IPAddressToStringWithPort(const IPAddress& address, | 116 NET_EXPORT std::string IPAddressToStringWithPort(const IPAddress& address, |
115 uint16_t port); | 117 uint16_t port); |
116 | 118 |
117 // Returns the address as a sequence of bytes in network-byte-order. | 119 // Returns the address as a sequence of bytes in network-byte-order. |
(...skipping 27 matching lines...) Expand all Loading... |
145 template <size_t N> | 147 template <size_t N> |
146 bool IPAddressStartsWith(const IPAddress& address, const uint8_t (&prefix)[N]) { | 148 bool IPAddressStartsWith(const IPAddress& address, const uint8_t (&prefix)[N]) { |
147 if (address.size() < N) | 149 if (address.size() < N) |
148 return false; | 150 return false; |
149 return std::equal(prefix, prefix + N, address.bytes().begin()); | 151 return std::equal(prefix, prefix + N, address.bytes().begin()); |
150 } | 152 } |
151 | 153 |
152 } // namespace net | 154 } // namespace net |
153 | 155 |
154 #endif // NET_BASE_IP_ADDRESS_NET_H_ | 156 #endif // NET_BASE_IP_ADDRESS_NET_H_ |
OLD | NEW |