]> git.proxmox.com Git - pve-common.git/blobdiff - src/PVE/Tools.pm
wait_for_vnc_port: allow to enforce IP family
[pve-common.git] / src / PVE / Tools.pm
index 2c64f6ac33206791a5e70b038b49b76fa71b13dd..6d579d8f9cd1234cecafd986e60cf9eaec7a6c5b 100644 (file)
@@ -791,17 +791,20 @@ sub extract_param {
 
 # Note: we use this to wait until vncterm/spiceterm is ready
 sub wait_for_vnc_port {
-    my ($port, $timeout) = @_;
+    my ($port, $family, $timeout) = @_;
 
     $timeout = 5 if !$timeout;
     my $sleeptime = 0;
     my $starttime = [gettimeofday];
     my $elapsed;
 
+    my $cmd = ['/bin/ss', '-Htln', "sport = :$port"];
+    push @$cmd, $family == AF_INET6 ? '-6' : '-4' if defined($family);
+
     my $found;
     while (($elapsed = tv_interval($starttime)) < $timeout) {
        # -Htln = don't print header, tcp, listening sockets only, numeric ports
-       run_command(['/bin/ss', '-Htln', "sport = :$port"], outfunc => sub {
+       run_command($cmd, outfunc => sub {
            my $line = shift;
            if ($line =~ m/^LISTEN\s+\d+\s+\d+\s+\S+:(\d+)\s/) {
                $found = 1 if ($port == $1);