]> git.proxmox.com Git - pve-common.git/blobdiff - src/PVE/Tools.pm
prevent the use of AI_ADDRCONFIG
[pve-common.git] / src / PVE / Tools.pm
index 0c6e532473d8d7f8939b37d6ae975618de4e32f3..1bc9eec6afa857926e62626747318268f4d21ed6 100644 (file)
@@ -696,7 +696,8 @@ sub next_unused_port {
                                           LocalPort => $p,
                                           ReuseAddr => 1,
                                           Family    => $family,
-                                          Proto     => 0);
+                                          Proto     => 0,
+                                          GetAddrInfoFlags => 0);
 
            if ($sock) {
                close($sock);
@@ -1055,14 +1056,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;