]> git.proxmox.com Git - pve-common.git/commitdiff
net: ip from host: code shrink
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 17 Sep 2021 09:35:06 +0000 (11:35 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 17 Sep 2021 09:37:00 +0000 (11:37 +0200)
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>
src/PVE/Network.pm

index 81945fa0dd3544d386ead9eedf79b4e5580a6c80..f6ad4cde110545f583d4d4de9707f8a03a0ee4cf 100644 (file)
@@ -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 {