]> git.proxmox.com Git - pve-common.git/commitdiff
tools: next_unused_port: use IPPROTO_TCP explicitly
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Tue, 30 May 2017 13:30:10 +0000 (15:30 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Wed, 31 May 2017 05:34:14 +0000 (07:34 +0200)
Otherwise perl tries to bind+listen on a UDP socket if the
TCP socket fails - which is a waste since we're looking for
TCP ports.
Additionall since UDP doesn't support listen(), perl will
return EOPNOTSUPP instead of, say, EADDRINUSE. (We don't
care about the error in this code though.)

src/PVE/Tools.pm

index 30322b2888246a8b6ae1c139f370582de936db7e..da7da5d36146a51a5d95276faaa822284ecaf91d 100644 (file)
@@ -4,7 +4,8 @@ use strict;
 use warnings;
 use POSIX qw(EINTR EEXIST EOPNOTSUPP);
 use IO::Socket::IP;
-use Socket qw(AF_INET AF_INET6 AI_ALL AI_V4MAPPED AI_CANONNAME SOCK_DGRAM);
+use Socket qw(AF_INET AF_INET6 AI_ALL AI_V4MAPPED AI_CANONNAME SOCK_DGRAM
+             IPPROTO_TCP);
 use IO::Select;
 use File::Basename;
 use File::Path qw(make_path);
@@ -789,7 +790,7 @@ sub next_unused_port {
        my %sockargs = (Listen => 5,
                        ReuseAddr => 1,
                        Family    => $family,
-                       Proto     => 0,
+                       Proto     => IPPROTO_TCP,
                        GetAddrInfoFlags => 0);
        $sockargs{LocalAddr} = $address if defined($address);