Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Comment on

( #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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (3)
    As of 2018-05-21 09:16 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Notices?