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

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

Issue 1810183002: Migrate net/proxy/* to net::IPAddress. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments eroman 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 | « net/base/ip_address.cc ('k') | net/base/ip_address_number.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 const IPAddressNumber& ipv4_number); 74 const IPAddressNumber& ipv4_number);
75 75
76 // Returns true iff |address| is an IPv4-mapped IPv6 address. 76 // Returns true iff |address| is an IPv4-mapped IPv6 address.
77 NET_EXPORT_PRIVATE bool IsIPv4Mapped(const IPAddressNumber& address); 77 NET_EXPORT_PRIVATE bool IsIPv4Mapped(const IPAddressNumber& address);
78 78
79 // Converts an IPv4-mapped IPv6 address to IPv4 address. Should only be called 79 // Converts an IPv4-mapped IPv6 address to IPv4 address. Should only be called
80 // on IPv4-mapped IPv6 addresses. 80 // on IPv4-mapped IPv6 addresses.
81 NET_EXPORT_PRIVATE IPAddressNumber ConvertIPv4MappedToIPv4( 81 NET_EXPORT_PRIVATE IPAddressNumber ConvertIPv4MappedToIPv4(
82 const IPAddressNumber& address); 82 const IPAddressNumber& address);
83 83
84 // Parses an IP block specifier from CIDR notation to an
85 // (IP address, prefix length) pair. Returns true on success and fills
86 // |*ip_number| with the numeric value of the IP address and sets
87 // |*prefix_length_in_bits| with the length of the prefix.
88 //
89 // CIDR notation literals can use either IPv4 or IPv6 literals. Some examples:
90 //
91 // 10.10.3.1/20
92 // a:b:c::/46
93 // ::1/128
94 NET_EXPORT bool ParseCIDRBlock(const std::string& cidr_literal,
95 IPAddressNumber* ip_number,
96 size_t* prefix_length_in_bits);
97
98 // Compares an IP address to see if it falls within the specified IP block. 84 // Compares an IP address to see if it falls within the specified IP block.
99 // Returns true if it does, false otherwise. 85 // Returns true if it does, false otherwise.
100 // 86 //
101 // The IP block is given by (|ip_prefix|, |prefix_length_in_bits|) -- any 87 // The IP block is given by (|ip_prefix|, |prefix_length_in_bits|) -- any
102 // IP address whose |prefix_length_in_bits| most significant bits match 88 // IP address whose |prefix_length_in_bits| most significant bits match
103 // |ip_prefix| will be matched. 89 // |ip_prefix| will be matched.
104 // 90 //
105 // In cases when an IPv4 address is being compared to an IPv6 address prefix 91 // In cases when an IPv4 address is being compared to an IPv6 address prefix
106 // and vice versa, the IPv4 addresses will be converted to IPv4-mapped 92 // and vice versa, the IPv4 addresses will be converted to IPv4-mapped
107 // (IPv6) addresses. 93 // (IPv6) addresses.
108 NET_EXPORT_PRIVATE bool IPNumberMatchesPrefix(const IPAddressNumber& ip_number, 94 NET_EXPORT_PRIVATE bool IPNumberMatchesPrefix(const IPAddressNumber& ip_number,
109 const IPAddressNumber& ip_prefix, 95 const IPAddressNumber& ip_prefix,
110 size_t prefix_length_in_bits); 96 size_t prefix_length_in_bits);
111 97
112 // Returns number of matching initial bits between the addresses |a1| and |a2|. 98 // Returns number of matching initial bits between the addresses |a1| and |a2|.
113 unsigned CommonPrefixLength(const IPAddressNumber& a1, 99 unsigned CommonPrefixLength(const IPAddressNumber& a1,
114 const IPAddressNumber& a2); 100 const IPAddressNumber& a2);
115 101
116 // Computes the number of leading 1-bits in |mask|. 102 // Computes the number of leading 1-bits in |mask|.
117 unsigned MaskPrefixLength(const IPAddressNumber& mask); 103 unsigned MaskPrefixLength(const IPAddressNumber& mask);
118 104
119 } // namespace net 105 } // namespace net
120 106
121 #endif // NET_BASE_IP_ADDRESS_NUMBER_H_ 107 #endif // NET_BASE_IP_ADDRESS_NUMBER_H_
OLDNEW
« no previous file with comments | « net/base/ip_address.cc ('k') | net/base/ip_address_number.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698