summaryrefslogtreecommitdiff
path: root/lldb/unittests/TestingSupport/Host/SocketTestUtilities.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/unittests/TestingSupport/Host/SocketTestUtilities.cpp')
-rw-r--r--lldb/unittests/TestingSupport/Host/SocketTestUtilities.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/lldb/unittests/TestingSupport/Host/SocketTestUtilities.cpp b/lldb/unittests/TestingSupport/Host/SocketTestUtilities.cpp
index eb5bda0fabc7..72ecde845567 100644
--- a/lldb/unittests/TestingSupport/Host/SocketTestUtilities.cpp
+++ b/lldb/unittests/TestingSupport/Host/SocketTestUtilities.cpp
@@ -116,6 +116,28 @@ bool lldb_private::HostSupportsIPv6() {
return CheckIPSupport("IPv6", "[::1]:0");
}
+bool lldb_private::HostSupportsLocalhostToIPv4() {
+ if (!HostSupportsIPv4())
+ return false;
+
+ auto addresses = SocketAddress::GetAddressInfo(
+ "localhost", nullptr, AF_UNSPEC, SOCK_STREAM, IPPROTO_TCP);
+ return llvm::any_of(addresses, [](const SocketAddress &addr) {
+ return addr.GetFamily() == AF_INET;
+ });
+}
+
+bool lldb_private::HostSupportsLocalhostToIPv6() {
+ if (!HostSupportsIPv6())
+ return false;
+
+ auto addresses = SocketAddress::GetAddressInfo(
+ "localhost", nullptr, AF_UNSPEC, SOCK_STREAM, IPPROTO_TCP);
+ return llvm::any_of(addresses, [](const SocketAddress &addr) {
+ return addr.GetFamily() == AF_INET6;
+ });
+}
+
llvm::Expected<std::string> lldb_private::GetLocalhostIP() {
if (HostSupportsIPv4())
return "127.0.0.1";