From e064c9b06873f4e7532a91dace7e68f86d10b0ce Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Tue, 2 May 2017 11:51:21 +0200 Subject: [PATCH] remote_node_ip: replace fallback method with new PVE::Network helper Improve code reuse. Note that the wantarray check exists in the used helper, so the return signature of remote_node_ip stayed the same here Signed-off-by: Thomas Lamprecht --- data/PVE/Cluster.pm | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/data/PVE/Cluster.pm b/data/PVE/Cluster.pm index f764e8a..2509465 100644 --- a/data/PVE/Cluster.pm +++ b/data/PVE/Cluster.pm @@ -1027,26 +1027,7 @@ sub remote_node_ip { } # fallback: try to get IP by other means - my ($family, $packed_ip); - - eval { - my @res = PVE::Tools::getaddrinfo_all($nodename); - $family = $res[0]->{family}; - $packed_ip = (PVE::Tools::unpack_sockaddr_in46($res[0]->{addr}))[2]; - }; - - if ($@) { - die "hostname lookup failed:\n$@" if !$noerr; - return undef; - } - - my $ip = Socket::inet_ntop($family, $packed_ip); - if ($ip =~ m/^127\.|^::1$/) { - die "hostname lookup failed - got local IP address ($nodename = $ip)\n" if !$noerr; - return undef; - } - - return wantarray ? ($ip, $family) : $ip; + return PVE::Network::get_ip_from_hostname($nodename, $noerr); } sub get_local_migration_ip { -- 2.39.5