From 29dde5f46b4bb616ed4814903c5d28427e668a4d Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Fri, 17 Sep 2021 11:35:06 +0200 Subject: [PATCH] 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 --- src/PVE/Network.pm | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/PVE/Network.pm b/src/PVE/Network.pm index 81945fa..f6ad4cd 100644 --- a/src/PVE/Network.pm +++ b/src/PVE/Network.pm @@ -632,21 +632,15 @@ sub get_ip_from_hostname { return undef; } - my ($ip, $family); for my $ai (@res) { - $family = $ai->{family}; - my $tmpip = addr_to_ip($ai->{addr}); - if ($tmpip !~ m/^127\.|^::1$/) { - $ip = $tmpip; - last; + my $ip = addr_to_ip($ai->{addr}); + if ($ip !~ m/^127\.|^::1$/) { + return wantarray ? ($ip, $ai->{family}) : $ip; } } - if (!defined($ip) ) { - die "address lookup for '$hostname' did not find any IP address\n" if !$noerr; - return undef; - } - - return wantarray ? ($ip, $family) : $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; + return undef; } sub lock_network { -- 2.39.2