blob: d963efd6ef4b92c38798be37f138db365fb1e624 [file] [log] [blame]
Guo-wei Shieh9faf1542015-12-28 22:06:551/*
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 04:47:3111#include "rtc_base/ifaddrs_converter.h"
Guo-wei Shieh9faf1542015-12-28 22:06:5512
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: {
Taylor Brandstetter01cb5f22018-03-07 23:49:3225 *ip = InterfaceAddress(IPAddress(
26 reinterpret_cast<sockaddr_in*>(interface->ifa_addr)->sin_addr));
Guo-wei Shieh9faf1542015-12-28 22:06:5527 *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 }
Jonas Olssona4d87372019-07-05 17:08:3343 default: {
44 return false;
45 }
Guo-wei Shieh9faf1542015-12-28 22:06:5546 }
47}
48
49bool IfAddrsConverter::ConvertNativeAttributesToIPAttributes(
50 const struct ifaddrs* interface,
51 int* ip_attributes) {
52 *ip_attributes = IPV6_ADDRESS_FLAG_NONE;
53 return true;
54}
55
56#if !defined(WEBRTC_MAC)
57// For MAC and IOS, it's defined in macifaddrs_converter.cc
58IfAddrsConverter* CreateIfAddrsConverter() {
59 return new IfAddrsConverter();
60}
61#endif
62} // namespace rtc