develooper Front page | perl.perl5.porters | Postings from January 2012

[perl #106370] IO::Socket::INET does not bind UDP sockets to ephemeral ports

Thread Previous | Thread Next
From:
James E Keenan via RT
Date:
January 6, 2012 16:12
Subject:
[perl #106370] IO::Socket::INET does not bind UDP sockets to ephemeral ports
Message ID:
rt-3.6.HEAD-14510-1325895140-1905.106370-15-0@perl.org
On Thu Dec 15 16:15:45 2011, imran.patel@gmail.com wrote:
> 
> This is a bug report for perl from imran.patel@gmail.com,
> generated with the help of perlbug 1.35 running under perl v5.8.8.
> 
> Perls' IO::Socket::INET core library module has a bug which prevents
>    creating a
> socket that is bound to an OS-selected ephemeral port.
> 
> The standard way to bind to an available port is to set the port to
>    zero when
> calling bind(). With IO::Socket::INET, you'd do something like:
> 
> my @socket_args = (
>     Proto => 'udp',
>     LocalPort => 0,
> );
> my $sock = IO::Socket::INET->new( @socket_args ) or die "socket: $@";
> 
> Except this doesn't work. 

Can you be a bit more explicit as to what doesn't work?

Also, can you try this on a currently supported version of Perl (5.12 or
5.14)?

> Here's the offending bit from
>    IO/Socket/INET.pm:
> 
> if($lport || ($laddr ne INADDR_ANY) || exists $arg->{Listen}) {
>    $sock->bind($lport || 0, $laddr) or
>        return _error($sock, $!, "$!");
> }
> 
> In reality, $lport is undef instead of zero because of another bug,
>    but it
> doesn't matter either way. I verified that this if branch is not taken
>    by using
> the debugger.
> 
> The same thing is true for TCP. But since the Listen option is usually
>    supplied
> for TCP, it makes the if expression evaluate to true and the bind()
>    happens by
> accident.
> 
> I think the best workaround is to use the core Socket.pm module
>    directly.
> 

Thank you very much.
Jim Keenan



---
via perlbug:  queue: perl5 status: new
https://rt.perl.org:443/rt3/Ticket/Display.html?id=106370

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About