[TE] fix: filter out DOWN network interfaces in findLocalIpAddresses() (#422)

Signed-off-by: phoenixwu0229 <phoenixwu0229@icloud.com>
This commit is contained in:
phoenixwu0229 2025-05-29 15:23:55 +08:00 committed by GitHub
parent 072248ba68
commit 9bcdbf36ff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 0 deletions

View File

@ -867,9 +867,18 @@ std::vector<std::string> findLocalIpAddresses() {
continue;
}
// Check if interface is UP and RUNNING
if (!(ifa->ifa_flags & IFF_UP) || !(ifa->ifa_flags & IFF_RUNNING)) {
LOG(INFO) << "Skipping interface " << ifa->ifa_name
<< " (not UP or not RUNNING)";
continue;
}
char host[NI_MAXHOST];
if (getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in), host,
NI_MAXHOST, nullptr, 0, NI_NUMERICHOST) == 0) {
LOG(INFO) << "Found active interface " << ifa->ifa_name
<< " with IP " << host;
ips.push_back(host);
}
}