]> git.proxmox.com Git - pve-storage.git/commitdiff
ipv6 support for Storage::resolv_server
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Tue, 12 May 2015 07:42:37 +0000 (09:42 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Tue, 12 May 2015 08:39:15 +0000 (10:39 +0200)
While in posix gethostbyname(3) does support ipv6, perl's gethostbyname
usually returns wrong results for names, or no results for ipv6
addresses. Since we provide a getaddrinfo helper already, we now use
that instead.

PVE/Storage.pm

index 92c7d146c61ab0d6bfec4e2d8f180be39409c1fc..c1cf524354dcb3c5c8f45e38ab0e786ef2a67f90 100755 (executable)
@@ -930,9 +930,14 @@ sub storage_info {
 sub resolv_server {
     my ($server) = @_;
 
-    my $packed_ip = gethostbyname($server);
+    my ($packed_ip, $family);
+    eval {
+       my @res = PVE::Tools::getaddrinfo_all($server);
+       $family = $res[0]->{family};
+       $packed_ip = (PVE::Tools::unpack_sockaddr_in46($res[0]->{addr}))[2];
+    };
     if (defined $packed_ip) {
-       return inet_ntoa($packed_ip);
+       return inet_ntop($family, $packed_ip);
     }
     return undef;
 }