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 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
294 return StripWWW(base::ASCIIToUTF16(url.host())); | 294 return StripWWW(base::ASCIIToUTF16(url.host())); |
295 } | 295 } |
296 | 296 |
297 bool IsPortAllowedByDefault(int port) { | 297 bool IsPortAllowedByDefault(int port) { |
298 int array_size = arraysize(kRestrictedPorts); | 298 int array_size = arraysize(kRestrictedPorts); |
299 for (int i = 0; i < array_size; i++) { | 299 for (int i = 0; i < array_size; i++) { |
300 if (kRestrictedPorts[i] == port) { | 300 if (kRestrictedPorts[i] == port) { |
301 return false; | 301 return false; |
302 } | 302 } |
303 } | 303 } |
304 return true; | 304 return port >= 0 && port <= 65535; |
Peter Kasting
2014/11/12 23:54:31
This ensures it's safe to cast the port number to
mmenke
2014/11/13 16:00:42
Not a big fan of depending on this for correctness
| |
305 } | 305 } |
306 | 306 |
307 bool IsPortAllowedByFtp(int port) { | 307 bool IsPortAllowedByFtp(int port) { |
308 int array_size = arraysize(kAllowedFtpPorts); | 308 int array_size = arraysize(kAllowedFtpPorts); |
309 for (int i = 0; i < array_size; i++) { | 309 for (int i = 0; i < array_size; i++) { |
310 if (kAllowedFtpPorts[i] == port) { | 310 if (kAllowedFtpPorts[i] == port) { |
311 return true; | 311 return true; |
312 } | 312 } |
313 } | 313 } |
314 // Port not explicitly allowed by FTP, so return the default restrictions. | 314 // Port not explicitly allowed by FTP, so return the default restrictions. |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
561 | 561 |
562 #if defined(OS_WIN) | 562 #if defined(OS_WIN) |
563 if (sock_addr->sa_family == AF_BTH) { | 563 if (sock_addr->sa_family == AF_BTH) { |
564 if (sock_addr_len < static_cast<socklen_t>(sizeof(SOCKADDR_BTH))) | 564 if (sock_addr_len < static_cast<socklen_t>(sizeof(SOCKADDR_BTH))) |
565 return false; | 565 return false; |
566 const SOCKADDR_BTH* addr = | 566 const SOCKADDR_BTH* addr = |
567 reinterpret_cast<const SOCKADDR_BTH*>(sock_addr); | 567 reinterpret_cast<const SOCKADDR_BTH*>(sock_addr); |
568 *address = reinterpret_cast<const uint8*>(&addr->btAddr); | 568 *address = reinterpret_cast<const uint8*>(&addr->btAddr); |
569 *address_len = kBluetoothAddressSize; | 569 *address_len = kBluetoothAddressSize; |
570 if (port) | 570 if (port) |
571 *port = addr->port; | 571 *port = static_cast<uint16>(addr->port); |
572 return true; | 572 return true; |
573 } | 573 } |
574 #endif | 574 #endif |
575 | 575 |
576 return false; // Unrecognized |sa_family|. | 576 return false; // Unrecognized |sa_family|. |
577 } | 577 } |
578 | 578 |
579 std::string IPAddressToString(const uint8* address, | 579 std::string IPAddressToString(const uint8* address, |
580 size_t address_len) { | 580 size_t address_len) { |
581 std::string str; | 581 std::string str; |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1052 | 1052 |
1053 unsigned MaskPrefixLength(const IPAddressNumber& mask) { | 1053 unsigned MaskPrefixLength(const IPAddressNumber& mask) { |
1054 IPAddressNumber all_ones(mask.size(), 0xFF); | 1054 IPAddressNumber all_ones(mask.size(), 0xFF); |
1055 return CommonPrefixLength(mask, all_ones); | 1055 return CommonPrefixLength(mask, all_ones); |
1056 } | 1056 } |
1057 | 1057 |
1058 ScopedWifiOptions::~ScopedWifiOptions() { | 1058 ScopedWifiOptions::~ScopedWifiOptions() { |
1059 } | 1059 } |
1060 | 1060 |
1061 } // namespace net | 1061 } // namespace net |
OLD | NEW |