OLD | NEW |
---|---|
(Empty) | |
1 /* | |
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 | |
11 #include "webrtc/base/ifaddrs_converter.h" | |
12 | |
13 #include "webrtc/base/logging.h" | |
14 | |
15 namespace rtc { | |
16 | |
17 IfAddrsConverter::IfAddrsConverter() {} | |
18 | |
19 IfAddrsConverter::~IfAddrsConverter() {} | |
20 | |
21 bool IfAddrsConverter::Convert(const struct ifaddrs* interface, | |
22 InterfaceAddress* ip, | |
23 IPAddress* mask) { | |
24 switch (interface->ifa_addr->sa_family) { | |
25 case AF_INET: { | |
26 *ip = IPAddress( | |
27 reinterpret_cast<sockaddr_in*>(interface->ifa_addr)->sin_addr); | |
28 *mask = IPAddress( | |
29 reinterpret_cast<sockaddr_in*>(interface->ifa_netmask)->sin_addr); | |
30 return true; | |
31 } | |
32 case AF_INET6: { | |
33 int ip_attributes = IPV6_ADDRESS_FLAG_NONE; | |
34 if (!ConvertNativeToIPAttributes(interface, &ip_attributes)) { | |
35 return false; | |
36 } | |
37 *ip = InterfaceAddress( | |
38 reinterpret_cast<sockaddr_in6*>(interface->ifa_addr)->sin6_addr, | |
39 ip_attributes); | |
40 *mask = IPAddress( | |
41 reinterpret_cast<sockaddr_in6*>(interface->ifa_netmask)->sin6_addr); | |
42 LOG(LS_ERROR) << "IPv6 " << ip->ToString(); | |
pthatcher1
2015/12/18 19:51:20
Was this just a debugging statement that you shoul
guoweis_webrtc
2015/12/21 20:26:33
Sorry, missed this one.
| |
43 return true; | |
44 } | |
45 default: { return false; } | |
46 } | |
47 } | |
48 | |
49 bool IfAddrsConverter::ConvertNativeToIPAttributes( | |
pthatcher1
2015/12/18 19:51:20
What is "native" in this context? Should this be
guoweis_webrtc
2015/12/21 20:26:33
I meant by native attributes. They have their own
pthatcher1
2015/12/21 22:18:32
Then should it be named ConvertNativeAttributesToI
| |
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) | |
pthatcher1
2015/12/18 19:51:20
Can you leave a comment about what happens for mac
guoweis_webrtc
2015/12/21 20:26:33
Done.
| |
57 IfAddrsConverter* CreateIfAddrsConverter() { | |
58 return new IfAddrsConverter(); | |
59 } | |
60 #endif | |
61 } // namespace rtc | |
OLD | NEW |