Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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' );

In reply to Re^2: Net::SSH::Perl ConnectTimeout (ssh -o option) by codejerk
in thread Net::SSH::Perl ConnectTimeout (ssh -o option) by codejerk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (7)
As of 2024-04-24 12:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found