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.
This commit is contained in:
Wolfgang Bumiller 2015-05-12 09:51:12 +02:00 committed by Dietmar Maurer
parent 467752183d
commit a0b6ef523a

View File

@ -1055,14 +1055,19 @@ sub unpack_sockaddr_in46 {
return ($family, $port, $host);
}
sub getaddrinfo_all {
my ($hostname, @opts) = @_;
my %hints = ( flags => AI_V4MAPPED | AI_ALL,
@opts );
my ($err, @res) = Socket::getaddrinfo($hostname, '0', \%hints);
die "failed to get address info for: $hostname: $err\n" if $err;
return @res;
}
sub get_host_address_family {
my ($hostname, $socktype) = @_;
my %hints = ( flags => AI_V4MAPPED | AI_ALL,
socktype => $socktype );
my ($err, @res) = Socket::getaddrinfo($hostname, '0', \%hints);
die "failed to resolve $hostname: $err\n" if $err;
return ${res[0]}->{family};
my @res = getaddrinfo_all($hostname, socktype => $socktype);
return $res[0]->{family};
}
1;