| 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 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 [ip](const InterfaceAddress& existing_ip) { | 385 [ip](const InterfaceAddress& existing_ip) { |
| 386 return ip == static_cast<rtc::IPAddress>(existing_ip); | 386 return ip == static_cast<rtc::IPAddress>(existing_ip); |
| 387 }) != ips.end()) { | 387 }) != ips.end()) { |
| 388 return network; | 388 return network; |
| 389 } | 389 } |
| 390 } | 390 } |
| 391 return nullptr; | 391 return nullptr; |
| 392 } | 392 } |
| 393 | 393 |
| 394 BasicNetworkManager::BasicNetworkManager() | 394 BasicNetworkManager::BasicNetworkManager() |
| 395 : thread_(NULL), sent_first_update_(false), start_count_(0), | 395 : thread_(nullptr), |
| 396 ignore_non_default_routes_(false) { | 396 sent_first_update_(false), |
| 397 } | 397 start_count_(0), |
| 398 ignore_non_default_routes_(false) {} |
| 398 | 399 |
| 399 BasicNetworkManager::~BasicNetworkManager() { | 400 BasicNetworkManager::~BasicNetworkManager() { |
| 400 } | 401 } |
| 401 | 402 |
| 402 void BasicNetworkManager::OnNetworksChanged() { | 403 void BasicNetworkManager::OnNetworksChanged() { |
| 403 LOG(LS_INFO) << "Network change was observed"; | 404 LOG(LS_INFO) << "Network change was observed"; |
| 404 UpdateNetworksOnce(); | 405 UpdateNetworksOnce(); |
| 405 } | 406 } |
| 406 | 407 |
| 407 #if defined(__native_client__) | 408 #if defined(__native_client__) |
| 408 | 409 |
| 409 bool BasicNetworkManager::CreateNetworks(bool include_ignored, | 410 bool BasicNetworkManager::CreateNetworks(bool include_ignored, |
| 410 NetworkList* networks) const { | 411 NetworkList* networks) const { |
| 411 RTC_NOTREACHED(); | 412 RTC_NOTREACHED(); |
| 412 LOG(LS_WARNING) << "BasicNetworkManager doesn't work on NaCl yet"; | 413 LOG(LS_WARNING) << "BasicNetworkManager doesn't work on NaCl yet"; |
| 413 return false; | 414 return false; |
| 414 } | 415 } |
| 415 | 416 |
| 416 #elif defined(WEBRTC_POSIX) | 417 #elif defined(WEBRTC_POSIX) |
| 417 void BasicNetworkManager::ConvertIfAddrs(struct ifaddrs* interfaces, | 418 void BasicNetworkManager::ConvertIfAddrs(struct ifaddrs* interfaces, |
| 418 IfAddrsConverter* ifaddrs_converter, | 419 IfAddrsConverter* ifaddrs_converter, |
| 419 bool include_ignored, | 420 bool include_ignored, |
| 420 NetworkList* networks) const { | 421 NetworkList* networks) const { |
| 421 NetworkMap current_networks; | 422 NetworkMap current_networks; |
| 422 | 423 |
| 423 for (struct ifaddrs* cursor = interfaces; | 424 for (struct ifaddrs* cursor = interfaces; cursor != nullptr; |
| 424 cursor != NULL; cursor = cursor->ifa_next) { | 425 cursor = cursor->ifa_next) { |
| 425 IPAddress prefix; | 426 IPAddress prefix; |
| 426 IPAddress mask; | 427 IPAddress mask; |
| 427 InterfaceAddress ip; | 428 InterfaceAddress ip; |
| 428 int scope_id = 0; | 429 int scope_id = 0; |
| 429 | 430 |
| 430 // Some interfaces may not have address assigned. | 431 // Some interfaces may not have address assigned. |
| 431 if (!cursor->ifa_addr || !cursor->ifa_netmask) { | 432 if (!cursor->ifa_addr || !cursor->ifa_netmask) { |
| 432 continue; | 433 continue; |
| 433 } | 434 } |
| 434 // Skip ones which are down. | 435 // Skip ones which are down. |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 | 512 |
| 512 #elif defined(WEBRTC_WIN) | 513 #elif defined(WEBRTC_WIN) |
| 513 | 514 |
| 514 unsigned int GetPrefix(PIP_ADAPTER_PREFIX prefixlist, | 515 unsigned int GetPrefix(PIP_ADAPTER_PREFIX prefixlist, |
| 515 const IPAddress& ip, IPAddress* prefix) { | 516 const IPAddress& ip, IPAddress* prefix) { |
| 516 IPAddress current_prefix; | 517 IPAddress current_prefix; |
| 517 IPAddress best_prefix; | 518 IPAddress best_prefix; |
| 518 unsigned int best_length = 0; | 519 unsigned int best_length = 0; |
| 519 while (prefixlist) { | 520 while (prefixlist) { |
| 520 // Look for the longest matching prefix in the prefixlist. | 521 // Look for the longest matching prefix in the prefixlist. |
| 521 if (prefixlist->Address.lpSockaddr == NULL || | 522 if (prefixlist->Address.lpSockaddr == nullptr || |
| 522 prefixlist->Address.lpSockaddr->sa_family != ip.family()) { | 523 prefixlist->Address.lpSockaddr->sa_family != ip.family()) { |
| 523 prefixlist = prefixlist->Next; | 524 prefixlist = prefixlist->Next; |
| 524 continue; | 525 continue; |
| 525 } | 526 } |
| 526 switch (prefixlist->Address.lpSockaddr->sa_family) { | 527 switch (prefixlist->Address.lpSockaddr->sa_family) { |
| 527 case AF_INET: { | 528 case AF_INET: { |
| 528 sockaddr_in* v4_addr = | 529 sockaddr_in* v4_addr = |
| 529 reinterpret_cast<sockaddr_in*>(prefixlist->Address.lpSockaddr); | 530 reinterpret_cast<sockaddr_in*>(prefixlist->Address.lpSockaddr); |
| 530 current_prefix = IPAddress(v4_addr->sin_addr); | 531 current_prefix = IPAddress(v4_addr->sin_addr); |
| 531 break; | 532 break; |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 } | 654 } |
| 654 adapter_addrs = adapter_addrs->Next; | 655 adapter_addrs = adapter_addrs->Next; |
| 655 } | 656 } |
| 656 return true; | 657 return true; |
| 657 } | 658 } |
| 658 #endif // WEBRTC_WIN | 659 #endif // WEBRTC_WIN |
| 659 | 660 |
| 660 #if defined(WEBRTC_LINUX) | 661 #if defined(WEBRTC_LINUX) |
| 661 bool IsDefaultRoute(const std::string& network_name) { | 662 bool IsDefaultRoute(const std::string& network_name) { |
| 662 FileStream fs; | 663 FileStream fs; |
| 663 if (!fs.Open("/proc/net/route", "r", NULL)) { | 664 if (!fs.Open("/proc/net/route", "r", nullptr)) { |
| 664 LOG(LS_WARNING) << "Couldn't read /proc/net/route, skipping default " | 665 LOG(LS_WARNING) << "Couldn't read /proc/net/route, skipping default " |
| 665 << "route check (assuming everything is a default route)."; | 666 << "route check (assuming everything is a default route)."; |
| 666 return true; | 667 return true; |
| 667 } else { | 668 } else { |
| 668 std::string line; | 669 std::string line; |
| 669 while (fs.ReadLine(&line) == SR_SUCCESS) { | 670 while (fs.ReadLine(&line) == SR_SUCCESS) { |
| 670 char iface_name[256]; | 671 char iface_name[256]; |
| 671 unsigned int iface_ip, iface_gw, iface_mask, iface_flags; | 672 unsigned int iface_ip, iface_gw, iface_mask, iface_flags; |
| 672 if (sscanf(line.c_str(), | 673 if (sscanf(line.c_str(), |
| 673 "%255s %8X %8X %4X %*d %*u %*d %8X", | 674 "%255s %8X %8X %4X %*d %*u %*d %8X", |
| (...skipping 30 matching lines...) Expand all Loading... |
| 704 // Make sure this is a default route, if we're ignoring non-defaults. | 705 // Make sure this is a default route, if we're ignoring non-defaults. |
| 705 if (ignore_non_default_routes_ && !IsDefaultRoute(network.name())) { | 706 if (ignore_non_default_routes_ && !IsDefaultRoute(network.name())) { |
| 706 return true; | 707 return true; |
| 707 } | 708 } |
| 708 #endif | 709 #endif |
| 709 #elif defined(WEBRTC_WIN) | 710 #elif defined(WEBRTC_WIN) |
| 710 // Ignore any HOST side vmware adapters with a description like: | 711 // Ignore any HOST side vmware adapters with a description like: |
| 711 // VMware Virtual Ethernet Adapter for VMnet1 | 712 // VMware Virtual Ethernet Adapter for VMnet1 |
| 712 // but don't ignore any GUEST side adapters with a description like: | 713 // but don't ignore any GUEST side adapters with a description like: |
| 713 // VMware Accelerated AMD PCNet Adapter #2 | 714 // VMware Accelerated AMD PCNet Adapter #2 |
| 714 if (strstr(network.description().c_str(), "VMnet") != NULL) { | 715 if (strstr(network.description().c_str(), "VMnet") != nullptr) { |
| 715 return true; | 716 return true; |
| 716 } | 717 } |
| 717 #endif | 718 #endif |
| 718 | 719 |
| 719 // Ignore any networks with a 0.x.y.z IP | 720 // Ignore any networks with a 0.x.y.z IP |
| 720 if (network.prefix().family() == AF_INET) { | 721 if (network.prefix().family() == AF_INET) { |
| 721 return (network.prefix().v4AddressAsHostOrderInteger() < 0x01000000); | 722 return (network.prefix().v4AddressAsHostOrderInteger() < 0x01000000); |
| 722 } | 723 } |
| 723 | 724 |
| 724 return false; | 725 return false; |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 982 std::stringstream ss; | 983 std::stringstream ss; |
| 983 // Print out the first space-terminated token of the network desc, plus | 984 // Print out the first space-terminated token of the network desc, plus |
| 984 // the IP address. | 985 // the IP address. |
| 985 ss << "Net[" << description_.substr(0, description_.find(' ')) | 986 ss << "Net[" << description_.substr(0, description_.find(' ')) |
| 986 << ":" << prefix_.ToSensitiveString() << "/" << prefix_length_ | 987 << ":" << prefix_.ToSensitiveString() << "/" << prefix_length_ |
| 987 << ":" << AdapterTypeToString(type_) << "]"; | 988 << ":" << AdapterTypeToString(type_) << "]"; |
| 988 return ss.str(); | 989 return ss.str(); |
| 989 } | 990 } |
| 990 | 991 |
| 991 } // namespace rtc | 992 } // namespace rtc |
| OLD | NEW |