[pve-devel] [PATCH] ipv6 support for Storage::resolv_server
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 | 9 +++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/PVE/Storage.pm b/PVE/Storage.pm index b542ee6..b0c63a1 100755 --- a/PVE/Storage.pm +++ b/PVE/Storage.pm @@ -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; } -- 2.1.4 ___ pve-devel mailing list pve-devel@pve.proxmox.com http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
Re: [pve-devel] [PATCH] ipv6 support for Storage::resolv_server
> --- a/PVE/Storage.pm > +++ b/PVE/Storage.pm > @@ -930,9 +930,14 @@ sub storage_info { > sub resolv_server { > my ($server) = @_; > > -my $packed_ip = gethostbyname($server); What is wrong with gethostbyname? > +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; > } > -- > 2.1.4 > > > ___ > pve-devel mailing list > pve-devel@pve.proxmox.com > http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel > ___ pve-devel mailing list pve-devel@pve.proxmox.com http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
[pve-devel] [PATCH] ipv6 support for Storage::resolv_server
--- PVE/Storage.pm | 9 +++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/PVE/Storage.pm b/PVE/Storage.pm index b542ee6..b0c63a1 100755 --- a/PVE/Storage.pm +++ b/PVE/Storage.pm @@ -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; } -- 2.1.4 ___ pve-devel mailing list pve-devel@pve.proxmox.com http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel