| Index: webrtc/base/network.cc
|
| diff --git a/webrtc/base/network.cc b/webrtc/base/network.cc
|
| index 678541d0b11025b0d8e17023828cc479c000026b..7519253d08fa37776f2489778f3765c08939c8b5 100644
|
| --- a/webrtc/base/network.cc
|
| +++ b/webrtc/base/network.cc
|
| @@ -13,6 +13,7 @@
|
| #endif
|
|
|
| #include "webrtc/base/network.h"
|
| +#include "webrtc/base/logging.h"
|
|
|
| #if defined(WEBRTC_POSIX)
|
| // linux/if.h can't be included at the same time as the posix sys/if.h, and
|
| @@ -24,23 +25,13 @@
|
| #elif !defined(__native_client__)
|
| #include <net/if.h>
|
| #endif
|
| -#include <sys/socket.h>
|
| -#include <sys/utsname.h>
|
| -#include <sys/ioctl.h>
|
| -#include <unistd.h>
|
| -#include <errno.h>
|
| -
|
| -#if defined(WEBRTC_ANDROID)
|
| -#include "webrtc/base/ifaddrs-android.h"
|
| -#elif !defined(__native_client__)
|
| -#include <ifaddrs.h>
|
| -#endif
|
| -
|
| #endif // WEBRTC_POSIX
|
|
|
| #if defined(WEBRTC_WIN)
|
| #include "webrtc/base/win32.h"
|
| #include <Iphlpapi.h>
|
| +#else
|
| +#include "webrtc/base/ifaddrs_converter.h"
|
| #endif
|
|
|
| #include <stdio.h>
|
| @@ -129,7 +120,7 @@ std::string AdapterTypeToString(AdapterType type) {
|
| }
|
| }
|
|
|
| -bool IsIgnoredIPv6(const IPAddress& ip) {
|
| +bool IsIgnoredIPv6(const InterfaceAddress& ip) {
|
| if (ip.family() != AF_INET6) {
|
| return false;
|
| }
|
| @@ -146,6 +137,11 @@ bool IsIgnoredIPv6(const IPAddress& ip) {
|
| return true;
|
| }
|
|
|
| + // Ignore deprecated IPv6.
|
| + if (ip.ipv6_flags() & IPV6_ADDRESS_FLAG_DEPRECATED) {
|
| + return true;
|
| + }
|
| +
|
| return false;
|
| }
|
|
|
| @@ -383,46 +379,45 @@ void BasicNetworkManager::ConvertIfAddrs(struct ifaddrs* interfaces,
|
| bool include_ignored,
|
| NetworkList* networks) const {
|
| NetworkMap current_networks;
|
| + rtc::scoped_ptr<IfAddrsConverter> ifaddrs_converter(
|
| + CreateIfAddrsConverter());
|
| +
|
| for (struct ifaddrs* cursor = interfaces;
|
| cursor != NULL; cursor = cursor->ifa_next) {
|
| IPAddress prefix;
|
| IPAddress mask;
|
| - IPAddress ip;
|
| + InterfaceAddress ip;
|
| int scope_id = 0;
|
|
|
| // Some interfaces may not have address assigned.
|
| - if (!cursor->ifa_addr || !cursor->ifa_netmask)
|
| + if (!cursor->ifa_addr || !cursor->ifa_netmask) {
|
| continue;
|
| + }
|
| + // Skip ones which are down.
|
| + if (!(IFF_RUNNING & cursor->ifa_flags)) {
|
| + continue;
|
| + }
|
| + // Skip unknown family.
|
| + if (cursor->ifa_addr->sa_family != AF_INET &&
|
| + cursor->ifa_addr->sa_family != AF_INET6) {
|
| + continue;
|
| + }
|
| + // Skip IPv6 if not enabled.
|
| + if (cursor->ifa_addr->sa_family == AF_INET6 && !ipv6_enabled()) {
|
| + continue;
|
| + }
|
| + // Convert to InterfaceAddress.
|
| + if (!ifaddrs_converter->Convert(cursor, &ip, &mask)) {
|
| + continue;
|
| + }
|
|
|
| - switch (cursor->ifa_addr->sa_family) {
|
| - case AF_INET: {
|
| - ip = IPAddress(
|
| - reinterpret_cast<sockaddr_in*>(cursor->ifa_addr)->sin_addr);
|
| - mask = IPAddress(
|
| - reinterpret_cast<sockaddr_in*>(cursor->ifa_netmask)->sin_addr);
|
| - break;
|
| - }
|
| - case AF_INET6: {
|
| - if (ipv6_enabled()) {
|
| - ip = IPAddress(
|
| - reinterpret_cast<sockaddr_in6*>(cursor->ifa_addr)->sin6_addr);
|
| -
|
| - if (IsIgnoredIPv6(ip)) {
|
| - continue;
|
| - }
|
| -
|
| - mask = IPAddress(
|
| - reinterpret_cast<sockaddr_in6*>(cursor->ifa_netmask)->sin6_addr);
|
| - scope_id =
|
| - reinterpret_cast<sockaddr_in6*>(cursor->ifa_addr)->sin6_scope_id;
|
| - break;
|
| - } else {
|
| - continue;
|
| - }
|
| - }
|
| - default: {
|
| + // Special case for IPv6 address.
|
| + if (cursor->ifa_addr->sa_family == AF_INET6) {
|
| + if (IsIgnoredIPv6(ip)) {
|
| continue;
|
| }
|
| + scope_id =
|
| + reinterpret_cast<sockaddr_in6*>(cursor->ifa_addr)->sin6_scope_id;
|
| }
|
|
|
| int prefix_length = CountIPMaskBits(mask);
|
|
|