OLD | NEW |
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 #include "net/base/net_util.h" | 5 #include "net/base/net_util.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 | 369 |
370 // If parsing failed, port_number will be either PORT_INVALID or | 370 // If parsing failed, port_number will be either PORT_INVALID or |
371 // PORT_UNSPECIFIED, both of which are negative. | 371 // PORT_UNSPECIFIED, both of which are negative. |
372 if (parsed_port_number < 0) | 372 if (parsed_port_number < 0) |
373 return false; // Failed parsing the port number. | 373 return false; // Failed parsing the port number. |
374 } | 374 } |
375 | 375 |
376 if (port_component.len == 0) | 376 if (port_component.len == 0) |
377 return false; // Reject inputs like "foo:" | 377 return false; // Reject inputs like "foo:" |
378 | 378 |
| 379 unsigned char tmp_ipv6_addr[16]; |
| 380 |
| 381 // If the hostname starts with a bracket, it is either an IPv6 literal or |
| 382 // invalid. If it is an IPv6 literal then strip the brackets. |
| 383 if (hostname_component.len > 0 && |
| 384 auth_begin[hostname_component.begin] == '[') { |
| 385 if (auth_begin[hostname_component.end() - 1] == ']' && |
| 386 url::IPv6AddressToNumber( |
| 387 auth_begin, hostname_component, tmp_ipv6_addr)) { |
| 388 // Strip the brackets. |
| 389 hostname_component.begin++; |
| 390 hostname_component.len -= 2; |
| 391 } else { |
| 392 return false; |
| 393 } |
| 394 } |
| 395 |
379 // Pass results back to caller. | 396 // Pass results back to caller. |
380 host->assign(auth_begin + hostname_component.begin, hostname_component.len); | 397 host->assign(auth_begin + hostname_component.begin, hostname_component.len); |
381 *port = parsed_port_number; | 398 *port = parsed_port_number; |
382 | 399 |
383 return true; // Success. | 400 return true; // Success. |
384 } | 401 } |
385 | 402 |
386 bool ParseHostAndPort(const std::string& host_and_port, | 403 bool ParseHostAndPort(const std::string& host_and_port, |
387 std::string* host, | 404 std::string* host, |
388 int* port) { | 405 int* port) { |
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1037 | 1054 |
1038 unsigned MaskPrefixLength(const IPAddressNumber& mask) { | 1055 unsigned MaskPrefixLength(const IPAddressNumber& mask) { |
1039 IPAddressNumber all_ones(mask.size(), 0xFF); | 1056 IPAddressNumber all_ones(mask.size(), 0xFF); |
1040 return CommonPrefixLength(mask, all_ones); | 1057 return CommonPrefixLength(mask, all_ones); |
1041 } | 1058 } |
1042 | 1059 |
1043 ScopedWifiOptions::~ScopedWifiOptions() { | 1060 ScopedWifiOptions::~ScopedWifiOptions() { |
1044 } | 1061 } |
1045 | 1062 |
1046 } // namespace net | 1063 } // namespace net |
OLD | NEW |