From a4be6d78ef7b1f942093488caece560151f43718 Mon Sep 17 00:00:00 2001 From: fhzhang Date: Tue, 23 Jun 2026 21:45:07 -0700 Subject: [PATCH] Support IPv6-only environments in GetLocalHostNicAddresses PiperOrigin-RevId: 937082818 --- tpu_raiden/core/tpu_utils.cc | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/tpu_raiden/core/tpu_utils.cc b/tpu_raiden/core/tpu_utils.cc index 7cfc935d..86aa10cc 100644 --- a/tpu_raiden/core/tpu_utils.cc +++ b/tpu_raiden/core/tpu_utils.cc @@ -359,12 +359,35 @@ std::vector GetLocalHostNicAddresses() { nics.push_back({ifa->ifa_name, ip_str, node}); } } + } else if (ifa->ifa_addr->sa_family == AF_INET6) { + if (std::strcmp(ifa->ifa_name, "lo") != 0) { + char host[INET6_ADDRSTRLEN]; + auto* s_in6 = reinterpret_cast(ifa->ifa_addr); + if (IN6_IS_ADDR_LINKLOCAL(&s_in6->sin6_addr)) { + continue; + } + inet_ntop(AF_INET6, &s_in6->sin6_addr, host, IN6_ADDRSTRLEN); + std::string ip_str(host); + auto it = std::find_if( + nics.begin(), nics.end(), + [&](const HostNicAddress& n) { return n.ip_address == ip_str; }); + if (it == nics.end()) { + int node = GetInterfaceNumaNode(ifa->ifa_name); + nics.push_back({ifa->ifa_name, ip_str, node}); + } + } } } freeifaddrs(ifaddr); } if (nics.empty()) { - nics.push_back({"lo", "127.0.0.1", -1}); + int fd = socket(AF_INET, SOCK_STREAM, 0); + if (fd >= 0) { + close(fd); + nics.push_back({"lo", "127.0.0.1", -1}); + } else { + nics.push_back({"lo", "::1", -1}); + } } return nics; }