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

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

Issue 1828103002: Extend net/base/parse_number.h for parsing of negative numbers, and determining if there was overflo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@proxy_num
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
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 #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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698