Skip Menu |

This queue is for tickets about the Net-Telnet CPAN distribution.

Report information
The Basics
Id: 79961
Status: resolved
Priority: 0/
Queue: Net-Telnet

People
Owner: Nobody in particular
Requestors: VINSWORLD [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 3.03
Fixed in: 3.04



Subject: IPv6 Support - with patch!
The current version of Net::Telnet (3.03) does not support IPv6 and uses IPv4 only Socket routines. The attached patch adds IPv6 support by using IO::Socket::IP in lieu of IO::Socket::INET and getaddrinfo() in lieu of inet_aton() and sockaddr_in().
Subject: Telnet.patch
--- lib\Net\Telnet.pm Tue Jul 16 20:30:42 2002 +++ lib\Net\Telnet.pm Tue Oct 02 08:55:26 2012 @@ -29,14 +29,14 @@ ## Module import. use Exporter (); -use Socket qw(AF_INET SOCK_STREAM inet_aton sockaddr_in); +use Socket qw(AF_INET AF_INET6 SOCK_STREAM :addrinfo); use Symbol qw(qualify); ## Base classes. use vars qw(@ISA); @ISA = qw(Exporter); if (&_io_socket_include) { # successfully required module IO::Socket - push @ISA, "IO::Socket::INET"; + push @ISA, "IO::Socket::IP"; } else { # perl version < 5.004 require FileHandle; @@ -63,6 +63,7 @@ my ($class) = @_; my ( $errmode, + $family, $fh_open, $host, $self, @@ -82,6 +83,7 @@ eofile => 1, errormode => "die", errormsg => "", + family => AF_INET, fdmask => '', host => "localhost", inputlog => '', @@ -140,6 +142,9 @@ elsif (/^-?errmode$/i) { $errmode = $args{$_}; } + elsif (/^-?family$/i) { + $family = $args{$_} + } elsif (/^-?fhopen$/i) { $fh_open = $args{$_}; } @@ -190,6 +195,9 @@ } elsif (defined $host) { # user wants us to open a connection to host $self->host($host); + if (defined($family)) { + $self->family($family) + } $self->open or return; } @@ -885,6 +893,34 @@ @lines; } # end sub getlines +sub family { + my ($self, $family) = @_; + my ( + $prev, + $s, + ); + + $s = *$self->{net_telnet}; + $prev = $s->{family}; + + if (@_ >= 2) { + unless (defined $family) { + $family = ""; + } + if ($family =~ /^[46]$/) { + if ($family == 4) { + $s->{family} = AF_INET + } else { + $s->{family} = AF_INET6 + } + } else { + &_croak($self, "bad family \"$family\" given " . + "to " . ref($self) . "::family()"); + } + } + + $prev; +} # end sub family sub host { my ($self, $host) = @_; @@ -1200,6 +1236,7 @@ my ( $errmode, $errno, + $family, $host, $ip_addr, $port, @@ -1233,6 +1270,10 @@ $self->port($args{$_}) or return; } + elsif (/^-?family$/i) { + $self->family($args{$_}) + or return; + } elsif (/^-?timeout$/i) { $timeout = &_parse_timeout($self, $args{$_}); } @@ -1250,6 +1291,7 @@ ## Get host and port. $host = $self->host; $port = $self->port; + $family = $self->family; ## Ensure we're already closed. $self->close; @@ -1275,15 +1317,20 @@ alarm $timeout; ## Lookup server's IP address. - $ip_addr = inet_aton $host - or die "unknown remote host: $host\n"; + my ($err, @res) = getaddrinfo($host, $port, {socktype => SOCK_STREAM, family => $family}) + or die "error - getaddrinfo(): $host\n"; + if (defined($res[0])) { + $ip_addr = $res[0]->{addr} + } else { + die "unknown remote host: $host\n"; + } ## Create a socket and attach the filehandle to it. - socket $self, AF_INET, SOCK_STREAM, 0 + socket $self, $family, SOCK_STREAM, 0 or die "problem creating socket: $!\n"; ## Open connection to server. - connect $self, sockaddr_in($port, $ip_addr) + connect $self, $ip_addr or die "problem connecting to \"$host\", port $port: $!\n"; }; alarm 0; @@ -1311,15 +1358,20 @@ $timeout = undef; ## Lookup server's IP address. - $ip_addr = inet_aton $host - or return $self->error("unknown remote host: $host"); + my ($err, @res) = getaddrinfo($host, $port, {socktype => SOCK_STREAM, family => $family}) + or return $self->error("error - getaddrinfo(): $host"); + if (defined($res[0])) { + $ip_addr = $res[0]->{addr} + } else { + return $self->error("unknown remote host: $host"); + } ## Create a socket and attach the filehandle to it. - socket $self, AF_INET, SOCK_STREAM, 0 + socket $self, $family, SOCK_STREAM, 0 or return $self->error("problem creating socket: $!"); ## Open connection to server. - connect $self, sockaddr_in($port, $ip_addr) + connect $self, $ip_addr or do { $errno = "$!"; $self->close; @@ -2377,7 +2429,7 @@ sub _io_socket_include { local $SIG{"__DIE__"} = "DEFAULT"; - eval "require IO::Socket"; + eval "require IO::Socket::IP"; } # end sub io_socket_include @@ -3936,6 +3988,26 @@ This method is primarily used by this class or a sub-class to perform the user requested action when an error is encountered. + +=back + + +=over 4 + +=item B<family> - address family + + $family = $obj->family; + + $prev = $obj->family($family); + +This method designates the address family for C<open()>. With no +argument it returns the current address family set in the object. With an +argument it sets the current address family to I<$family> and returns the +previous address family. You may indicate the address family using either 4 +for IPv4 or 6 for IPv6. + +The default value is C<4>. It may also be set by C<open()> +or C<new()>. =back
I added the "family" method/parameter to control IPv4/IPv6 connection via new() or open(). It is in the development version for 3.04. You can find the development version at ftp://ftp.rgrs.com Also added are methods for peerhost, peerport, sockhost, and sockport to support IPv6, because the inherited ones from IO::Socket::INET don't Thanks for submitting this request.
Subject: Re: [rt.cpan.org #79961] IPv6 Support - with patch!
Date: Wed, 16 Jan 2013 21:10:05 -0500
To: bug-Net-Telnet [...] rt.cpan.org
From: Vince <vin [...] vinsworld.com>
Jay, Been a hectic holiday season for me - sorry about the late response. My quick testing found no errors. My only suggestion is in the '_parse_family' sub, perhaps more legal values for IPv4 and IPv6: Valid values for IPv4: 4, v4, ip4, ipv4, AF_INET (constant equal to integer 2) Valid values for IPv6: 6, v6, ip6, ipv6, AF_INET6 (constant equal to integer 23) cheers. On Sat, Dec 15, 2012 at 10:48 PM, Jay Rogers via RT <bug-Net-Telnet@rt.cpan.org> wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=79961 > > > I added the "family" method/parameter to control IPv4/IPv6 connection > via new() or open(). It is in the development version for 3.04. You can > find the development version at ftp://ftp.rgrs.com Also added are > methods for peerhost, peerport, sockhost, and sockport to support IPv6, > because the inherited ones from IO::Socket::INET don't > > Thanks for submitting this request. >
Subject: Re: [rt.cpan.org #79961] IPv6 Support - with patch!
Date: Thu, 17 Jan 2013 10:13:18 -0500
To: bug-Net-Telnet [...] rt.cpan.org
From: Jay Rogers <jay [...] rgrs.com>
On Wed, Jan 16, 2013 at 9:10 PM, vinsworldcom via RT < bug-Net-Telnet@rt.cpan.org> wrote: Show quoted text
> My only suggestion is in the '_parse_family' sub, perhaps more legal > values for IPv4 and IPv6: >
Yes I originally planned on providing more than one value to specify the address family. I then realized a method, sockfamily(), was necessary to return the connected address family when "any" was chosen. To reduce confusion, I think it best that the value returned by sockfamily() should match the same v4 or v6 value the user would provide as an arg to localfamily. The code is all there but I haven't had a chance to fully test it yet. When that is done I can release it. -- Jay Rogers
Why didn't you use IO::Socket::IP as in the patch? It will probably become core in Perl 5.20.
Subject: Re: [rt.cpan.org #79961] IPv6 Support - with patch!
Date: Mon, 22 Apr 2013 10:30:53 -0400
To: bug-Net-Telnet [...] rt.cpan.org
From: Jay Rogers <jay [...] rgrs.com>
Alexander, you ask why I didn't use IO::Socket::IP for IPv6 support. Net::Telnet does not require any libraries that don't already come with a standard Perl distribution. Using IO::Socket::IP would break that. This is particularly burdensome since most users do not care about IPV6. Also Net::Telnet inherits from IO::Socket::INET. Switching to IO::Socket::IP allows for breaking existing code. -- Jay Rogers