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
3 // found in the LICENSE file.
5 #ifndef NET_BASE_NETWORK_INTERFACES_H_
6 #define NET_BASE_NETWORK_INTERFACES_H_
8 #include "build/build_config.h"
13 #elif defined(OS_POSIX)
14 #include <sys/types.h>
15 #include <sys/socket.h>
21 #include "base/basictypes.h"
22 #include "base/strings/string16.h"
23 #include "base/strings/utf_offset_string_conversions.h"
24 #include "net/base/address_family.h"
25 #include "net/base/escape.h"
26 #include "net/base/ip_address_number.h"
27 #include "net/base/net_export.h"
28 #include "net/base/network_change_notifier.h"
43 // struct that is used by GetNetworkList() to represent a network
45 struct NET_EXPORT NetworkInterface
{
47 NetworkInterface(const std::string
& name
,
48 const std::string
& friendly_name
,
49 uint32_t interface_index
,
50 NetworkChangeNotifier::ConnectionType type
,
51 const IPAddressNumber
& address
,
52 uint32_t prefix_length
,
53 int ip_address_attributes
);
57 std::string friendly_name
; // Same as |name| on non-Windows.
58 uint32_t interface_index
; // Always 0 on Android.
59 NetworkChangeNotifier::ConnectionType type
;
60 IPAddressNumber address
;
61 uint32_t prefix_length
;
62 int ip_address_attributes
; // Combination of |IPAddressAttributes|.
65 typedef std::vector
<NetworkInterface
> NetworkInterfaceList
;
67 // Policy settings to include/exclude network interfaces.
68 enum HostAddressSelectionPolicy
{
69 INCLUDE_HOST_SCOPE_VIRTUAL_INTERFACES
= 0x0,
70 EXCLUDE_HOST_SCOPE_VIRTUAL_INTERFACES
= 0x1,
73 // Returns list of network interfaces except loopback interface. If an
74 // interface has more than one address, a separate entry is added to
75 // the list for each address.
76 // Can be called only on a thread that allows IO.
77 NET_EXPORT
bool GetNetworkList(NetworkInterfaceList
* networks
,
80 // Gets the SSID of the currently associated WiFi access point if there is one.
81 // Otherwise, returns empty string.
82 // Currently only implemented on Linux, ChromeOS, Android and Windows.
83 NET_EXPORT
std::string
GetWifiSSID();
85 // General category of the IEEE 802.11 (wifi) physical layer operating mode.
86 enum WifiPHYLayerProtocol
{
87 // No wifi support or no associated AP.
88 WIFI_PHY_LAYER_PROTOCOL_NONE
,
89 // An obsolete modes introduced by the original 802.11, e.g. IR, FHSS.
90 WIFI_PHY_LAYER_PROTOCOL_ANCIENT
,
91 // 802.11a, OFDM-based rates.
92 WIFI_PHY_LAYER_PROTOCOL_A
,
93 // 802.11b, DSSS or HR DSSS.
94 WIFI_PHY_LAYER_PROTOCOL_B
,
95 // 802.11g, same rates as 802.11a but compatible with 802.11b.
96 WIFI_PHY_LAYER_PROTOCOL_G
,
98 WIFI_PHY_LAYER_PROTOCOL_N
,
99 // Unclassified mode or failure to identify.
100 WIFI_PHY_LAYER_PROTOCOL_UNKNOWN
103 // Characterize the PHY mode of the currently associated access point.
104 // Currently only available on Windows.
105 NET_EXPORT WifiPHYLayerProtocol
GetWifiPHYLayerProtocol();
108 // Disables background SSID scans.
109 WIFI_OPTIONS_DISABLE_SCAN
= 1 << 0,
110 // Enables media streaming mode.
111 WIFI_OPTIONS_MEDIA_STREAMING_MODE
= 1 << 1
114 class NET_EXPORT ScopedWifiOptions
{
116 ScopedWifiOptions() {}
117 virtual ~ScopedWifiOptions();
120 DISALLOW_COPY_AND_ASSIGN(ScopedWifiOptions
);
123 // Set temporary options on all wifi interfaces.
124 // |options| is an ORed bitfield of WifiOptions.
125 // Options are automatically disabled when the scoped pointer
126 // is freed. Currently only available on Windows.
127 NET_EXPORT scoped_ptr
<ScopedWifiOptions
> SetWifiOptions(int options
);
131 #endif // NET_BASE_NETWORK_INTERFACES_H_