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

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: 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 NET_EXPORT bool ParseCIDRBlock(const std::string& cidr_literal,
153 IPAddress& ip_address,
154 size_t& prefix_length_in_bits);
155
152 // Returns number of matching initial bits between the addresses |a1| and |a2|. 156 // Returns number of matching initial bits between the addresses |a1| and |a2|.
153 unsigned CommonPrefixLength(const IPAddress& a1, const IPAddress& a2); 157 unsigned CommonPrefixLength(const IPAddress& a1, const IPAddress& a2);
154 158
155 // Computes the number of leading 1-bits in |mask|. 159 // Computes the number of leading 1-bits in |mask|.
156 unsigned MaskPrefixLength(const IPAddress& mask); 160 unsigned MaskPrefixLength(const IPAddress& mask);
157 161
158 // Checks whether |address| starts with |prefix|. This provides similar 162 // Checks whether |address| starts with |prefix|. This provides similar
159 // functionality as IPAddressMatchesPrefix() but doesn't perform automatic IPv4 163 // functionality as IPAddressMatchesPrefix() but doesn't perform automatic IPv4
160 // to IPv4MappedIPv6 conversions and only checks against full bytes. 164 // to IPv4MappedIPv6 conversions and only checks against full bytes.
161 template <size_t N> 165 template <size_t N>
162 bool IPAddressStartsWith(const IPAddress& address, const uint8_t (&prefix)[N]) { 166 bool IPAddressStartsWith(const IPAddress& address, const uint8_t (&prefix)[N]) {
163 if (address.size() < N) 167 if (address.size() < N)
164 return false; 168 return false;
165 return std::equal(prefix, prefix + N, address.bytes().begin()); 169 return std::equal(prefix, prefix + N, address.bytes().begin());
166 } 170 }
167 171
168 } // namespace net 172 } // namespace net
169 173
170 #endif // NET_BASE_IP_ADDRESS_NET_H_ 174 #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