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 <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/strings/string_piece.h" | 12 #include "base/strings/string_piece.h" |
13 #include "net/base/net_export.h" | 13 #include "net/base/net_export.h" |
14 | 14 |
15 namespace net { | 15 namespace net { |
16 | 16 |
17 // IPAddressNumber is used to represent an IP address's numeric value as an | 17 // IPAddressNumber is used to represent an IP address's numeric value as an |
18 // array of bytes, from most significant to least significant. This is the | 18 // array of bytes, from most significant to least significant. This is the |
19 // network byte ordering. | 19 // network byte ordering. |
20 // | 20 // |
21 // IPv4 addresses will have length 4, whereas IPv6 address will have length 16. | 21 // IPv4 addresses will have length 4, whereas IPv6 address will have length 16. |
| 22 // |
| 23 // TODO(Martijnc): Remove the IPAddressNumber typedef. New code should use |
| 24 // IPAddress instead and existing code should be switched over. |
| 25 // https://crbug.com/496258 |
22 typedef std::vector<unsigned char> | 26 typedef std::vector<unsigned char> |
23 IPAddressNumber; // This is also duplicated in net_util.h | 27 IPAddressNumber; // This is also duplicated in net_util.h |
24 typedef std::vector<IPAddressNumber> IPAddressList; | 28 typedef std::vector<IPAddressNumber> IPAddressList; |
25 | 29 |
26 static const size_t kIPv4AddressSize = 4; | 30 static const size_t kIPv4AddressSize = 4; |
27 static const size_t kIPv6AddressSize = 16; | 31 static const size_t kIPv6AddressSize = 16; |
28 | 32 |
29 // Returns true if an IP address hostname is in a range reserved by the IANA. | 33 // Returns true if an IP address hostname is in a range reserved by the IANA. |
30 // Works with both IPv4 and IPv6 addresses, and only compares against a given | 34 // Works with both IPv4 and IPv6 addresses, and only compares against a given |
31 // protocols's reserved ranges. | 35 // protocols's reserved ranges. |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 // Returns number of matching initial bits between the addresses |a1| and |a2|. | 110 // Returns number of matching initial bits between the addresses |a1| and |a2|. |
107 unsigned CommonPrefixLength(const IPAddressNumber& a1, | 111 unsigned CommonPrefixLength(const IPAddressNumber& a1, |
108 const IPAddressNumber& a2); | 112 const IPAddressNumber& a2); |
109 | 113 |
110 // Computes the number of leading 1-bits in |mask|. | 114 // Computes the number of leading 1-bits in |mask|. |
111 unsigned MaskPrefixLength(const IPAddressNumber& mask); | 115 unsigned MaskPrefixLength(const IPAddressNumber& mask); |
112 | 116 |
113 } // namespace net | 117 } // namespace net |
114 | 118 |
115 #endif // NET_BASE_IP_ADDRESS_NUMBER_H_ | 119 #endif // NET_BASE_IP_ADDRESS_NUMBER_H_ |
OLD | NEW |