scripts/mosh: Add -6 option to connect with IPv6

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
This commit is contained in:
Anders Kaseorg
2013-08-17 02:29:40 -04:00
parent aeee659c28
commit a4c5829812
2 changed files with 25 additions and 3 deletions
+13
View File
@@ -120,6 +120,19 @@ Synonym for \-\-predict=always
.B \-n
Synonym for \-\-predict=never
.TP
.B --family=\fIFAMILY\fP
Force the use of a particular address family, which defaults to `inet'
(IPv4), and can also be `inet6' (IPv6; requires IO::Socket::IP).
.TP
.B -4
Synonym for \-\-family=inet
.TP
.B -6
Synonym for \-\-family=inet6
.TP
.B \-p \fIPORT\fP[:\fIPORT2\fP], \-\-port=\fIPORT\fP[:\fIPORT2\fP]
Use a particular server-side UDP port or port range,
+12 -3
View File
@@ -46,6 +46,7 @@ my $predict = undef;
my $bind_ip = undef;
my $family = 'inet';
my $port_request = undef;
my $ssh = 'ssh';
@@ -69,6 +70,8 @@ qq{Usage: $0 [options] [--] [user@]host [command...]
-n --predict=never never use local echo
--predict=experimental aggressively echo even when incorrect
-4 --family=inet use IPv4 only [default]
-6 --family=inet6 use IPv6 only
-p PORT[:PORT2]
--port=PORT[:PORT2] server-side UDP port or range
--bind-server={ssh|any|IP} ask the server to reply from an IP address
@@ -110,6 +113,9 @@ GetOptions( 'client=s' => \$client,
'port=s' => \$port_request,
'a' => sub { $predict = 'always' },
'n' => sub { $predict = 'never' },
'family=s' => \$family,
'4' => sub { $family = 'inet' },
'6' => sub { $family = 'inet6' },
'p=s' => \$port_request,
'ssh=s' => \$ssh,
'init!' => \$term_init,
@@ -168,13 +174,16 @@ if ( not defined $bind_ip or $bind_ip =~ m{^ssh$}i ) {
if ( defined $fake_proxy ) {
use Errno qw(EINTR);
BEGIN { eval { require IO::Socket::IP; IO::Socket::IP->import('-register'); }; }
use POSIX qw(_exit);
my ( $host, $port ) = @ARGV;
# Resolve hostname and connect
my $sock = IO::Socket->new( Domain => AF_INET,
Family => AF_INET,
my $afstr = 'AF_' . uc( $family );
my $af = eval { IO::Socket->$afstr } or die "$0: Invalid family $family\n";
my $sock = IO::Socket->new( Domain => $af,
Family => $af,
PeerHost => $host,
PeerPort => $port,
Proto => "tcp" )
@@ -254,7 +263,7 @@ if ( $pid == 0 ) { # child
push @server, '--', @command;
}
my $quoted_self = shell_quote( $0 );
my $quoted_self = shell_quote( $0, "--family=$family" );
exec "$ssh " . shell_quote( '-S', 'none', '-o', "ProxyCommand=$quoted_self --fake-proxy -- %h %p", '-n', '-tt', $userhost, '--', "$server " . shell_quote( @server ) );
die "Cannot exec ssh: $!\n";
} else { # parent