network_interfaces_posix.cc 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright 2015 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "net/base/network_interfaces_posix.h"
  5. #include <netinet/in.h>
  6. #include <sys/types.h>
  7. #include <memory>
  8. #include <set>
  9. #include "net/base/network_interfaces.h"
  10. namespace net {
  11. namespace internal {
  12. // The application layer can pass |policy| defined in net_util.h to
  13. // request filtering out certain type of interfaces.
  14. bool ShouldIgnoreInterface(const std::string& name, int policy) {
  15. // Filter out VMware interfaces, typically named vmnet1 and vmnet8,
  16. // which might not be useful for use cases like WebRTC.
  17. if ((policy & EXCLUDE_HOST_SCOPE_VIRTUAL_INTERFACES) &&
  18. ((name.find("vmnet") != std::string::npos) ||
  19. (name.find("vnic") != std::string::npos))) {
  20. return true;
  21. }
  22. return false;
  23. }
  24. // Check if the address is unspecified (i.e. made of zeroes) or loopback.
  25. bool IsLoopbackOrUnspecifiedAddress(const sockaddr* addr) {
  26. if (addr->sa_family == AF_INET6) {
  27. const struct sockaddr_in6* addr_in6 =
  28. reinterpret_cast<const struct sockaddr_in6*>(addr);
  29. const struct in6_addr* sin6_addr = &addr_in6->sin6_addr;
  30. if (IN6_IS_ADDR_LOOPBACK(sin6_addr) || IN6_IS_ADDR_UNSPECIFIED(sin6_addr)) {
  31. return true;
  32. }
  33. } else if (addr->sa_family == AF_INET) {
  34. const struct sockaddr_in* addr_in =
  35. reinterpret_cast<const struct sockaddr_in*>(addr);
  36. if (addr_in->sin_addr.s_addr == INADDR_LOOPBACK ||
  37. addr_in->sin_addr.s_addr == 0) {
  38. return true;
  39. }
  40. } else {
  41. // Skip non-IP addresses.
  42. return true;
  43. }
  44. return false;
  45. }
  46. } // namespace internal
  47. WifiPHYLayerProtocol GetWifiPHYLayerProtocol() {
  48. return WIFI_PHY_LAYER_PROTOCOL_UNKNOWN;
  49. }
  50. std::unique_ptr<ScopedWifiOptions> SetWifiOptions(int options) {
  51. return nullptr;
  52. }
  53. } // namespace net