Skip Menu |
 

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

Report information
The Basics
Id: 75071
Status: resolved
Priority: 0/
Queue: IO-Socket-IP

People
Owner: Nobody in particular
Requestors: zefram [...] fysh.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in:
  • 0.08
  • 0.08_005
Fixed in: 0.09



From zefram [...] fysh.org Thu Feb 16 15: 34:39 2012
MIME-Version: 1.0
X-Spam-Status: No, score=-3.917 tagged_above=-99.9 required=10 tests=[AWL=-2.017, BAYES_00=-1.9] autolearn=ham
Content-Disposition: inline
X-Spam-Flag: NO
content-type: text/plain; charset="utf-8"
Message-ID: <20120216203428.GA14008 [...] lake.fysh.org>
X-Virus-Scanned: Debian amavisd-new at bestpractical.com
X-Spam-Score: -3.917
Received: from localhost (localhost [127.0.0.1]) by hipster.bestpractical.com (Postfix) with ESMTP id 56E9C24165D for <cpan-bug+IO-Socket-IP [...] hipster.bestpractical.com>; Thu, 16 Feb 2012 15:34:39 -0500 (EST)
Received: from hipster.bestpractical.com ([127.0.0.1]) by localhost (hipster.bestpractical.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id lmx8a+ADrfFf for <cpan-bug+IO-Socket-IP [...] hipster.bestpractical.com>; Thu, 16 Feb 2012 15:34:37 -0500 (EST)
Received: from la.mx.develooper.com (x1.develooper.com [207.171.7.70]) by hipster.bestpractical.com (Postfix) with SMTP id 8FFCD2415C8 for <bug-IO-Socket-IP [...] rt.cpan.org>; Thu, 16 Feb 2012 15:34:37 -0500 (EST)
Received: (qmail 23947 invoked by uid 103); 16 Feb 2012 20:34:37 -0000
Received: from x16.dev (10.0.100.26) by x1.dev with QMQP; 16 Feb 2012 20:34:37 -0000
Received: from lake.fysh.org (HELO lake.fysh.org) (81.94.195.195) by 16.mx.develooper.com (qpsmtpd/0.80/v0.80-19-gf52d165) with ESMTP; Thu, 16 Feb 2012 12:34:34 -0800
Received: from zefram by lake.fysh.org with local (Exim 4.72 #1 (Debian)) id 1Ry828-0003iw-4e; Thu, 16 Feb 2012 20:34:28 +0000
Delivered-To: cpan-bug+IO-Socket-IP [...] hipster.bestpractical.com
Subject: missing peeraddr and sockaddr methods
Return-Path: <zefram [...] fysh.org>
X-RT-Mail-Extension: io-socket-ip
X-Original-To: cpan-bug+IO-Socket-IP [...] hipster.bestpractical.com
X-Spam-Check-BY: 16.mx.develooper.com
Date: Thu, 16 Feb 2012 20:34:28 +0000
X-Spam-Level:
To: bug-IO-Socket-IP [...] rt.cpan.org
From: Zefram <zefram [...] fysh.org>
X-RT-Original-Encoding: us-ascii
Content-Length: 455
Download (untitled) / with headers
text/plain 455b
IO::Socket::INET has methods ->peeraddr and ->sockaddr which return the IP addresses of the two endpoints in octet-string form. IO::Socket::IP doesn't have them. I think it should, for drop-in replaceability. I just got bitten by this, having selected a method from the I:S:INET doc and assumed that I:S:IP would work correctly in its place. Of course, for an IPv6 socket these methods will return 16-octet strings instead of 4-octet strings. -zefram
MIME-Version: 1.0
In-Reply-To: <20120216203428.GA14008 [...] lake.fysh.org>
X-Mailer: MIME-tools 5.427 (Entity 5.427)
References: <20120216203428.GA14008 [...] lake.fysh.org>
Content-Type: multipart/mixed; boundary="----------=_1329437570-10814-37"
Message-ID: <rt-3.8.HEAD-10814-1329437570-1878.75071-0-0 [...] rt.cpan.org>
X-RT-Original-Encoding: utf-8
Content-Length: 0
Content-Disposition: inline
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 139
Download (untitled) / with headers
text/plain 139b
Attached patch adds these methods. Doesn't use Socket::inet_pton in the end as it turns out that is broken (see RT 75074) -- Paul Evans
MIME-Version: 1.0
Subject: rt75071.patch
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Type: text/x-patch; name="rt75071.patch"
Content-Disposition: inline; filename="rt75071.patch"
Content-Transfer-Encoding: binary
Content-Length: 5924
Download rt75071.patch
text/x-diff 5.7k
=== modified file 'lib/IO/Socket/IP.pm' --- lib/IO/Socket/IP.pm 2012-02-15 23:09:32 +0000 +++ lib/IO/Socket/IP.pm 2012-02-17 00:10:30 +0000 @@ -15,6 +15,7 @@ use Socket 1.97 qw( getaddrinfo getnameinfo + sockaddr_family AF_INET AI_PASSIVE IPPROTO_TCP IPPROTO_UDP @@ -627,6 +628,22 @@ return ( $host, $service ); } +sub _unpack_sockaddr +{ + my ( $addr ) = @_; + my $family = sockaddr_family $addr; + + if( $family == AF_INET ) { + return ( Socket::unpack_sockaddr_in $addr )[1]; + } + elsif( defined $AF_INET6 and $family == $AF_INET6 ) { + return ( Socket::unpack_sockaddr_in6 $addr )[1]; + } + else { + croak "Unrecognised address family $family"; + } +} + =head2 ( $host, $service ) = $sock->sockhost_service( $numeric ) Returns the hostname and service name of the local address (that is, the @@ -652,7 +669,7 @@ =head2 $addr = $sock->sockhost -Return the numeric form of the local address +Return the numeric form of the local address as a textual representation =head2 $port = $sock->sockport @@ -674,6 +691,14 @@ sub sockhostname { my $self = shift; ( $self->_get_host_service( $self->sockname, 0, NIx_NOSERV ) )[0] } sub sockservice { my $self = shift; ( $self->_get_host_service( $self->sockname, 0, NIx_NOHOST ) )[1] } +=head2 $addr = $sock->sockaddr + +Return the local address as a binary octet string + +=cut + +sub sockaddr { my $self = shift; _unpack_sockaddr $self->sockname } + =head2 ( $host, $service ) = $sock->peerhost_service( $numeric ) Returns the hostname and service name of the peer address (that is, the @@ -697,7 +722,7 @@ =head2 $addr = $sock->peerhost -Return the numeric form of the peer address +Return the numeric form of the peer address as a textual representation =head2 $port = $sock->peerport @@ -719,6 +744,14 @@ sub peerhostname { my $self = shift; ( $self->_get_host_service( $self->peername, 0, NIx_NOSERV ) )[0] } sub peerservice { my $self = shift; ( $self->_get_host_service( $self->peername, 0, NIx_NOHOST ) )[1] } +=head2 $addr = $peer->peeraddr + +Return the peer address as a binary octet string + +=cut + +sub peeraddr { my $self = shift; _unpack_sockaddr $self->peername } + # This unbelievably dodgy hack works around the bug that IO::Socket doesn't do # it # https://rt.cpan.org/Ticket/Display.html?id=61577 === modified file 't/01local-client-v4.t' --- t/01local-client-v4.t 2011-03-16 12:38:26 +0000 +++ t/01local-client-v4.t 2012-02-17 00:10:30 +0000 @@ -1,7 +1,7 @@ #!/usr/bin/perl -w use strict; -use Test::More tests => 16; +use Test::More tests => 20; use IO::Socket::IP; @@ -45,6 +45,10 @@ is( $socket->peerhost, "127.0.0.1", "\$socket->peerhost for $socktype" ); is( $socket->peerport, $testserver->sockport, "\$socket->peerport for $socktype" ); + # Unpack just so it pretty prints without wrecking the terminal if it fails + is( unpack("H*", $socket->sockaddr), "7f000001", "\$socket->sockaddr for $socktype" ); + is( unpack("H*", $socket->peeraddr), "7f000001", "\$socket->peeraddr for $socktype" ); + # Can't easily test the non-numeric versions without relying on the system's # ability to resolve the name "localhost" } === modified file 't/02local-server-v4.t' --- t/02local-server-v4.t 2011-03-16 12:38:26 +0000 +++ t/02local-server-v4.t 2012-02-17 00:10:30 +0000 @@ -1,7 +1,7 @@ #!/usr/bin/perl -w use strict; -use Test::More tests => 26; +use Test::More tests => 30; use IO::Socket::IP; @@ -51,4 +51,8 @@ is( $testclient->sockport, $socket->peerport, "\$testclient->sockport for $socktype" ); is( $testclient->peerport, $socket->sockport, "\$testclient->peerport for $socktype" ); + + # Unpack just so it pretty prints without wrecking the terminal if it fails + is( unpack("H*", $testclient->sockaddr), "7f000001", "\$testclient->sockaddr for $socktype" ); + is( unpack("H*", $testclient->peeraddr), "7f000001", "\$testclient->peeraddr for $socktype" ); } === modified file 't/04local-client-v6.t' --- t/04local-client-v6.t 2012-02-03 17:14:46 +0000 +++ t/04local-client-v6.t 2012-02-17 00:10:30 +0000 @@ -12,7 +12,7 @@ eval { IO::Socket::IP->new( LocalHost => "::1" ) } or plan skip_all => "Unable to bind to ::1"; -plan tests => 16; +plan tests => 20; # Unpack just ip6_addr and port because other fields might not match end to end sub unpack_sockaddr_in6_addrport { @@ -60,6 +60,10 @@ is( $socket->peerhost, "::1", "\$socket->peerhost for $socktype" ); is( $socket->peerport, $testport, "\$socket->peerport for $socktype" ); + # Unpack just so it pretty prints without wrecking the terminal if it fails + is( unpack("H*", $socket->sockaddr), "0000"x7 . "0001", "\$socket->sockaddr for $socktype" ); + is( unpack("H*", $socket->peeraddr), "0000"x7 . "0001", "\$socket->peeraddr for $socktype" ); + # Can't easily test the non-numeric versions without relying on the system's # ability to resolve the name "localhost" } === modified file 't/05local-server-v6.t' --- t/05local-server-v6.t 2012-02-03 17:14:46 +0000 +++ t/05local-server-v6.t 2012-02-17 00:10:30 +0000 @@ -12,7 +12,7 @@ eval { IO::Socket::IP->new( LocalHost => "::1" ) } or plan skip_all => "Unable to bind to ::1"; -plan tests => 26; +plan tests => 30; # Unpack just ip6_addr and port because other fields might not match end to end sub unpack_sockaddr_in6_addrport { @@ -64,4 +64,8 @@ is( $testclient->sockport, $peerport, "\$testclient->sockport for $socktype" ); is( $testclient->peerport, $sockport, "\$testclient->peerport for $socktype" ); + + # Unpack just so it pretty prints without wrecking the terminal if it fails + is( unpack("H*", $testclient->sockaddr), "0000"x7 . "0001", "\$testclient->sockaddr for $socktype" ); + is( unpack("H*", $testclient->peeraddr), "0000"x7 . "0001", "\$testclient->peeraddr for $socktype" ); }
From zefram [...] fysh.org Fri Feb 17 02: 59:58 2012
MIME-Version: 1.0
X-Spam-Status: No, score=-3.905 tagged_above=-99.9 required=10 tests=[AWL=-2.005, BAYES_00=-1.9] autolearn=ham
In-Reply-To: <rt-3.8.HEAD-10814-1329437571-1661.75071-6-0 [...] rt.cpan.org>
Content-Disposition: inline
X-Spam-Flag: NO
References: <RT-Ticket-75071 [...] rt.cpan.org> <20120216203428.GA14008 [...] lake.fysh.org> <rt-3.8.HEAD-10814-1329437571-1661.75071-6-0 [...] rt.cpan.org>
X-Virus-Scanned: Debian amavisd-new at bestpractical.com
Message-ID: <20120217075934.GA10262 [...] lake.fysh.org>
Content-Type: text/plain; charset="utf-8"
X-RT-Original-Encoding: utf-8
X-Spam-Score: -3.905
Received: from localhost (localhost [127.0.0.1]) by hipster.bestpractical.com (Postfix) with ESMTP id 3A66E241663 for <cpan-bug+IO-Socket-IP [...] hipster.bestpractical.com>; Fri, 17 Feb 2012 02:59:58 -0500 (EST)
Received: from hipster.bestpractical.com ([127.0.0.1]) by localhost (hipster.bestpractical.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id N0CtPl0Vfxpn for <cpan-bug+IO-Socket-IP [...] hipster.bestpractical.com>; Fri, 17 Feb 2012 02:59:53 -0500 (EST)
Received: from la.mx.develooper.com (x1.develooper.com [207.171.7.70]) by hipster.bestpractical.com (Postfix) with SMTP id 3E0792416C2 for <bug-IO-Socket-IP [...] rt.cpan.org>; Fri, 17 Feb 2012 02:59:52 -0500 (EST)
Received: (qmail 19698 invoked by uid 103); 17 Feb 2012 07:59:51 -0000
Received: from x16.dev (10.0.100.26) by x1.dev with QMQP; 17 Feb 2012 07:59:51 -0000
Received: from lake.fysh.org (HELO lake.fysh.org) (81.94.195.195) by 16.mx.develooper.com (qpsmtpd/0.80/v0.80-19-gf52d165) with ESMTP; Thu, 16 Feb 2012 23:59:46 -0800
Received: from zefram by lake.fysh.org with local (Exim 4.72 #1 (Debian)) id 1RyIj8-0002l1-BX; Fri, 17 Feb 2012 07:59:34 +0000
Delivered-To: cpan-bug+IO-Socket-IP [...] hipster.bestpractical.com
Subject: Re: [rt.cpan.org #75071] missing peeraddr and sockaddr methods
Return-Path: <zefram [...] fysh.org>
X-Spam-Check-BY: 16.mx.develooper.com
X-Original-To: cpan-bug+IO-Socket-IP [...] hipster.bestpractical.com
X-RT-Mail-Extension: io-socket-ip
Date: Fri, 17 Feb 2012 07:59:34 +0000
X-Spam-Level:
To: Paul Evans via RT <bug-IO-Socket-IP [...] rt.cpan.org>
From: Zefram <zefram [...] fysh.org>
RT-Message-ID: <rt-3.8.HEAD-10809-1329465598-112.75071-0-0 [...] rt.cpan.org>
Content-Length: 284
Download (untitled) / with headers
text/plain 284b
Paul Evans via RT wrote: Show quoted text
>+ return ( Socket::unpack_sockaddr_in $addr )[1];
... Show quoted text
>+ return ( Socket::unpack_sockaddr_in6 $addr )[1];
Are these functions (especially the latter) guaranteed to exist? If not, you'll get a compile error due to calling without parens. -zefram
MIME-Version: 1.0
In-Reply-To: <rt-3.8.HEAD-10809-1329465598-112.75071-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
References: <RT-Ticket-75071 [...] rt.cpan.org> <20120216203428.GA14008 [...] lake.fysh.org> <rt-3.8.HEAD-10814-1329437571-1661.75071-6-0 [...] rt.cpan.org> <20120217075934.GA10262 [...] lake.fysh.org> <rt-3.8.HEAD-10809-1329465598-112.75071-0-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="UTF-8"
Message-ID: <rt-3.8.HEAD-10809-1329477656-30.75071-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 680
Download (untitled) / with headers
text/plain 680b
On Fri Feb 17 02:59:58 2012, zefram@fysh.org wrote: Show quoted text
> Paul Evans via RT wrote:
> >+ return ( Socket::unpack_sockaddr_in $addr )[1];
> ...
> >+ return ( Socket::unpack_sockaddr_in6 $addr )[1];
> > Are these functions (especially the latter) guaranteed to exist? If
not, Show quoted text
> you'll get a compile error due to calling without parens. > > -zefram
I think they are guaranteed to exist, even if they immediately croak. It's hard to make an XS function that #ifdef-conditionally doesn't exist, so all the ones in Socket.xs definitely exist but conditionally work or croak. That said, there's no reason not to add the parens anyway, so I'll do that now. -- Paul Evans
MIME-Version: 1.0
In-Reply-To: <20120216203428.GA14008 [...] lake.fysh.org>
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
References: <20120216203428.GA14008 [...] lake.fysh.org>
Content-Type: text/plain; charset="UTF-8"
Message-ID: <rt-3.8.HEAD-10815-1331409116-1253.75071-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 38
Now released in 0.09. -- Paul Evans


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.