OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
354 default_local_ipv6_address_ = ipv6; | 354 default_local_ipv6_address_ = ipv6; |
355 } | 355 } |
356 } | 356 } |
357 | 357 |
358 bool NetworkManagerBase::GetDefaultLocalAddress(int family, | 358 bool NetworkManagerBase::GetDefaultLocalAddress(int family, |
359 IPAddress* ipaddr) const { | 359 IPAddress* ipaddr) const { |
360 if (family == AF_INET && !default_local_ipv4_address_.IsNil()) { | 360 if (family == AF_INET && !default_local_ipv4_address_.IsNil()) { |
361 *ipaddr = default_local_ipv4_address_; | 361 *ipaddr = default_local_ipv4_address_; |
362 return true; | 362 return true; |
363 } else if (family == AF_INET6 && !default_local_ipv6_address_.IsNil()) { | 363 } else if (family == AF_INET6 && !default_local_ipv6_address_.IsNil()) { |
364 *ipaddr = default_local_ipv6_address_; | 364 // Using the best IP on the same network as the default IPv6 address |
365 // prevents potential IP leaking. | |
366 Network* network = GetNetworkFromAddress(default_local_ipv6_address_); | |
pthatcher1
2016/03/30 17:25:06
I think this could be a little more clear:
*ipadd
honghaiz3
2016/03/30 18:02:59
Revised. 1. we don't need to assign *ipaddr twice
| |
367 *ipaddr = (network != nullptr) ? network->GetBestIP() | |
pthatcher1
2016/03/30 17:25:06
How do we know that GetBestIP() will return an ipv
honghaiz3
2016/03/30 18:02:59
IPv6 address and IPv4 address will be contained in
| |
368 : default_local_ipv6_address_; | |
365 return true; | 369 return true; |
366 } | 370 } |
367 return false; | 371 return false; |
368 } | 372 } |
369 | 373 |
374 Network* NetworkManagerBase::GetNetworkFromAddress( | |
375 const rtc::IPAddress& ip) const { | |
376 for (Network* network : networks_) { | |
377 const auto& ips = network->GetIPs(); | |
378 if (std::find_if(ips.begin(), ips.end(), | |
379 [ip](const InterfaceAddress& existing_ip) { | |
380 return ip == static_cast<rtc::IPAddress>(existing_ip); | |
381 }) != ips.end()) { | |
382 return network; | |
383 } | |
384 } | |
385 return nullptr; | |
386 } | |
387 | |
370 BasicNetworkManager::BasicNetworkManager() | 388 BasicNetworkManager::BasicNetworkManager() |
371 : thread_(NULL), sent_first_update_(false), start_count_(0), | 389 : thread_(NULL), sent_first_update_(false), start_count_(0), |
372 ignore_non_default_routes_(false) { | 390 ignore_non_default_routes_(false) { |
373 } | 391 } |
374 | 392 |
375 BasicNetworkManager::~BasicNetworkManager() { | 393 BasicNetworkManager::~BasicNetworkManager() { |
376 } | 394 } |
377 | 395 |
378 void BasicNetworkManager::OnNetworksChanged() { | 396 void BasicNetworkManager::OnNetworksChanged() { |
379 LOG(LS_VERBOSE) << "Network change was observed at the network manager"; | 397 LOG(LS_VERBOSE) << "Network change was observed at the network manager"; |
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
920 std::stringstream ss; | 938 std::stringstream ss; |
921 // Print out the first space-terminated token of the network desc, plus | 939 // Print out the first space-terminated token of the network desc, plus |
922 // the IP address. | 940 // the IP address. |
923 ss << "Net[" << description_.substr(0, description_.find(' ')) | 941 ss << "Net[" << description_.substr(0, description_.find(' ')) |
924 << ":" << prefix_.ToSensitiveString() << "/" << prefix_length_ | 942 << ":" << prefix_.ToSensitiveString() << "/" << prefix_length_ |
925 << ":" << AdapterTypeToString(type_) << "]"; | 943 << ":" << AdapterTypeToString(type_) << "]"; |
926 return ss.str(); | 944 return ss.str(); |
927 } | 945 } |
928 | 946 |
929 } // namespace rtc | 947 } // namespace rtc |
OLD | NEW |