Chromium Code Reviews| Index: net/base/net_util_linux.cc |
| diff --git a/net/base/net_util_linux.cc b/net/base/net_util_linux.cc |
| index e4e0f7f3277e9110cb944ea0714ea9136f36ea18..fc90e2456b735c75f6cdd6a152d5d5346c0e4add 100644 |
| --- a/net/base/net_util_linux.cc |
| +++ b/net/base/net_util_linux.cc |
| @@ -4,9 +4,10 @@ |
| #include "net/base/net_util_linux.h" |
| -#include <net/if.h> |
| -#include <netinet/in.h> |
| +#include <linux/if.h> |
| +#include <linux/wireless.h> |
| #include <set> |
| +#include <sys/ioctl.h> |
| #include <sys/types.h> |
| #include "base/files/file_path.h" |
| @@ -69,6 +70,31 @@ inline const unsigned char* GetIPAddressData(const IPAddressNumber& ip) { |
| #endif |
| } |
| +// Gets the connection type for interface |ifname| by checking for wireless |
| +// extensions. |
| +NetworkChangeNotifier::ConnectionType GetInterfaceConnectionType( |
| + const std::string& ifname) { |
| + NetworkChangeNotifier::ConnectionType type = |
| + NetworkChangeNotifier::CONNECTION_UNKNOWN; |
| + |
| + int s = socket(AF_INET, SOCK_STREAM, 0); |
| + if (s == -1) |
| + return type; |
| + |
| + struct iwreq pwrq; |
| + memset(&pwrq, 0, sizeof(pwrq)); |
| + strncpy(pwrq.ifr_name, ifname.c_str(), IFNAMSIZ); |
| + |
| + if (ioctl(s, SIOCGIWNAME, &pwrq) != -1) { |
| + type = NetworkChangeNotifier::CONNECTION_WIFI; |
| + } else { |
| + type = NetworkChangeNotifier::CONNECTION_UNKNOWN; |
|
pauljensen
2015/01/27 20:25:17
I think this else clause can be deleted
derekjchow1
2015/01/27 21:50:32
Done.
|
| + } |
| + |
| + close(s); |
| + return type; |
| +} |
| + |
| bool GetNetworkListImpl( |
| NetworkInterfaceList* networks, |
| int policy, |
| @@ -112,7 +138,7 @@ bool GetNetworkListImpl( |
| ifnames.find(it->second.ifa_index); |
| std::string ifname; |
| if (itname == ifnames.end()) { |
| - char buffer[IF_NAMESIZE] = {0}; |
| + char buffer[IFNAMSIZ] = {0}; |
| if (get_interface_name(it->second.ifa_index, buffer)) { |
| ifname = ifnames[it->second.ifa_index] = buffer; |
| } else { |
| @@ -128,9 +154,11 @@ bool GetNetworkListImpl( |
| if (ShouldIgnoreInterface(ifname, policy)) |
| continue; |
| + NetworkChangeNotifier::ConnectionType type = |
| + GetInterfaceConnectionType(ifname); |
| + |
| networks->push_back( |
| - NetworkInterface(ifname, ifname, it->second.ifa_index, |
| - NetworkChangeNotifier::CONNECTION_UNKNOWN, it->first, |
| + NetworkInterface(ifname, ifname, it->second.ifa_index, type, it->first, |
| it->second.ifa_prefixlen, ip_attributes)); |
| } |
| @@ -146,9 +174,9 @@ bool GetNetworkList(NetworkInterfaceList* networks, int policy) { |
| internal::AddressTrackerLinux tracker; |
| tracker.Init(); |
| - return internal::GetNetworkListImpl(networks, policy, |
| - tracker.GetOnlineLinks(), |
| - tracker.GetAddressMap(), &if_indextoname); |
| + return internal::GetNetworkListImpl( |
| + networks, policy, tracker.GetOnlineLinks(), tracker.GetAddressMap(), |
| + &internal::AddressTrackerLinux::GetInterfaceName); |
| } |
| } // namespace net |