webrtc_m130/webrtc/base/ifaddrs_converter.cc
Guo-wei Shieh 9faf154960 Reland 1531763006
Enable IPv6 temporary address filtering on iOS.

We'll only use temporary address for IPv6. However, due to a bug in iOS sdk, the necessary headers are not included. This change copies the minimum necessary definitions such that we could retrieve the ip attributes.

BUG=webrtc:4343

Committed: https://crrev.com/29488c23644721c10a45eba74c67602b0262e582
Cr-Commit-Position: refs/heads/master@{#11114}

patch from issue 1531763006 at patchset 200001 (http://crrev.com/1531763006#ps200001)

TBR=pthatcher@webrtc.org

Review URL: https://codereview.webrtc.org/1551703002 .

Cr-Commit-Position: refs/heads/master@{#11133}
2015-12-28 22:07:05 +00:00

61 lines
1.8 KiB
C++

/*
* Copyright 2015 The WebRTC Project Authors. All rights reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/base/ifaddrs_converter.h"
namespace rtc {
IfAddrsConverter::IfAddrsConverter() {}
IfAddrsConverter::~IfAddrsConverter() {}
bool IfAddrsConverter::ConvertIfAddrsToIPAddress(
const struct ifaddrs* interface,
InterfaceAddress* ip,
IPAddress* mask) {
switch (interface->ifa_addr->sa_family) {
case AF_INET: {
*ip = IPAddress(
reinterpret_cast<sockaddr_in*>(interface->ifa_addr)->sin_addr);
*mask = IPAddress(
reinterpret_cast<sockaddr_in*>(interface->ifa_netmask)->sin_addr);
return true;
}
case AF_INET6: {
int ip_attributes = IPV6_ADDRESS_FLAG_NONE;
if (!ConvertNativeAttributesToIPAttributes(interface, &ip_attributes)) {
return false;
}
*ip = InterfaceAddress(
reinterpret_cast<sockaddr_in6*>(interface->ifa_addr)->sin6_addr,
ip_attributes);
*mask = IPAddress(
reinterpret_cast<sockaddr_in6*>(interface->ifa_netmask)->sin6_addr);
return true;
}
default: { return false; }
}
}
bool IfAddrsConverter::ConvertNativeAttributesToIPAttributes(
const struct ifaddrs* interface,
int* ip_attributes) {
*ip_attributes = IPV6_ADDRESS_FLAG_NONE;
return true;
}
#if !defined(WEBRTC_MAC)
// For MAC and IOS, it's defined in macifaddrs_converter.cc
IfAddrsConverter* CreateIfAddrsConverter() {
return new IfAddrsConverter();
}
#endif
} // namespace rtc