Subject: | BindAddress functionality not implemented |
We really would like to see BindAddress support in this library so that we don't have to maintain local patches to all installations. I have attached a patch that implements it in version 1.25.
Regards,
Matthew Hunt.
--- ./Perl.pm Wed Feb 11 16:48:02 2004
+++ ./Perl.pm Wed Feb 11 16:51:00 2004
@@ -223,10 +223,19 @@
if ($ssh->{config}->get('privileged')) {
my $p;
my $proto = getprotobyname('tcp');
+ my $addr = $ssh->{config}->get('bind_address');
+ my $paddr;
+ if ($addr) {
+ my $iaddr = inet_aton($addr);
+ $paddr = sockaddr_in($p, $iaddr);
+ }
+ else {
+ $paddr = sockaddr_in($p, INADDR_ANY);
+ }
for ($p = 1023; $p > 512; $p--) {
socket($sock, AF_INET, SOCK_STREAM, $proto) ||
croak "Net::SSH: Can't create socket: $!";
- last if bind($sock, sockaddr_in($p, INADDR_ANY));
+ last if bind($sock, $paddr);
if ($! =~ /Address already in use/i) {
close($sock);
next;
@@ -239,6 +248,16 @@
else {
socket($sock, AF_INET, SOCK_STREAM, 0) ||
croak "Net::SSH: Can't create socket: $!";
+
+ my $addr = $ssh->{config}->get('bind_address');
+ if ($addr) {
+ my $iaddr = inet_aton($addr);
+ my $paddr;
+ for (my $p = 10000; $p < 65535; $p++) {
+ $paddr = sockaddr_in($p, $iaddr);
+ last if bind($sock, $paddr);
+ }
+ }
}
$sock;
}
--- ./Perl/Config.pm Wed Feb 11 16:48:10 2004
+++ ./Perl/Config.pm Wed Feb 11 16:47:03 2004
@@ -8,6 +8,7 @@
use Carp qw( croak );
%DIRECTIVES = (
+ BindAddress => [ \&_set_str, 'bind_address' ],
Host => [ \&_host ],
BatchMode => [ \&_batch_mode ],
ChallengeResponseAuthentication => [ \&_set_str, 'auth_ch_res' ],