================
@@ -116,6 +116,24 @@ bool lldb_private::HostSupportsIPv6() {
return CheckIPSupport("IPv6", "[::1]:0");
}
+bool lldb_private::HostSupportsLocalhostToIPv4() {
+ if (!HostSupportsIPv4())
+ return false;
+
+ auto addresses = SocketAddress::GetAddressInfo("localhost", nullptr, AF_INET,
+ SOCK_STREAM, IPPROTO_TCP);
+ return !addresses.empty();
+}
+
+bool lldb_private::HostSupportsLocalhostToIPv6() {
+ if (!HostSupportsIPv6())
+ return false;
+
+ auto addresses = SocketAddress::GetAddressInfo("localhost", nullptr,
AF_INET6,
+ SOCK_STREAM, IPPROTO_TCP);
----------------
dzhidzhoev wrote:
I've got
```
llvm-project git:(becab1c1b0a3) cat /etc/hosts
127.0.0.1 localhost
127.0.1.1 ubuntu-linux-22-04-desktop
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
```
For some reason, `getaddrinfo("localhost", AF_UNSPEC, ...)` returns only one
address (IPv4 `127.0.0.1`), but `getaddrinfo("localhost", AF_INET6, ...)`
returns an address as well (IPv6 `::1`).
I think it's probably an oddity in getaddrinfo implementation (my gai.conf is
empty). This check seems to work the way expected:
```
auto addresses = SocketAddress::GetAddressInfo(
"localhost", nullptr, AF_UNSPEC, SOCK_STREAM, IPPROTO_TCP);
return std::find_if(addresses.begin(), addresses.end(),
[](SocketAddress &addr) {
return addr.GetFamily() == AF_INET6;
}) != addresses.end();
```
https://github.com/llvm/llvm-project/pull/118673
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits