Skip to content

Commit

Permalink
move addr
Browse files Browse the repository at this point in the history
  • Loading branch information
qingyan01 committed May 7, 2024
1 parent a641d3f commit 2ed1cf9
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/common/network/NetworkUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,11 @@ StatusOr<std::vector<std::pair<std::string, std::string>>> 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<struct sockaddr_in*>(ifa->ifa_addr);
// Skip non-IPv4 devices
if (nullptr == addr || addr->sa_family != AF_INET) {
continue;
}
auto* addr = reinterpret_cast<struct sockaddr_in*>(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));
Expand Down

0 comments on commit 2ed1cf9

Please sign in to comment.