From 2ed1cf9068975acd3b37a75adb29fa65948481e5 Mon Sep 17 00:00:00 2001 From: qingyan01 <68208925+qingyan01@users.noreply.github.com> Date: Tue, 7 May 2024 11:43:09 +0800 Subject: [PATCH] move addr --- src/common/network/NetworkUtils.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/common/network/NetworkUtils.cpp b/src/common/network/NetworkUtils.cpp index 8ec6d6dc4f..1e38f7cc03 100644 --- a/src/common/network/NetworkUtils.cpp +++ b/src/common/network/NetworkUtils.cpp @@ -65,12 +65,11 @@ StatusOr>> NetworkUtils::listDev return Status::Error("%s", ::strerror(errno)); } for (auto* ifa = iflist; ifa != nullptr; ifa = ifa->ifa_next) { - auto* addr = ifa->ifa_addr; + auto* addr = reinterpret_cast(ifa->ifa_addr); // Skip non-IPv4 devices if (nullptr == addr || addr->sa_family != AF_INET) { continue; } - auto* addr = reinterpret_cast(ifa->ifa_addr); // inet_ntoa is thread safe but not re-entrant, // we could use inet_ntop instead when we need support for IPv6 dev2ipv4s.emplace_back(ifa->ifa_name, ::inet_ntoa(addr->sin_addr));