Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Net::SSH::Perl ConnectTimeout (ssh -o option)

by neilwatson (Curate)
on Aug 09, 2006 at 19:49 UTC ( #566471=note: print w/ replies, xml ) Need Help??


in reply to Net::SSH::Perl ConnectTimeout (ssh -o option)

Perhaps you could show us your code. The fault may lie there and not in the module.

Neil Watson
watson-wilson.ca


Comment on Re: Net::SSH::Perl ConnectTimeout (ssh -o option)
Re^2: Net::SSH::Perl ConnectTimeout (ssh -o option)
by codejerk (Initiate) on Aug 10, 2006 at 13:19 UTC

    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' );
      Thanks for pointing this out. My script has the need to use the ControlMaster=auto option, but can't because it's not supported by the module. Say, any ideas when the next release is coming? And if it'll have expanded support for options? :) -dox

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://566471]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (9)
As of 2014-08-22 08:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (150 votes), past polls