From 358e98d497661683a5ea74c0705d35f062184f56 Mon Sep 17 00:00:00 2001 From: jsatoh Date: Sun, 22 Sep 2013 15:00:57 +0000 Subject: [PATCH] 2013-09-22 Junichi Satoh * tentacle_client: Upgraded to 0.4.0. (Imported from trunk of tentacled repository.) Added IPv6 support. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@8797 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_agents/unix/ChangeLog | 6 +++ pandora_agents/unix/tentacle_client | 60 ++++++++++++++++++++++------- 2 files changed, 52 insertions(+), 14 deletions(-) diff --git a/pandora_agents/unix/ChangeLog b/pandora_agents/unix/ChangeLog index 704a8b0501..fccef95e98 100644 --- a/pandora_agents/unix/ChangeLog +++ b/pandora_agents/unix/ChangeLog @@ -1,3 +1,9 @@ +2013-09-22 Junichi Satoh + + * tentacle_client: Upgraded to 0.4.0. (Imported from trunk of + tentacled repository.) + Added IPv6 support. + 2013-09-19 Ramon Novoa * pandora_agent_installer: Changed the bash style == to =. diff --git a/pandora_agents/unix/tentacle_client b/pandora_agents/unix/tentacle_client index d0676164ea..d798fd95af 100755 --- a/pandora_agents/unix/tentacle_client +++ b/pandora_agents/unix/tentacle_client @@ -26,7 +26,7 @@ tentacle_client - Tentacle Client =head1 VERSION -Version 0.3.0 +Version 0.4.0 =head1 USAGE @@ -50,16 +50,26 @@ Tentacle was created to replace more complex tools like SCP and FTP for simple f The client and server (B) are designed to be run from the command line or called from a shell script, and B. +If IO::Socket::INET6 is installed, the tentacle client supports IPv6. + =cut use strict; use File::Basename; use Getopt::Std; use IO::Select; -use IO::Socket::INET; +use Socket (qw(SOCK_STREAM AF_INET AF_INET6)); +my $SOCKET_MODULE = + eval { require IO::Socket::INET6 } ? 'IO::Socket::INET6' + : eval { require IO::Socket::INET } ? 'IO::Socket::INET' + : die $@; + +if ($SOCKET_MODULE eq 'IO::Socket::INET') { + print_log ("IO::Socket::INET6 is not found. IPv6 is disabled."); +} # Program version -our $VERSION = '0.3.0'; +our $VERSION = '0.4.0'; # Server address my $t_address = '127.0.0.1'; @@ -164,9 +174,10 @@ sub parse_options { # Address if (defined ($opts{'a'})) { $t_address = $opts{'a'}; - if ($t_address !~ /^[a-zA-Z\.][a-zA-Z0-9\.\-]+$/ && ($t_address !~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/ + if (($t_address !~ /^[a-zA-Z\.][a-zA-Z0-9\.\-]+$/ && ($t_address !~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/ || $1 < 0 || $1 > 255 || $2 < 0 || $2 > 255 - || $3 < 0 || $3 > 255 || $4 < 0 || $4 > 255)) { + || $3 < 0 || $3 > 255 || $4 < 0 || $4 > 255)) && + ($t_address !~ /^[0-9a-f:]+$/o)) { error ("Address $t_address is not valid."); } @@ -297,11 +308,22 @@ sub parse_options { sub start_client { # Connect to server - $t_socket = IO::Socket::INET->new ( - PeerAddr => $t_address, - PeerPort => $t_port, - Type => SOCK_STREAM - ); + if ($SOCKET_MODULE ne 'IO::Socket::INET') { + $t_socket = $SOCKET_MODULE->new ( + Domain => AF_INET6, + PeerAddr => $t_address, + PeerPort => $t_port, + Type => SOCK_STREAM + ); + } + if (! defined ($t_socket)) { + $t_socket = $SOCKET_MODULE->new ( + Domain => AF_INET, + PeerAddr => $t_address, + PeerPort => $t_port, + Type => SOCK_STREAM + ); + } if (! defined ($t_socket)) { error ("Cannot connect to $t_address on port $t_port: $!."); @@ -321,10 +343,20 @@ sub start_client { sub start_client_proxy { # Connect to proxy - $t_socket = IO::Socket::INET->new ( - PeerAddr => $t_proxy_address, - PeerPort => $t_proxy_port, - ); + if ($SOCKET_MODULE ne 'IO::Socket::INET') { + $t_socket = $SOCKET_MODULE->new ( + Domain => AF_INET6, + PeerAddr => $t_proxy_address, + PeerPort => $t_proxy_port, + ); + } + if (! defined ($t_socket)) { + $t_socket = $SOCKET_MODULE->new ( + Domain => AF_INET, + PeerAddr => $t_proxy_address, + PeerPort => $t_proxy_port, + ); + } if (! defined ($t_socket)) { error ("Cannot connect to proxy server $t_proxy_address on port $t_proxy_port: $!.");