From a0b6ef523a2f3ea423bd61b5257dee7c96cb1a0a Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Tue, 12 May 2015 09:51:12 +0200 Subject: [PATCH] new helper: getaddrinfo_all As it's commonly used in ipv6 support code a getaddrinfo wrapper passing default flags and dealing with the (err,result) tuple was added. --- src/PVE/Tools.pm | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm index 0c6e532..01823c2 100644 --- a/src/PVE/Tools.pm +++ b/src/PVE/Tools.pm @@ -1055,14 +1055,19 @@ sub unpack_sockaddr_in46 { return ($family, $port, $host); } -sub get_host_address_family { - my ($hostname, $socktype) = @_; +sub getaddrinfo_all { + my ($hostname, @opts) = @_; my %hints = ( flags => AI_V4MAPPED | AI_ALL, - socktype => $socktype ); + @opts ); my ($err, @res) = Socket::getaddrinfo($hostname, '0', \%hints); - die "failed to resolve $hostname: $err\n" if $err; + die "failed to get address info for: $hostname: $err\n" if $err; + return @res; +} - return ${res[0]}->{family}; +sub get_host_address_family { + my ($hostname, $socktype) = @_; + my @res = getaddrinfo_all($hostname, socktype => $socktype); + return $res[0]->{family}; } 1; -- 2.39.2