Skip to content

Commit

Permalink
move the following auto *addr above the if and check whether the addr…
Browse files Browse the repository at this point in the history
… is nullptr
  • Loading branch information
qingyan01 committed Apr 19, 2024
1 parent 73ff1a2 commit a641d3f
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/common/network/NetworkUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ 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;
// Skip non-IPv4 devices
if (nullptr == ifa->ifa_addr || 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);
Expand Down

0 comments on commit a641d3f

Please sign in to comment.