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 #include "net/base/ip_address.h" | 5 #include "net/base/ip_address.h" |
6 | 6 |
7 #include <limits.h> | 7 #include <limits.h> |
8 | 8 |
9 #include "base/strings/string_piece.h" | 9 #include "base/strings/string_piece.h" |
10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "net/base/ip_address_number.h" | |
13 #include "net/base/parse_number.h" | 12 #include "net/base/parse_number.h" |
14 #include "url/gurl.h" | 13 #include "url/gurl.h" |
15 #include "url/url_canon_ip.h" | 14 #include "url/url_canon_ip.h" |
16 | 15 |
17 namespace { | 16 namespace { |
18 | 17 |
19 // The prefix for IPv6 mapped IPv4 addresses. | 18 // The prefix for IPv6 mapped IPv4 addresses. |
20 // https://tools.ietf.org/html/rfc4291#section-2.5.5.2 | 19 // https://tools.ietf.org/html/rfc4291#section-2.5.5.2 |
21 const uint8_t kIPv4MappedPrefix[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF}; | 20 const uint8_t kIPv4MappedPrefix[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF}; |
22 | 21 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 ip_literal.data(), host_comp, bytes->data(), &num_components); | 127 ip_literal.data(), host_comp, bytes->data(), &num_components); |
129 return family == url::CanonHostInfo::IPV4; | 128 return family == url::CanonHostInfo::IPV4; |
130 } | 129 } |
131 | 130 |
132 } // namespace | 131 } // namespace |
133 | 132 |
134 namespace net { | 133 namespace net { |
135 | 134 |
136 IPAddress::IPAddress() {} | 135 IPAddress::IPAddress() {} |
137 | 136 |
138 IPAddress::IPAddress(const IPAddressNumber& address) : ip_address_(address) {} | 137 IPAddress::IPAddress(const std::vector<uint8_t>& address) |
| 138 : ip_address_(address) {} |
139 | 139 |
140 IPAddress::IPAddress(const IPAddress& other) = default; | 140 IPAddress::IPAddress(const IPAddress& other) = default; |
141 | 141 |
142 IPAddress::IPAddress(const uint8_t* address, size_t address_len) | 142 IPAddress::IPAddress(const uint8_t* address, size_t address_len) |
143 : ip_address_(address, address + address_len) {} | 143 : ip_address_(address, address + address_len) {} |
144 | 144 |
145 IPAddress::IPAddress(uint8_t b0, uint8_t b1, uint8_t b2, uint8_t b3) { | 145 IPAddress::IPAddress(uint8_t b0, uint8_t b1, uint8_t b2, uint8_t b3) { |
146 ip_address_.reserve(4); | 146 ip_address_.reserve(4); |
147 ip_address_.push_back(b0); | 147 ip_address_.push_back(b0); |
148 ip_address_.push_back(b1); | 148 ip_address_.push_back(b1); |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 } | 396 } |
397 return a1.size() * CHAR_BIT; | 397 return a1.size() * CHAR_BIT; |
398 } | 398 } |
399 | 399 |
400 unsigned MaskPrefixLength(const IPAddress& mask) { | 400 unsigned MaskPrefixLength(const IPAddress& mask) { |
401 std::vector<uint8_t> all_ones(mask.size(), 0xFF); | 401 std::vector<uint8_t> all_ones(mask.size(), 0xFF); |
402 return CommonPrefixLength(mask, IPAddress(all_ones)); | 402 return CommonPrefixLength(mask, IPAddress(all_ones)); |
403 } | 403 } |
404 | 404 |
405 } // namespace net | 405 } // namespace net |
OLD | NEW |