From 467752183d14a62e6412156eff8ec2f3554fb38e Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Tue, 12 May 2015 09:51:11 +0200 Subject: [PATCH] add a socket family argument to next_*_port functions Instead of assuming a local address of 0.0.0.0, the next_*_port family of functions now takes an optional packet family argument (AF_INET/AF_INET6), used for ipv6 support. --- src/PVE/Tools.pm | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm index 0e1af09..0c6e532 100644 --- a/src/PVE/Tools.pm +++ b/src/PVE/Tools.pm @@ -660,7 +660,7 @@ sub wait_for_vnc_port { } sub next_unused_port { - my ($range_start, $range_end) = @_; + my ($range_start, $range_end, $family) = @_; # We use a file to register allocated ports. # Those registrations expires after $expiretime. @@ -693,9 +693,9 @@ sub next_unused_port { next if $ports->{$p}; # reserved my $sock = IO::Socket::IP->new(Listen => 5, - LocalAddr => '0.0.0.0', LocalPort => $p, ReuseAddr => 1, + Family => $family, Proto => 0); if ($sock) { @@ -725,15 +725,18 @@ sub next_unused_port { } sub next_migrate_port { - return next_unused_port(60000, 60050); + my ($family) = @_; + return next_unused_port(60000, 60050, $family); } sub next_vnc_port { - return next_unused_port(5900, 6000); + my ($family) = @_; + return next_unused_port(5900, 6000, $family); } sub next_spice_port { - return next_unused_port(61000, 61099); + my ($family) = @_; + return next_unused_port(61000, 61099, $family); } # NOTE: NFS syscall can't be interrupted, so alarm does -- 2.39.2