| 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 "base/strings/string_piece.h" | 7 #include "base/strings/string_piece.h" |
| 8 #include "base/strings/string_split.h" | 8 #include "base/strings/string_split.h" |
| 9 #include "net/base/ip_address_number.h" | 9 #include "net/base/ip_address_number.h" |
| 10 #include "net/base/parse_number.h" | 10 #include "net/base/parse_number.h" |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 cidr_literal, "/", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 174 cidr_literal, "/", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 175 if (parts.size() != 2) | 175 if (parts.size() != 2) |
| 176 return false; | 176 return false; |
| 177 | 177 |
| 178 // Parse the IP address. | 178 // Parse the IP address. |
| 179 if (!ip_address->AssignFromIPLiteral(parts[0])) | 179 if (!ip_address->AssignFromIPLiteral(parts[0])) |
| 180 return false; | 180 return false; |
| 181 | 181 |
| 182 // Parse the prefix length. | 182 // Parse the prefix length. |
| 183 int number_of_bits = -1; | 183 int number_of_bits = -1; |
| 184 if (!ParseNonNegativeDecimalInt(parts[1], &number_of_bits)) | 184 if (!ParseNonNegativeInteger(parts[1], &number_of_bits)) |
| 185 return false; | 185 return false; |
| 186 | 186 |
| 187 // Make sure the prefix length is in a valid range. | 187 // Make sure the prefix length is in a valid range. |
| 188 if (number_of_bits < 0 || | 188 if (number_of_bits < 0 || |
| 189 number_of_bits > static_cast<int>(ip_address->size() * 8)) | 189 number_of_bits > static_cast<int>(ip_address->size() * 8)) |
| 190 return false; | 190 return false; |
| 191 | 191 |
| 192 *prefix_length_in_bits = static_cast<size_t>(number_of_bits); | 192 *prefix_length_in_bits = static_cast<size_t>(number_of_bits); |
| 193 return true; | 193 return true; |
| 194 } | 194 } |
| 195 | 195 |
| 196 unsigned CommonPrefixLength(const IPAddress& a1, const IPAddress& a2) { | 196 unsigned CommonPrefixLength(const IPAddress& a1, const IPAddress& a2) { |
| 197 return CommonPrefixLength(a1.bytes(), a2.bytes()); | 197 return CommonPrefixLength(a1.bytes(), a2.bytes()); |
| 198 } | 198 } |
| 199 | 199 |
| 200 unsigned MaskPrefixLength(const IPAddress& mask) { | 200 unsigned MaskPrefixLength(const IPAddress& mask) { |
| 201 return MaskPrefixLength(mask.bytes()); | 201 return MaskPrefixLength(mask.bytes()); |
| 202 } | 202 } |
| 203 | 203 |
| 204 } // namespace net | 204 } // namespace net |
| OLD | NEW |