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 |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
15 #include "base/strings/string_piece.h" | 15 #include "base/strings/string_piece.h" |
16 #include "net/base/ip_address_number.h" | |
17 #include "net/base/net_export.h" | 16 #include "net/base/net_export.h" |
18 | 17 |
19 namespace net { | 18 namespace net { |
20 | 19 |
21 class NET_EXPORT IPAddress { | 20 class NET_EXPORT IPAddress { |
22 public: | 21 public: |
23 enum : size_t { kIPv4AddressSize = 4, kIPv6AddressSize = 16 }; | 22 enum : size_t { kIPv4AddressSize = 4, kIPv6AddressSize = 16 }; |
24 | 23 |
25 // Creates a zero-sized, invalid address. | 24 // Creates a zero-sized, invalid address. |
26 IPAddress(); | 25 IPAddress(); |
27 | 26 |
28 // Creates an IP address from a deprecated IPAddressNumber. | 27 // Copies the input address to |ip_address_|. The input is expected to be in |
29 explicit IPAddress(const IPAddressNumber& address); | 28 // network byte order. |
| 29 explicit IPAddress(const std::vector<uint8_t>& address); |
30 | 30 |
31 IPAddress(const IPAddress& other); | 31 IPAddress(const IPAddress& other); |
32 | 32 |
33 // Copies the input address to |ip_address_|. The input is expected to be in | 33 // Copies the input address to |ip_address_|. The input is expected to be in |
34 // network byte order. | 34 // network byte order. |
35 template <size_t N> | 35 template <size_t N> |
36 IPAddress(const uint8_t(&address)[N]) | 36 IPAddress(const uint8_t(&address)[N]) |
37 : IPAddress(address, N) {} | 37 : IPAddress(address, N) {} |
38 | 38 |
39 // Copies the input address to |ip_address_| taking an additional length | 39 // Copies the input address to |ip_address_| taking an additional length |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 template <size_t N> | 198 template <size_t N> |
199 bool IPAddressStartsWith(const IPAddress& address, const uint8_t (&prefix)[N]) { | 199 bool IPAddressStartsWith(const IPAddress& address, const uint8_t (&prefix)[N]) { |
200 if (address.size() < N) | 200 if (address.size() < N) |
201 return false; | 201 return false; |
202 return std::equal(prefix, prefix + N, address.bytes().begin()); | 202 return std::equal(prefix, prefix + N, address.bytes().begin()); |
203 } | 203 } |
204 | 204 |
205 } // namespace net | 205 } // namespace net |
206 | 206 |
207 #endif // NET_BASE_IP_ADDRESS_NET_H_ | 207 #endif // NET_BASE_IP_ADDRESS_NET_H_ |
OLD | NEW |