Thanks for your explanations MNibble, I'm still not sure what to do with
 fork, but now I have an idea of how it works.

I finally got that problem solved!!!

when executing the script as root the priviliged parameters is set to 1
by default. priviliged binds you to a specific port. In order to change
that, it as to be set to 0 manually when parameting Net::SSH::Perl

my %params = (
        'priviledge'=0,
        'protocol' => 2,
        'identity_files' => [EMAIL PROTECTED],
);

MNibble a écrit :
> Gui wrote:
> 
>> 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
> 
> 
> 
> fork is only a nice way of making 2 process out off one
> 
> die $! unless defined (my $child = fork());
> if ($child == 0)
> {
>     #Everything here is "unrelateted" to the OTHER
>     print $$;
> 
> }
> else
> {
>     #OTHER
>     print $$;
> }
> unrelated is .. a bit wrong, since you just created a child process, in
> that childprocess you get the filehandles from the org. process.
> Variable you have create before the fork are "if needed also forked
> (duplicated). After the fork you have 2 processes. The parent process
> can ident his child. The var. my $child is for the parent 0 and for the
> child the pid of that child.
> 
> 
> 
> 
> 
> 

-- 
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