Skip to content
Open
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/common/network/NetworkUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +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 = reinterpret_cast<struct sockaddr_in*>(ifa->ifa_addr);
// Skip non-IPv4 devices
if (ifa->ifa_addr->sa_family != AF_INET) {
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