Skip Menu |

This queue is for tickets about the Danga-Socket CPAN distribution.

Report information
The Basics
Id: 85715
Status: resolved
Priority: 0/
Queue: Danga-Socket

People
Owner: NML [...] cpan.org
Requestors: ROBN [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: 1.62



Subject: [PATCH] IPv6 support for local_ip_string
Calling local_ip_string on a socket with a local IPv6 address results in an exception because it doesn't know to handle IPv6 sockets specially. This pretty much just copies the code from peer_ip_string to add support for it.
Subject: local-ipv6.patch
Index: Danga-Socket-1.61/lib/Danga/Socket.pm =================================================================== --- Danga-Socket-1.61.orig/lib/Danga/Socket.pm 2008-11-28 07:32:47.000000000 +0000 +++ Danga-Socket-1.61/lib/Danga/Socket.pm 2013-05-29 22:19:50.108540552 +0000 @@ -120,6 +120,7 @@ use fields ('sock', # under 'peer_v6', # bool: cached; if peer is an IPv6 address 'peer_ip', # cached stringified IP address of $sock 'peer_port', # cached port number of $sock + 'local_v6', # bool: cached; if local IP address is an IPv6 address 'local_ip', # cached stringified IP address of local end of $sock 'local_port', # cached port number of local end of $sock 'writer_func', # subref which does writing. must return bytes written (or undef) and set $! on errors @@ -1356,10 +1357,28 @@ sub local_ip_string { my $pn = getsockname($self->{sock}); return _undef("local_ip_string undef: getsockname") unless $pn; - my ($port, $iaddr) = Socket::sockaddr_in($pn); + my ($port, $iaddr) = eval { + if (length($pn) >= 28) { + return Socket6::unpack_sockaddr_in6($pn); + } else { + return Socket::sockaddr_in($pn); + } + }; + + if ($@) { + $self->{local_port} = "[Unknown localport '$@']"; + return "[Unknown localname '$@']"; + } + $self->{local_port} = $port; - return $self->{local_ip} = Socket::inet_ntoa($iaddr); + if (length($iaddr) == 4) { + return $self->{local_ip} = Socket::inet_ntoa($iaddr); + } else { + $self->{local_v6} = 1; + return $self->{local_ip} = Socket6::inet_ntop(Socket6::AF_INET6(), + $iaddr); + } } =head2 C<< $obj->local_addr_string() >> @@ -1370,8 +1389,11 @@ object in form "ip:port" =cut sub local_addr_string { my Danga::Socket $self = shift; - my $ip = $self->local_ip_string; - return $ip ? "$ip:$self->{local_port}" : undef; + my $ip = $self->local_ip_string + or return undef; + return $self->{local_v6} ? + "[$ip]:$self->{local_port}" : + "$ip:$self->{local_port}"; }
The bug is fixed in https://cpan.metacpan.org/authors/id/N/NM/NML/Danga-Socket-1.62_03-TRIAL.tar.gz Please test and/or review the code. It's a preview version and I'll release normal 1.62 in a week or so if no new easy to fix problems are discovered. - CPAN Testers: http://matrix.cpantesters.org/?dist=Danga-Socket+1.62_03-TRIAL (all green at the time of the posting) - GitHub: https://github.com/nponeccop/libdanga-socket-perl/tree/windows-blocking