OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/p2p/ipc_network_manager.h" | 5 #include "content/renderer/p2p/ipc_network_manager.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/sys_byteorder.h" | 8 #include "base/sys_byteorder.h" |
9 #include "net/base/net_util.h" | 9 #include "net/base/net_util.h" |
10 | 10 |
(...skipping 28 matching lines...) Expand all Loading... |
39 --start_count_; | 39 --start_count_; |
40 } | 40 } |
41 | 41 |
42 void IpcNetworkManager::OnNetworkListChanged( | 42 void IpcNetworkManager::OnNetworkListChanged( |
43 const net::NetworkInterfaceList& list) { | 43 const net::NetworkInterfaceList& list) { |
44 | 44 |
45 // Update flag if network list received for the first time. | 45 // Update flag if network list received for the first time. |
46 if (!network_list_received_) | 46 if (!network_list_received_) |
47 network_list_received_ = true; | 47 network_list_received_ = true; |
48 | 48 |
| 49 // Note: 32 and 64 are the arbitrary(kind of) prefix length used to |
| 50 // differentiate IPv4 and IPv6 addresses. |
| 51 // talk_base::Network uses these prefix_length to compare network |
| 52 // interfaces discovered. |
49 std::vector<talk_base::Network*> networks; | 53 std::vector<talk_base::Network*> networks; |
50 for (net::NetworkInterfaceList::const_iterator it = list.begin(); | 54 for (net::NetworkInterfaceList::const_iterator it = list.begin(); |
51 it != list.end(); it++) { | 55 it != list.end(); it++) { |
52 uint32 address; | 56 if (it->address.size() == net::kIPv4AddressSize) { |
53 if (it->address.size() != net::kIPv4AddressSize) | 57 uint32 address; |
54 continue; | 58 memcpy(&address, &it->address[0], sizeof(uint32)); |
55 memcpy(&address, &it->address[0], sizeof(uint32)); | 59 address = talk_base::NetworkToHost32(address); |
56 address = talk_base::NetworkToHost32(address); | 60 talk_base::Network* network = new talk_base::Network( |
57 talk_base::Network* network = new talk_base::Network( | 61 it->name, it->name, talk_base::IPAddress(address), 32); |
58 it->name, it->name, talk_base::IPAddress(address), 32); | 62 network->AddIP(talk_base::IPAddress(address)); |
59 network->AddIP(talk_base::IPAddress(address)); | 63 networks.push_back(network); |
60 networks.push_back(network); | 64 } else if (it->address.size() == net::kIPv6AddressSize) { |
| 65 in6_addr address; |
| 66 memcpy(&address, &it->address[0], sizeof(in6_addr)); |
| 67 talk_base::IPAddress ip6_addr(address); |
| 68 if (!talk_base::IPIsPrivate(ip6_addr)) { |
| 69 talk_base::Network* network = new talk_base::Network( |
| 70 it->name, it->name, ip6_addr, 64); |
| 71 network->AddIP(ip6_addr); |
| 72 networks.push_back(network); |
| 73 } |
| 74 } |
61 } | 75 } |
62 | 76 |
63 bool changed = false; | 77 bool changed = false; |
64 MergeNetworkList(networks, &changed); | 78 MergeNetworkList(networks, &changed); |
65 if (changed) | 79 if (changed) |
66 SignalNetworksChanged(); | 80 SignalNetworksChanged(); |
67 } | 81 } |
68 | 82 |
69 void IpcNetworkManager::SendNetworksChangedSignal() { | 83 void IpcNetworkManager::SendNetworksChangedSignal() { |
70 SignalNetworksChanged(); | 84 SignalNetworksChanged(); |
71 } | 85 } |
72 | 86 |
73 } // namespace content | 87 } // namespace content |
OLD | NEW |