Revert "Extract HasIPv4Enabled/HasIPv6Enabled."
This reverts commit 86cfe50c0e3549544ca4a7ec097feac44f0e8437.
Reason for revert: Breaks roll into Chromium.
https://ci.chromium.org/ui/p/chromium/builders/try/android-arm64-rel/264191/overview
Original change's description:
> Extract HasIPv4Enabled/HasIPv6Enabled.
>
> Bug: b/292167110
> Change-Id: Idafa4ef23e87951bdd0276c29dee3e7f8be68476
> Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/312580
> Reviewed-by: Harald Alvestrand <hta@webrtc.org>
> Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
> Cr-Commit-Position: refs/heads/main@{#40478}
Bug: b/292167110
Change-Id: Id7ebb5a673eac3c83a2236d4dfbaf31cce1eb9b6
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/313262
Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com>
Owners-Override: Mirko Bonadei <mbonadei@webrtc.org>
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#40480}
diff --git a/p2p/BUILD.gn b/p2p/BUILD.gn
index bc2a647..105536b 100644
--- a/p2p/BUILD.gn
+++ b/p2p/BUILD.gn
@@ -202,7 +202,6 @@
deps = [
":rtc_p2p",
"../rtc_base:net_helpers",
- "../rtc_base:net_test_helpers",
"../rtc_base:task_queue_for_test",
"../rtc_base:threading",
"../rtc_base/memory:always_valid_pointer",
@@ -313,7 +312,6 @@
"../rtc_base:mdns_responder_interface",
"../rtc_base:net_helper",
"../rtc_base:net_helpers",
- "../rtc_base:net_test_helpers",
"../rtc_base:network",
"../rtc_base:network_constants",
"../rtc_base:proxy_info",
diff --git a/p2p/base/fake_port_allocator.h b/p2p/base/fake_port_allocator.h
index 20f6780..05c6313 100644
--- a/p2p/base/fake_port_allocator.h
+++ b/p2p/base/fake_port_allocator.h
@@ -22,7 +22,6 @@
#include "p2p/base/udp_port.h"
#include "rtc_base/memory/always_valid_pointer.h"
#include "rtc_base/net_helpers.h"
-#include "rtc_base/net_test_helpers.h"
#include "rtc_base/task_queue_for_test.h"
#include "rtc_base/thread.h"
diff --git a/p2p/client/basic_port_allocator_unittest.cc b/p2p/client/basic_port_allocator_unittest.cc
index 44e39c3..710d32a 100644
--- a/p2p/client/basic_port_allocator_unittest.cc
+++ b/p2p/client/basic_port_allocator_unittest.cc
@@ -34,7 +34,6 @@
#include "rtc_base/nat_types.h"
#include "rtc_base/net_helper.h"
#include "rtc_base/net_helpers.h"
-#include "rtc_base/net_test_helpers.h"
#include "rtc_base/network.h"
#include "rtc_base/network_constants.h"
#include "rtc_base/network_monitor.h"
diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn
index 3b67e80..7dd8e9c 100644
--- a/rtc_base/BUILD.gn
+++ b/rtc_base/BUILD.gn
@@ -892,27 +892,6 @@
absl_deps = [ "//third_party/abseil-cpp/absl/strings" ]
}
-rtc_library("net_test_helpers") {
- testonly = true
- sources = [
- "net_test_helpers.cc",
- "net_test_helpers.h",
- ]
- deps = [
- ":net_helpers",
- "system:rtc_export",
- ]
- if (is_android) {
- deps += [ ":ifaddrs_android" ]
- }
- if (is_win) {
- deps += [
- ":win32",
- "win:windows_version",
- ]
- }
-}
-
rtc_library("async_resolver_interface") {
visibility = [ "*" ]
sources = [
@@ -1799,7 +1778,6 @@
":logging",
":macromagic",
":net_helpers",
- ":net_test_helpers",
":null_socket_server",
":platform_thread",
":rtc_base_tests_utils",
@@ -2065,7 +2043,6 @@
":logging",
":macromagic",
":net_helpers",
- ":net_test_helpers",
":network",
":network_route",
":null_socket_server",
diff --git a/rtc_base/nat_unittest.cc b/rtc_base/nat_unittest.cc
index 19e5354..f6dd83c 100644
--- a/rtc_base/nat_unittest.cc
+++ b/rtc_base/nat_unittest.cc
@@ -26,7 +26,6 @@
#include "rtc_base/nat_socket_factory.h"
#include "rtc_base/nat_types.h"
#include "rtc_base/net_helpers.h"
-#include "rtc_base/net_test_helpers.h"
#include "rtc_base/network.h"
#include "rtc_base/physical_socket_server.h"
#include "rtc_base/socket.h"
diff --git a/rtc_base/net_helpers.cc b/rtc_base/net_helpers.cc
index 00cd434..73fe862 100644
--- a/rtc_base/net_helpers.cc
+++ b/rtc_base/net_helpers.cc
@@ -19,9 +19,15 @@
#include <ws2spi.h>
#include <ws2tcpip.h>
+#include "rtc_base/win/windows_version.h"
#endif
#if defined(WEBRTC_POSIX) && !defined(__native_client__)
#include <arpa/inet.h>
+#if defined(WEBRTC_ANDROID)
+#include "rtc_base/ifaddrs_android.h"
+#else
+#include <ifaddrs.h>
+#endif
#endif // defined(WEBRTC_POSIX) && !defined(__native_client__)
namespace rtc {
@@ -42,4 +48,83 @@
return ::inet_pton(af, src_str.c_str(), dst);
#endif
}
+
+bool HasIPv4Enabled() {
+#if defined(WEBRTC_POSIX) && !defined(__native_client__)
+ bool has_ipv4 = false;
+ struct ifaddrs* ifa;
+ if (getifaddrs(&ifa) < 0) {
+ return false;
+ }
+ for (struct ifaddrs* cur = ifa; cur != nullptr; cur = cur->ifa_next) {
+ if (cur->ifa_addr != nullptr && cur->ifa_addr->sa_family == AF_INET) {
+ has_ipv4 = true;
+ break;
+ }
+ }
+ freeifaddrs(ifa);
+ return has_ipv4;
+#else
+ return true;
+#endif
+}
+
+bool HasIPv6Enabled() {
+#if defined(WINUWP)
+ // WinUWP always has IPv6 capability.
+ return true;
+#elif defined(WEBRTC_WIN)
+ if (rtc::rtc_win::GetVersion() >= rtc::rtc_win::Version::VERSION_VISTA) {
+ return true;
+ }
+ if (rtc::rtc_win::GetVersion() < rtc::rtc_win::Version::VERSION_XP) {
+ return false;
+ }
+ DWORD protbuff_size = 4096;
+ std::unique_ptr<char[]> protocols;
+ LPWSAPROTOCOL_INFOW protocol_infos = nullptr;
+ int requested_protocols[2] = {AF_INET6, 0};
+
+ int err = 0;
+ int ret = 0;
+ // Check for protocols in a do-while loop until we provide a buffer large
+ // enough. (WSCEnumProtocols sets protbuff_size to its desired value).
+ // It is extremely unlikely that this will loop more than once.
+ do {
+ protocols.reset(new char[protbuff_size]);
+ protocol_infos = reinterpret_cast<LPWSAPROTOCOL_INFOW>(protocols.get());
+ ret = WSCEnumProtocols(requested_protocols, protocol_infos, &protbuff_size,
+ &err);
+ } while (ret == SOCKET_ERROR && err == WSAENOBUFS);
+
+ if (ret == SOCKET_ERROR) {
+ return false;
+ }
+
+ // Even if ret is positive, check specifically for IPv6.
+ // Non-IPv6 enabled WinXP will still return a RAW protocol.
+ for (int i = 0; i < ret; ++i) {
+ if (protocol_infos[i].iAddressFamily == AF_INET6) {
+ return true;
+ }
+ }
+ return false;
+#elif defined(WEBRTC_POSIX) && !defined(__native_client__)
+ bool has_ipv6 = false;
+ struct ifaddrs* ifa;
+ if (getifaddrs(&ifa) < 0) {
+ return false;
+ }
+ for (struct ifaddrs* cur = ifa; cur != nullptr; cur = cur->ifa_next) {
+ if (cur->ifa_addr != nullptr && cur->ifa_addr->sa_family == AF_INET6) {
+ has_ipv6 = true;
+ break;
+ }
+ }
+ freeifaddrs(ifa);
+ return has_ipv6;
+#else
+ return true;
+#endif
+}
} // namespace rtc
diff --git a/rtc_base/net_helpers.h b/rtc_base/net_helpers.h
index a529f4f..478cec3 100644
--- a/rtc_base/net_helpers.h
+++ b/rtc_base/net_helpers.h
@@ -29,6 +29,9 @@
const char* inet_ntop(int af, const void* src, char* dst, socklen_t size);
int inet_pton(int af, absl::string_view src, void* dst);
+RTC_EXPORT bool HasIPv4Enabled();
+RTC_EXPORT bool HasIPv6Enabled();
+
} // namespace rtc
#endif // RTC_BASE_NET_HELPERS_H_
diff --git a/rtc_base/net_test_helpers.cc b/rtc_base/net_test_helpers.cc
deleted file mode 100644
index 806d7de..0000000
--- a/rtc_base/net_test_helpers.cc
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Copyright 2023 The WebRTC Project Authors. All rights reserved.
- *
- * Use of this source code is governed by a BSD-style license
- * that can be found in the LICENSE file in the root of the source
- * tree. An additional intellectual property rights grant can be found
- * in the file PATENTS. All contributing project authors may
- * be found in the AUTHORS file in the root of the source tree.
- */
-
-#include "rtc_base/net_test_helpers.h"
-
-#include <memory>
-#include <string>
-
-#if defined(WEBRTC_WIN)
-#include <ws2spi.h>
-#include <ws2tcpip.h>
-
-#include "rtc_base/win/windows_version.h"
-#endif
-#if defined(WEBRTC_POSIX) && !defined(__native_client__)
-#include <arpa/inet.h>
-#if defined(WEBRTC_ANDROID)
-#include "rtc_base/ifaddrs_android.h"
-#else
-#include <ifaddrs.h>
-#endif
-#endif // defined(WEBRTC_POSIX) && !defined(__native_client__)
-
-namespace rtc {
-
-bool HasIPv4Enabled() {
-#if defined(WEBRTC_POSIX) && !defined(__native_client__)
- bool has_ipv4 = false;
- struct ifaddrs* ifa;
- if (getifaddrs(&ifa) < 0) {
- return false;
- }
- for (struct ifaddrs* cur = ifa; cur != nullptr; cur = cur->ifa_next) {
- if (cur->ifa_addr != nullptr && cur->ifa_addr->sa_family == AF_INET) {
- has_ipv4 = true;
- break;
- }
- }
- freeifaddrs(ifa);
- return has_ipv4;
-#else
- return true;
-#endif
-}
-
-bool HasIPv6Enabled() {
-#if defined(WINUWP)
- // WinUWP always has IPv6 capability.
- return true;
-#elif defined(WEBRTC_WIN)
- if (rtc::rtc_win::GetVersion() >= rtc::rtc_win::Version::VERSION_VISTA) {
- return true;
- }
- if (rtc::rtc_win::GetVersion() < rtc::rtc_win::Version::VERSION_XP) {
- return false;
- }
- DWORD protbuff_size = 4096;
- std::unique_ptr<char[]> protocols;
- LPWSAPROTOCOL_INFOW protocol_infos = nullptr;
- int requested_protocols[2] = {AF_INET6, 0};
-
- int err = 0;
- int ret = 0;
- // Check for protocols in a do-while loop until we provide a buffer large
- // enough. (WSCEnumProtocols sets protbuff_size to its desired value).
- // It is extremely unlikely that this will loop more than once.
- do {
- protocols.reset(new char[protbuff_size]);
- protocol_infos = reinterpret_cast<LPWSAPROTOCOL_INFOW>(protocols.get());
- ret = WSCEnumProtocols(requested_protocols, protocol_infos, &protbuff_size,
- &err);
- } while (ret == SOCKET_ERROR && err == WSAENOBUFS);
-
- if (ret == SOCKET_ERROR) {
- return false;
- }
-
- // Even if ret is positive, check specifically for IPv6.
- // Non-IPv6 enabled WinXP will still return a RAW protocol.
- for (int i = 0; i < ret; ++i) {
- if (protocol_infos[i].iAddressFamily == AF_INET6) {
- return true;
- }
- }
- return false;
-#elif defined(WEBRTC_POSIX) && !defined(__native_client__)
- bool has_ipv6 = false;
- struct ifaddrs* ifa;
- if (getifaddrs(&ifa) < 0) {
- return false;
- }
- for (struct ifaddrs* cur = ifa; cur != nullptr; cur = cur->ifa_next) {
- if (cur->ifa_addr != nullptr && cur->ifa_addr->sa_family == AF_INET6) {
- has_ipv6 = true;
- break;
- }
- }
- freeifaddrs(ifa);
- return has_ipv6;
-#else
- return true;
-#endif
-}
-} // namespace rtc
diff --git a/rtc_base/net_test_helpers.h b/rtc_base/net_test_helpers.h
deleted file mode 100644
index 2e8320c..0000000
--- a/rtc_base/net_test_helpers.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Copyright 2023 The WebRTC Project Authors. All rights reserved.
- *
- * Use of this source code is governed by a BSD-style license
- * that can be found in the LICENSE file in the root of the source
- * tree. An additional intellectual property rights grant can be found
- * in the file PATENTS. All contributing project authors may
- * be found in the AUTHORS file in the root of the source tree.
- */
-
-#ifndef RTC_BASE_NET_TEST_HELPERS_H_
-#define RTC_BASE_NET_TEST_HELPERS_H_
-
-#include "rtc_base/system/rtc_export.h"
-
-namespace rtc {
-
-RTC_EXPORT bool HasIPv4Enabled();
-RTC_EXPORT bool HasIPv6Enabled();
-
-} // namespace rtc
-
-#endif // RTC_BASE_NET_TEST_HELPERS_H_
diff --git a/rtc_base/physical_socket_server_unittest.cc b/rtc_base/physical_socket_server_unittest.cc
index de64a31..f24c7e4 100644
--- a/rtc_base/physical_socket_server_unittest.cc
+++ b/rtc_base/physical_socket_server_unittest.cc
@@ -19,7 +19,6 @@
#include "rtc_base/ip_address.h"
#include "rtc_base/logging.h"
#include "rtc_base/net_helpers.h"
-#include "rtc_base/net_test_helpers.h"
#include "rtc_base/network_monitor.h"
#include "rtc_base/socket_unittest.h"
#include "rtc_base/test_utils.h"
diff --git a/rtc_base/socket_unittest.cc b/rtc_base/socket_unittest.cc
index 0a41a77..40da8c2 100644
--- a/rtc_base/socket_unittest.cc
+++ b/rtc_base/socket_unittest.cc
@@ -27,7 +27,6 @@
#include "rtc_base/gunit.h"
#include "rtc_base/logging.h"
#include "rtc_base/net_helpers.h"
-#include "rtc_base/net_test_helpers.h"
#include "rtc_base/socket_address.h"
#include "rtc_base/socket_server.h"
#include "rtc_base/socket_unittest.h"
diff --git a/rtc_base/test_client_unittest.cc b/rtc_base/test_client_unittest.cc
index b2866a2..a0c8b88 100644
--- a/rtc_base/test_client_unittest.cc
+++ b/rtc_base/test_client_unittest.cc
@@ -17,7 +17,6 @@
#include "rtc_base/async_udp_socket.h"
#include "rtc_base/logging.h"
#include "rtc_base/net_helpers.h"
-#include "rtc_base/net_test_helpers.h"
#include "rtc_base/physical_socket_server.h"
#include "rtc_base/socket.h"
#include "rtc_base/test_echo_server.h"