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 #ifndef NET_BASE_NET_UTIL_H_ | 5 #ifndef NET_BASE_NET_UTIL_H_ |
6 #define NET_BASE_NET_UTIL_H_ | 6 #define NET_BASE_NET_UTIL_H_ |
7 | 7 |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 | 9 |
10 #if defined(OS_WIN) | 10 #if defined(OS_WIN) |
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
507 // Returns true if |host| is one of the names (e.g. "localhost") or IP | 507 // Returns true if |host| is one of the names (e.g. "localhost") or IP |
508 // addresses (IPv4 127.0.0.0/8 or IPv6 ::1) that indicate a loopback. | 508 // addresses (IPv4 127.0.0.0/8 or IPv6 ::1) that indicate a loopback. |
509 // | 509 // |
510 // Note that this function does not check for IP addresses other than | 510 // Note that this function does not check for IP addresses other than |
511 // the above, although other IP addresses may point to the local | 511 // the above, although other IP addresses may point to the local |
512 // machine. | 512 // machine. |
513 NET_EXPORT_PRIVATE bool IsLocalhost(const std::string& host); | 513 NET_EXPORT_PRIVATE bool IsLocalhost(const std::string& host); |
514 | 514 |
515 // struct that is used by GetNetworkList() to represent a network | 515 // struct that is used by GetNetworkList() to represent a network |
516 // interface. | 516 // interface. |
517 | |
518 #if defined(OS_ANDROID) | |
519 | |
517 struct NET_EXPORT NetworkInterface { | 520 struct NET_EXPORT NetworkInterface { |
518 NetworkInterface(); | 521 NetworkInterface(); |
519 NetworkInterface(const std::string& name, const IPAddressNumber& address); | 522 NetworkInterface(const std::string& name, |
523 const IPAddressNumber& address); | |
520 ~NetworkInterface(); | 524 ~NetworkInterface(); |
521 | 525 |
522 std::string name; | 526 std::string name; |
523 IPAddressNumber address; | 527 IPAddressNumber address; |
528 // network_prefix on Android is not easily accessible. | |
szym
2013/09/19 23:21:01
Why not? This is easily done with ioctl SIOCGIFNET
szym
2013/09/20 19:30:15
While the ioctl is forbidden (because it would byp
| |
524 }; | 529 }; |
525 | 530 |
531 #else // OS_ANDROID | |
532 | |
533 struct NET_EXPORT NetworkInterface { | |
534 NetworkInterface(); | |
535 NetworkInterface(const std::string& name, | |
536 const IPAddressNumber& address, | |
537 uint8 network_prefix); | |
538 ~NetworkInterface(); | |
539 | |
540 std::string name; | |
541 IPAddressNumber address; | |
542 uint8 network_prefix; | |
543 }; | |
544 | |
545 #endif // OS_ANDROID | |
546 | |
526 typedef std::vector<NetworkInterface> NetworkInterfaceList; | 547 typedef std::vector<NetworkInterface> NetworkInterfaceList; |
527 | 548 |
528 // Returns list of network interfaces except loopback interface. If an | 549 // Returns list of network interfaces except loopback interface. If an |
529 // interface has more than one address, a separate entry is added to | 550 // interface has more than one address, a separate entry is added to |
530 // the list for each address. | 551 // the list for each address. |
531 // Can be called only on a thread that allows IO. | 552 // Can be called only on a thread that allows IO. |
532 NET_EXPORT bool GetNetworkList(NetworkInterfaceList* networks); | 553 NET_EXPORT bool GetNetworkList(NetworkInterfaceList* networks); |
533 | 554 |
534 // General category of the IEEE 802.11 (wifi) physical layer operating mode. | 555 // General category of the IEEE 802.11 (wifi) physical layer operating mode. |
535 enum WifiPHYLayerProtocol { | 556 enum WifiPHYLayerProtocol { |
(...skipping 10 matching lines...) Expand all Loading... | |
546 // 802.11n, HT rates. | 567 // 802.11n, HT rates. |
547 WIFI_PHY_LAYER_PROTOCOL_N, | 568 WIFI_PHY_LAYER_PROTOCOL_N, |
548 // Unclassified mode or failure to identify. | 569 // Unclassified mode or failure to identify. |
549 WIFI_PHY_LAYER_PROTOCOL_UNKNOWN | 570 WIFI_PHY_LAYER_PROTOCOL_UNKNOWN |
550 }; | 571 }; |
551 | 572 |
552 // Characterize the PHY mode of the currently associated access point. | 573 // Characterize the PHY mode of the currently associated access point. |
553 // Currently only available on OS_WIN. | 574 // Currently only available on OS_WIN. |
554 NET_EXPORT WifiPHYLayerProtocol GetWifiPHYLayerProtocol(); | 575 NET_EXPORT WifiPHYLayerProtocol GetWifiPHYLayerProtocol(); |
555 | 576 |
577 // Returns number of matching initial bits between the addresses |a1| and |a2|. | |
578 unsigned CommonPrefixLength(const IPAddressNumber& a1, | |
579 const IPAddressNumber& a2); | |
580 | |
581 // Computes the number of leading 1-bits in |mask|. | |
582 unsigned MaskPrefixLength(const IPAddressNumber& mask); | |
583 | |
556 } // namespace net | 584 } // namespace net |
557 | 585 |
558 #endif // NET_BASE_NET_UTIL_H_ | 586 #endif // NET_BASE_NET_UTIL_H_ |
OLD | NEW |