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 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 return port >= 0 && port <= std::numeric_limits<uint16>::max(); | 299 return port >= 0 && port <= std::numeric_limits<uint16>::max(); |
300 } | 300 } |
301 | 301 |
302 bool IsPortAllowedByDefault(int port) { | 302 bool IsPortAllowedByDefault(int port) { |
303 int array_size = arraysize(kRestrictedPorts); | 303 int array_size = arraysize(kRestrictedPorts); |
304 for (int i = 0; i < array_size; i++) { | 304 for (int i = 0; i < array_size; i++) { |
305 if (kRestrictedPorts[i] == port) { | 305 if (kRestrictedPorts[i] == port) { |
306 return false; | 306 return false; |
307 } | 307 } |
308 } | 308 } |
309 return true; | 309 return IsPortValid(port); |
310 } | 310 } |
311 | 311 |
312 bool IsPortAllowedByFtp(int port) { | 312 bool IsPortAllowedByFtp(int port) { |
313 int array_size = arraysize(kAllowedFtpPorts); | 313 int array_size = arraysize(kAllowedFtpPorts); |
314 for (int i = 0; i < array_size; i++) { | 314 for (int i = 0; i < array_size; i++) { |
315 if (kAllowedFtpPorts[i] == port) { | 315 if (kAllowedFtpPorts[i] == port) { |
316 return true; | 316 return true; |
317 } | 317 } |
318 } | 318 } |
319 // Port not explicitly allowed by FTP, so return the default restrictions. | 319 // Port not explicitly allowed by FTP, so return the default restrictions. |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 | 566 |
567 #if defined(OS_WIN) | 567 #if defined(OS_WIN) |
568 if (sock_addr->sa_family == AF_BTH) { | 568 if (sock_addr->sa_family == AF_BTH) { |
569 if (sock_addr_len < static_cast<socklen_t>(sizeof(SOCKADDR_BTH))) | 569 if (sock_addr_len < static_cast<socklen_t>(sizeof(SOCKADDR_BTH))) |
570 return false; | 570 return false; |
571 const SOCKADDR_BTH* addr = | 571 const SOCKADDR_BTH* addr = |
572 reinterpret_cast<const SOCKADDR_BTH*>(sock_addr); | 572 reinterpret_cast<const SOCKADDR_BTH*>(sock_addr); |
573 *address = reinterpret_cast<const uint8*>(&addr->btAddr); | 573 *address = reinterpret_cast<const uint8*>(&addr->btAddr); |
574 *address_len = kBluetoothAddressSize; | 574 *address_len = kBluetoothAddressSize; |
575 if (port) | 575 if (port) |
576 *port = addr->port; | 576 *port = static_cast<uint16>(addr->port); |
577 return true; | 577 return true; |
578 } | 578 } |
579 #endif | 579 #endif |
580 | 580 |
581 return false; // Unrecognized |sa_family|. | 581 return false; // Unrecognized |sa_family|. |
582 } | 582 } |
583 | 583 |
584 std::string IPAddressToString(const uint8* address, | 584 std::string IPAddressToString(const uint8* address, |
585 size_t address_len) { | 585 size_t address_len) { |
586 std::string str; | 586 std::string str; |
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1008 | 1008 |
1009 default: | 1009 default: |
1010 NOTREACHED(); | 1010 NOTREACHED(); |
1011 } | 1011 } |
1012 } | 1012 } |
1013 | 1013 |
1014 return false; | 1014 return false; |
1015 } | 1015 } |
1016 | 1016 |
1017 NetworkInterface::NetworkInterface() | 1017 NetworkInterface::NetworkInterface() |
1018 : type(NetworkChangeNotifier::CONNECTION_UNKNOWN), | 1018 : type(NetworkChangeNotifier::CONNECTION_UNKNOWN), prefix_length(0) { |
1019 network_prefix(0) { | |
1020 } | 1019 } |
1021 | 1020 |
1022 NetworkInterface::NetworkInterface(const std::string& name, | 1021 NetworkInterface::NetworkInterface(const std::string& name, |
1023 const std::string& friendly_name, | 1022 const std::string& friendly_name, |
1024 uint32 interface_index, | 1023 uint32 interface_index, |
1025 NetworkChangeNotifier::ConnectionType type, | 1024 NetworkChangeNotifier::ConnectionType type, |
1026 const IPAddressNumber& address, | 1025 const IPAddressNumber& address, |
1027 uint32 network_prefix, | 1026 uint32 prefix_length, |
1028 int ip_address_attributes) | 1027 int ip_address_attributes) |
1029 : name(name), | 1028 : name(name), |
1030 friendly_name(friendly_name), | 1029 friendly_name(friendly_name), |
1031 interface_index(interface_index), | 1030 interface_index(interface_index), |
1032 type(type), | 1031 type(type), |
1033 address(address), | 1032 address(address), |
1034 network_prefix(network_prefix), | 1033 prefix_length(prefix_length), |
1035 ip_address_attributes(ip_address_attributes) { | 1034 ip_address_attributes(ip_address_attributes) { |
1036 } | 1035 } |
1037 | 1036 |
1038 NetworkInterface::~NetworkInterface() { | 1037 NetworkInterface::~NetworkInterface() { |
1039 } | 1038 } |
1040 | 1039 |
1041 unsigned CommonPrefixLength(const IPAddressNumber& a1, | 1040 unsigned CommonPrefixLength(const IPAddressNumber& a1, |
1042 const IPAddressNumber& a2) { | 1041 const IPAddressNumber& a2) { |
1043 DCHECK_EQ(a1.size(), a2.size()); | 1042 DCHECK_EQ(a1.size(), a2.size()); |
1044 for (size_t i = 0; i < a1.size(); ++i) { | 1043 for (size_t i = 0; i < a1.size(); ++i) { |
(...skipping 12 matching lines...) Expand all Loading... |
1057 | 1056 |
1058 unsigned MaskPrefixLength(const IPAddressNumber& mask) { | 1057 unsigned MaskPrefixLength(const IPAddressNumber& mask) { |
1059 IPAddressNumber all_ones(mask.size(), 0xFF); | 1058 IPAddressNumber all_ones(mask.size(), 0xFF); |
1060 return CommonPrefixLength(mask, all_ones); | 1059 return CommonPrefixLength(mask, all_ones); |
1061 } | 1060 } |
1062 | 1061 |
1063 ScopedWifiOptions::~ScopedWifiOptions() { | 1062 ScopedWifiOptions::~ScopedWifiOptions() { |
1064 } | 1063 } |
1065 | 1064 |
1066 } // namespace net | 1065 } // namespace net |
OLD | NEW |