Subject: | Why IO::Socket::INET prohibit to bind dynamic port on INADDR_ANY? |
Date: | Sat, 07 Dec 2013 11:19:35 +0900 |
To: | bug-IO [...] rt.cpan.org |
From: | "N.A." <n-a [...] u01.gate01.com> |
Hi all,
I want to listen on dynamically selected port using IO::Socket::INET.
When I specify LocalAddr to '127.0.0.1' or so, it works.
However it doesn't work for '0.0.0.0'.
The code in IO/Socket/INET.pm seems intentionally prohibit this.
I'm just curious to know the reason.
N.A.
--- works well --
use IO::Socket;
my $sock = IO::Socket::INET->new( Proto => 'udp', LocalPort => 0,
LocalAddr => '127.0.0.1' );
say $sock->sockport();
------
--- doesn't work --
use IO::Socket;
my $sock = IO::Socket::INET->new( Proto => 'udp', LocalPort => 0,
LocalAddr => '0.0.0.0' );
say $sock->sockport();
------
--- IO/Socket/INET.pm line 202 --
if($lport || ($laddr ne INADDR_ANY) || exists $arg->{Listen}) {
$sock->bind($lport || 0, $laddr) or
return _error($sock, $!, "$!");
}
-------