| 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..d12ebeb583d868da5a3bb400b94c8148fd598d7a 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,48 @@ inline const unsigned char* GetIPAddressData(const IPAddressNumber& ip) {
|
| #endif
|
| }
|
|
|
| +char* GetInterfaceName(unsigned int interface_index, char* buf) {
|
| + memset(buf, 0, IFNAMSIZ);
|
| + int ioctl_socket = socket(AF_INET, SOCK_DGRAM, 0);
|
| + if (ioctl_socket < 0)
|
| + return buf;
|
| +
|
| + static struct ifreq ifr;
|
| + memset(&ifr, 0, sizeof(ifr));
|
| + ifr.ifr_ifindex = interface_index;
|
| + int rv = ioctl(ioctl_socket, SIOCGIFNAME, &ifr);
|
| + close(ioctl_socket);
|
| + if (rv != 0)
|
| + return buf;
|
| +
|
| + strncpy(buf, ifr.ifr_name, IFNAMSIZ - 1);
|
| + return buf;
|
| +}
|
| +
|
| +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 +155,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 +171,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 +191,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::GetInterfaceName);
|
| }
|
|
|
| } // namespace net
|
|
|