diff options
author | mallinath@chromium.org <mallinath@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-02 17:39:31 +0000 |
---|---|---|
committer | mallinath@chromium.org <mallinath@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-02 17:39:31 +0000 |
commit | d59b589f41dbd717e805e4aaaa1255ebef4b1b20 (patch) | |
tree | d1b2a280ce01c00b2938ba196afe761df9a01fd0 /net/base/net_util_posix.cc | |
parent | 353fa4ab0e7f9079f7d20d85382be9dc6ae89e42 (diff) | |
download | chromium_src-d59b589f41dbd717e805e4aaaa1255ebef4b1b20.zip chromium_src-d59b589f41dbd717e805e4aaaa1255ebef4b1b20.tar.gz chromium_src-d59b589f41dbd717e805e4aaaa1255ebef4b1b20.tar.bz2 |
Adding support of network interface type detection for OSX.
BUG=361791
R=pauljensen@chromium.org
Review URL: https://codereview.chromium.org/265813005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@267846 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/net_util_posix.cc')
-rw-r--r-- | net/base/net_util_posix.cc | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/net/base/net_util_posix.cc b/net/base/net_util_posix.cc index 06381f9..315e9ed 100644 --- a/net/base/net_util_posix.cc +++ b/net/base/net_util_posix.cc @@ -25,6 +25,7 @@ #endif #if defined(OS_MACOSX) && !defined(OS_IOS) +#include <net/if_media.h> #include <netinet/in_var.h> #include <sys/ioctl.h> #endif @@ -83,6 +84,34 @@ void RemovePermanentIPv6AddressesWhereTemporaryExists( #endif +#if defined(OS_MACOSX) && !defined(OS_IOS) + +NetworkChangeNotifier::ConnectionType GetNetworkInterfaceType( + int addr_family, const std::string& interface_name) { + NetworkChangeNotifier::ConnectionType type = + NetworkChangeNotifier::CONNECTION_UNKNOWN; + + struct ifmediareq ifmr = {}; + strncpy(ifmr.ifm_name, interface_name.c_str(), sizeof(ifmr.ifm_name) - 1); + + int s = socket(addr_family, SOCK_DGRAM, 0); + if (s == -1) { + return type; + } + + if (ioctl(s, SIOCGIFMEDIA, &ifmr) != -1) { + if (ifmr.ifm_current & IFM_IEEE80211) { + type = NetworkChangeNotifier::CONNECTION_WIFI; + } else if (ifmr.ifm_current & IFM_ETHER) { + type = NetworkChangeNotifier::CONNECTION_ETHERNET; + } + } + close(s); + return type; +} + +#endif + } // namespace bool GetNetworkList(NetworkInterfaceList* networks, int policy) { @@ -183,6 +212,8 @@ bool GetNetworkList(NetworkInterfaceList* networks, int policy) { } NetworkInterfaceInfo network_info; + NetworkChangeNotifier::ConnectionType connection_type = + NetworkChangeNotifier::CONNECTION_UNKNOWN; #if defined(OS_MACOSX) && !defined(OS_IOS) // Check if this is a temporary address. Currently this is only supported // on Mac. @@ -197,6 +228,8 @@ bool GetNetworkList(NetworkInterfaceList* networks, int policy) { network_info.permanent = !(ifr.ifr_ifru.ifru_flags & IN6_IFF_TEMPORARY); } } + + connection_type = GetNetworkInterfaceType(addr->sa_family, name); #endif IPEndPoint address; @@ -214,8 +247,7 @@ bool GetNetworkList(NetworkInterfaceList* networks, int policy) { } network_info.interface = NetworkInterface( name, name, if_nametoindex(name.c_str()), - NetworkChangeNotifier::CONNECTION_UNKNOWN, - address.address(), net_mask); + connection_type, address.address(), net_mask); network_infos.push_back(NetworkInterfaceInfo(network_info)); } |