net: ip from host: code shrink

Return a suitable address directly instead of breaking out of the
loop to do that.

no semantic change intended

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2021-09-17 11:35:06 +02:00
parent c45692e04a
commit 29dde5f46b

View File

@ -632,21 +632,15 @@ sub get_ip_from_hostname {
return undef; return undef;
} }
my ($ip, $family);
for my $ai (@res) { for my $ai (@res) {
$family = $ai->{family}; my $ip = addr_to_ip($ai->{addr});
my $tmpip = addr_to_ip($ai->{addr}); if ($ip !~ m/^127\.|^::1$/) {
if ($tmpip !~ m/^127\.|^::1$/) { return wantarray ? ($ip, $ai->{family}) : $ip;
$ip = $tmpip;
last;
} }
} }
if (!defined($ip) ) { # NOTE: we only get here if no WAN/LAN IP was found, so this is now the error path!
die "address lookup for '$hostname' did not find any IP address\n" if !$noerr; die "address lookup for '$hostname' did not find any IP address\n" if !$noerr;
return undef; return undef;
}
return wantarray ? ($ip, $family) : $ip;
} }
sub lock_network { sub lock_network {