Skip to content

Commit

Permalink
scripts/mosh: Add -6 option to connect with IPv6
Browse files Browse the repository at this point in the history
Signed-off-by: Anders Kaseorg <andersk@mit.edu>
  • Loading branch information
andersk committed Aug 17, 2013
1 parent aeee659 commit a4c5829
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
13 changes: 13 additions & 0 deletions man/mosh.1
Expand Up @@ -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,
Expand Down
15 changes: 12 additions & 3 deletions scripts/mosh
Expand Up @@ -46,6 +46,7 @@ my $predict = undef;

my $bind_ip = undef;

my $family = 'inet';
my $port_request = undef;

my $ssh = 'ssh';
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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" )
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a4c5829

Please sign in to comment.