blob: 2db99efd6c953939c090456ff945f156e52f13f0 [file] [log] [blame]
Guo-wei Shieh9faf1542015-12-28 14:06:55 -08001/*
2 * Copyright 2015 The WebRTC Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "rtc_base/ifaddrs_converter.h"
Guo-wei Shieh9faf1542015-12-28 14:06:55 -080012
13namespace rtc {
14
15IfAddrsConverter::IfAddrsConverter() {}
16
17IfAddrsConverter::~IfAddrsConverter() {}
18
19bool IfAddrsConverter::ConvertIfAddrsToIPAddress(
20 const struct ifaddrs* interface,
21 InterfaceAddress* ip,
22 IPAddress* mask) {
23 switch (interface->ifa_addr->sa_family) {
24 case AF_INET: {
25 *ip = IPAddress(
26 reinterpret_cast<sockaddr_in*>(interface->ifa_addr)->sin_addr);
27 *mask = IPAddress(
28 reinterpret_cast<sockaddr_in*>(interface->ifa_netmask)->sin_addr);
29 return true;
30 }
31 case AF_INET6: {
32 int ip_attributes = IPV6_ADDRESS_FLAG_NONE;
33 if (!ConvertNativeAttributesToIPAttributes(interface, &ip_attributes)) {
34 return false;
35 }
36 *ip = InterfaceAddress(
37 reinterpret_cast<sockaddr_in6*>(interface->ifa_addr)->sin6_addr,
38 ip_attributes);
39 *mask = IPAddress(
40 reinterpret_cast<sockaddr_in6*>(interface->ifa_netmask)->sin6_addr);
41 return true;
42 }
43 default: { return false; }
44 }
45}
46
47bool IfAddrsConverter::ConvertNativeAttributesToIPAttributes(
48 const struct ifaddrs* interface,
49 int* ip_attributes) {
50 *ip_attributes = IPV6_ADDRESS_FLAG_NONE;
51 return true;
52}
53
54#if !defined(WEBRTC_MAC)
55// For MAC and IOS, it's defined in macifaddrs_converter.cc
56IfAddrsConverter* CreateIfAddrsConverter() {
57 return new IfAddrsConverter();
58}
59#endif
60} // namespace rtc