Skip to content

Commit

Permalink
NetUtils: simplify logic in determineInterfaces (#257)
Browse files Browse the repository at this point in the history
* NetUtils: remove unused variable

The preferred_ip array is initialized to {0} and no code
writes to it; it is only read from, so just remove it.

* Remove if/else block with identical actions

Each branch executes the same code, so just run that code
unconditionally.

Signed-off-by: Steve Peters <[email protected]>
  • Loading branch information
scpeters authored Oct 18, 2021
1 parent 95bb75a commit 347ff00
Showing 1 changed file with 1 addition and 10 deletions.
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

0 comments on commit 347ff00

Please sign in to comment.