I'm really sorry for not replying during all this time. I'm involved in
lots of project, and I had to set this one aside for a moment. But now
I'm determined to get this thing fix!

I still have beginner level in perl, and can't quite make sense of the
code you posted.

I asked the net::ssh::perl mailing list about the pb, but the only
response I got back from that time was "use fork". unfortunatly, I don't
quite get how I should use fork (if someone knows a URL where there is
good tutorial or post or something where I can learn fork, please reply
and add that link!). Anyway, I'll send another email to the list...
maybe I'll get different responses.

I'm surprised nobody got interested in this problem. Anybody had a
socket bind problem before?

John Doe a écrit :
> Am Mittwoch, 6. April 2005 12.52 schrieb gui:
> 
> This phenomen with the TIME_WAIT was my other thought to explain the behavior 
> of your script, but then I decided not to mention it because I thought that 
> the sub _create_socket code in Perl.pm will handle this:
> 
> *---- code ----*
> sub _create_socket {
>     my $ssh = shift;
>     my $sock = gensym;
> 
>  my ($p,$end,$delta) = (0,1,1); # normally we use whatever port we can get
>        ($p,$end,$delta) = (1023,512,-1) if $ssh->{config}->get('privileged');
> 
>  # 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 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;
> }
> 
> *--- code ---*
> 
> The code tries to bind to several ports (1023 down to 512).
> 
> But now, when I look again - but still not deeply enough!... (and use the 
> hint 
> the port 1023 was also tried in the _second_ "loop run")... the code seems 
> only to handle the "port already in use" case...
> 
> Please look at the above code deeper... the croak code could be the problem, 
> and a possibility could be not to croak so fast, but try port after port 
> until binding has been done or the port range has fully be tested.
> 
> I could have a deeper look myself tomorrow ...äh... après-midi, if you wish 
> (we're located in the same time zone I think).
> 
> btw - where are all the cracks who have the 
> instant-shortestpossible-100%solution for all ???
> 
> greetings joe

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to