| 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..6a9f678fb245e9a6982cdfa90d069bb20b74ac2a 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,32 @@ 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;
|
| + }
|
| +
|
| + close(s);
|
| + return type;
|
| +}
|
| +
|
| bool GetNetworkListImpl(
|
| NetworkInterfaceList* networks,
|
| int policy,
|
| @@ -112,7 +139,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 +155,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 +175,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
|
|
|