mirror of
https://git.proxmox.com/git/pve-common
synced 2025-07-30 03:40:13 +00:00
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:
parent
467752183d
commit
a0b6ef523a
@ -1055,14 +1055,19 @@ sub unpack_sockaddr_in46 {
|
|||||||
return ($family, $port, $host);
|
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 {
|
sub get_host_address_family {
|
||||||
my ($hostname, $socktype) = @_;
|
my ($hostname, $socktype) = @_;
|
||||||
my %hints = ( flags => AI_V4MAPPED | AI_ALL,
|
my @res = getaddrinfo_all($hostname, socktype => $socktype);
|
||||||
socktype => $socktype );
|
return $res[0]->{family};
|
||||||
my ($err, @res) = Socket::getaddrinfo($hostname, '0', \%hints);
|
|
||||||
die "failed to resolve $hostname: $err\n" if $err;
|
|
||||||
|
|
||||||
return ${res[0]}->{family};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
Loading…
Reference in New Issue
Block a user