To the best of my knowledge, the fault is not in my code. If you dig into Net::SSH::Perl's Config.pm, you can easily find the routine for parsing the -o style options. ConnectTimeout is not parsed at all, and if you dig a bit more, you'll see that the socket is not created with any sort of timeout other than the default.
My question is less about how to make Net::SSH::Perl work for me, and more about how to implement a socket timeout given the current form of Net::SSH::Perl's socket implementation. I'm curious if anyone else has ever had a need for it and attempted a modification or workaround to incorporate a timeout.
All of that said... if a code snippet is what you want, here ya go :) :
from Net::SSH::Perl::Config -
%DIRECTIVES = (
BindAddress => [ \&_set_str, 'bind_address' ],
Host => [ \&_host ],
BatchMode => [ \&_batch_mode ],
ChallengeResponseAuthentication => [ \&_set_yesno, 'auth_ch_res' ]
+,
Cipher => [ \&_cipher ],
Ciphers => [ \&_set_str, 'ciphers' ],
Compression => [ \&_set_yesno, 'compression' ],
CompressionLevel => [ \&_set_str, 'compression_level' ],
DSAAuthentication => [ \&_set_yesno, 'auth_dsa' ],
GlobalKnownHostsFile => [ \&_set_str, 'global_known_hosts' ],
HostKeyAlgorithms => [ \&_set_str, 'host_key_algorithms' ],
HostName => [ \&_set_str, 'hostname' ],
IdentityFile => [ \&_identity_file ],
NumberOfPasswordPrompts => [ \&_set_str, 'number_of_password_promp
+ts' ],
PasswordAuthentication => [ \&_set_yesno, 'auth_password' ],
PasswordPromptHost => [ \&_set_yesno, 'password_prompt_host'
+],
PasswordPromptLogin => [ \&_set_yesno, 'password_prompt_login'
+ ],
Port => [ \&_set_str, 'port' ],
Protocol => [ \&_protocol ],
RhostsAuthentication => [ \&_set_yesno, 'auth_rhosts' ],
RhostsRSAAuthentication => [ \&_set_yesno, 'auth_rhosts_rsa' ],
RSAAuthentication => [ \&_set_yesno, 'auth_rsa' ],
UsePrivilegedPort => [ \&_set_yesno, 'privileged' ],
User => [ \&_set_str, 'user' ],
UserKnownHostsFile => [ \&_set_str, 'user_known_hosts' ],
);
as you can see, the option "ConnectTimeout" is not provided for.
from Perl.pm:
sub _create_socket {
my $ssh = shift;
my $sock = gensym;
my ($p,$end,$delta) = (0,1,1); # normally we use whatever por
+t we can get
($p,$end,$delta) = (1023,512,-1) if $ssh->{config}->get('pr
+ivileged');
# allow an explicit bind address
my $addr = $ssh->{config}->get('bind_address');
$addr = inet_aton($addr) if $addr;
($p,$end,$delta) = (10000,65535,1) if $addr and not $p;
$addr ||= INADDR_ANY;
for(; $p != $end; $p += $delta) {
socket($sock, AF_INET, SOCK_STREAM, getprotobyname('tcp') || 0
+) ||
croak "Net::SSH: Can't create socket: $!";
last if not $p or bind($sock, sockaddr_in($p,$addr));
if ($! =~ /(Address|The socket name is) already in use/i) {
close($sock);
next;
}
croak "Net::SSH: Can't bind socket to port $p: $!";
}
if($p) {
$ssh->debug("Allocated local port $p.");
$ssh->{config}->set('localport', $p);
}
$sock;
}
here we see that the socket is created with the Simple Socket.pm method, with no configurable timeout.
and for fun, my usage:
use Net::SSH::Perl;
my %ssh_params = ( protocol => "2,1",
identity_files => ["/home/codejerk/.ssh/test_id_dsa"],
options => [ "BatchMode yes",
"ConnectTimeout 3",
"StrictHostKeyChecking no"],
debug => 'true'
);
|