Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(846)

Side by Side Diff: net/base/ip_address.h

Issue 1810183002: Migrate net/proxy/* to net::IPAddress. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: re-add a comment Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | net/base/ip_address.cc » ('j') | net/base/ip_address_number_unittest.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 // IP address whose |prefix_length_in_bits| most significant bits match 142 // IP address whose |prefix_length_in_bits| most significant bits match
143 // |ip_prefix| will be matched. 143 // |ip_prefix| will be matched.
144 // 144 //
145 // In cases when an IPv4 address is being compared to an IPv6 address prefix 145 // In cases when an IPv4 address is being compared to an IPv6 address prefix
146 // and vice versa, the IPv4 addresses will be converted to IPv4-mapped 146 // and vice versa, the IPv4 addresses will be converted to IPv4-mapped
147 // (IPv6) addresses. 147 // (IPv6) addresses.
148 NET_EXPORT bool IPAddressMatchesPrefix(const IPAddress& ip_address, 148 NET_EXPORT bool IPAddressMatchesPrefix(const IPAddress& ip_address,
149 const IPAddress& ip_prefix, 149 const IPAddress& ip_prefix,
150 size_t prefix_length_in_bits); 150 size_t prefix_length_in_bits);
151 151
152 // Parses an IP block specifier from CIDR notation to an
153 // (IP address, prefix length) pair. Returns true on success and fills
154 // |ip_address| with the numeric value of the IP address and sets
155 // |prefix_length_in_bits| with the length of the prefix.
156 //
157 // CIDR notation literals can use either IPv4 or IPv6 literals. Some examples:
158 //
159 // 10.10.3.1/20
160 // a:b:c::/46
161 // ::1/128
162 NET_EXPORT bool ParseCIDRBlock(const std::string& cidr_literal,
163 IPAddress& ip_address,
eroman 2016/03/18 19:59:45 Why was the signature changed? Google C++ style r
martijnc 2016/03/18 21:41:11 Changed. Wanted to avoid passing a pointer and wa
164 size_t& prefix_length_in_bits);
165
152 // Returns number of matching initial bits between the addresses |a1| and |a2|. 166 // Returns number of matching initial bits between the addresses |a1| and |a2|.
153 unsigned CommonPrefixLength(const IPAddress& a1, const IPAddress& a2); 167 unsigned CommonPrefixLength(const IPAddress& a1, const IPAddress& a2);
154 168
155 // Computes the number of leading 1-bits in |mask|. 169 // Computes the number of leading 1-bits in |mask|.
156 unsigned MaskPrefixLength(const IPAddress& mask); 170 unsigned MaskPrefixLength(const IPAddress& mask);
157 171
158 // Checks whether |address| starts with |prefix|. This provides similar 172 // Checks whether |address| starts with |prefix|. This provides similar
159 // functionality as IPAddressMatchesPrefix() but doesn't perform automatic IPv4 173 // functionality as IPAddressMatchesPrefix() but doesn't perform automatic IPv4
160 // to IPv4MappedIPv6 conversions and only checks against full bytes. 174 // to IPv4MappedIPv6 conversions and only checks against full bytes.
161 template <size_t N> 175 template <size_t N>
162 bool IPAddressStartsWith(const IPAddress& address, const uint8_t (&prefix)[N]) { 176 bool IPAddressStartsWith(const IPAddress& address, const uint8_t (&prefix)[N]) {
163 if (address.size() < N) 177 if (address.size() < N)
164 return false; 178 return false;
165 return std::equal(prefix, prefix + N, address.bytes().begin()); 179 return std::equal(prefix, prefix + N, address.bytes().begin());
166 } 180 }
167 181
168 } // namespace net 182 } // namespace net
169 183
170 #endif // NET_BASE_IP_ADDRESS_NET_H_ 184 #endif // NET_BASE_IP_ADDRESS_NET_H_
OLDNEW
« no previous file with comments | « no previous file | net/base/ip_address.cc » ('j') | net/base/ip_address_number_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698