Skip to content

Why IO::Socket::INET prohibit to bind dynamic port on INADDR_ANY? [rt.cpan.org #91231] #17438

Open
@toddr

Description

@toddr

Migrated from rt.cpan.org#91231 (status was 'new')

Requestors:

From [email protected] on 2013-12-07 02:19:52:

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, $!, "$!");
	}
-------

Metadata

Metadata

Assignees

No one assigned

    Labels

    dist-IOissues in the dual-life blead-first IO distribution

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions