Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NetUtils: simplify logic in determineInterfaces #257

Merged
merged 6 commits into from
Oct 18, 2021
Merged
Changes from all 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
11 changes: 1 addition & 10 deletions src/NetUtils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ inline namespace IGNITION_TRANSPORT_VERSION_NAMESPACE
std::cerr << "error in getifaddrs: " << strerror(rc) << std::endl;
exit(-1);
}
char preferred_ip[200] = {0};

#if defined(SIOCGIFINDEX)
// Open a socket to use IOCTL later.
Expand Down Expand Up @@ -232,16 +231,8 @@ inline namespace IGNITION_TRANSPORT_VERSION_NAMESPACE
// Is not running.
if (!(ifa->ifa_flags & IFF_UP))
continue;
// IPv6 interface.
if (ifa->ifa_addr->sa_family == AF_INET6 && !preferred_ip[0])
interface = std::string(ip_);
// Private network interface.
else if (isPrivateIP(ip_) && !preferred_ip[0])
interface = std::string(ip_);
// Any other interface.
else if (!isPrivateIP(ip_) &&
(isPrivateIP(preferred_ip) || !preferred_ip[0]))
interface = std::string(ip_);
interface = std::string(ip_);

// Add the new interface if it's new and unique.
if (!interface.empty() &&
Expand Down