As it's commonly used in ipv6 support code a getaddrinfo wrapper passing
default flags and dealing with the (err,result) tuple was added.
return ($family, $port, $host);
}
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,
my %hints = ( flags => AI_V4MAPPED | AI_ALL,
- socktype => $socktype );
my ($err, @res) = Socket::getaddrinfo($hostname, '0', \%hints);
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};