From 4792992afa78d606fff35346bcce5a819fc72b69 Mon Sep 17 00:00:00 2001 From: Keith Winstein Date: Sun, 28 Apr 2013 15:33:36 -0400 Subject: [PATCH] Rename --bind-ip to --bind-server, add =ANY option, add error checking. Closes #415. --- man/mosh.1 | 21 +++++++++++++++------ scripts/mosh | 26 +++++++++++++++++--------- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/man/mosh.1 b/man/mosh.1 index f7f3efe..14405bf 100644 --- a/man/mosh.1 +++ b/man/mosh.1 @@ -129,12 +129,21 @@ server. Otherwise, \fBmosh\fP will choose a port between 60000 and 61000. .TP -.B \-\-bind\-ip={ssh|\fIIP\fP} -Bind the server to the ip of the ssh client or to IP by passing either the -s -switch (default) or -i IP to \fBmosh-server\fP. This is useful when the login -happens from an address different from the one used by the \fBmosh-client\fP. -For example, if ssh is served through \fBsslh\fP, \fBSSH_CONNECTION\fP might be -set to 127.0.0.1, but \fBmosh-server\fP can still be bound to 0.0.0.0. +.B \-\-bind\-server={ssh|any|\fIIP\fP} +Control the IP address that the \fBmosh-server\fP binds to. + +The default is `ssh', in which case the server will reply from the IP +address that the SSH connection came from (as found in the +\fBSSH_CONNECTION\fP environment variable). This is useful for +multihomed servers. + +With \-\-bind\-server=any, the server will reply on the default interface +and will not bind to a particular IP address. This can be useful if +the connection is made through \fBsslh\fP or another tool that makes +the SSH connection appear to come from localhost. + +With \-\-bind\-server=\fIIP\fP, the server will attempt to bind to the +specified IP address. .TP .B \-\-no\-init diff --git a/scripts/mosh b/scripts/mosh index 36b5c9c..4e8b796 100755 --- a/scripts/mosh +++ b/scripts/mosh @@ -71,9 +71,8 @@ qq{Usage: $0 [options] [--] [user@]host [command...] -p PORT[:PORT2] --port=PORT[:PORT2] server-side UDP port or range - --bind-ip={ssh|IP} bind the server to the ssh client's ip or to IP - (example: "0.0.0.0") - (default: "ssh") + --bind-server={ssh|any|IP} ask the server to reply from an IP address + (default: "ssh") --ssh=COMMAND ssh command to run when setting up session (example: "ssh -p 2222") @@ -117,7 +116,7 @@ GetOptions( 'client=s' => \$client, 'help' => \$help, 'version' => \$version, 'fake-proxy!' => \my $fake_proxy, - 'bind-ip=s' => \$bind_ip) or die $usage; + 'bind-server=s' => \$bind_ip) or die $usage; die $usage if ( defined $help ); die $version_message if ( defined $version ); @@ -154,6 +153,19 @@ if ( defined $port_request ) { delete $ENV{ 'MOSH_PREDICTION_DISPLAY' }; +my @bind_arguments; +if ( not defined $bind_ip or $bind_ip =~ m{^ssh$}i ) { + push @bind_arguments, '-s'; +} elsif ( $bind_ip =~ m{^any$}i ) { + # do nothing +} elsif ( $bind_ip =~ m{^[0-9\.]+$} ) { + push @bind_arguments, ('-i', "$bind_ip"); +} else { + print STDERR qq{$0: Unknown server binding option: $bind_ip\n}; + + die $usage; +} + if ( defined $fake_proxy ) { use Errno qw(EINTR); use IO::Socket::INET; @@ -232,11 +244,7 @@ if ( $pid == 0 ) { # child push @server, ( '-c', $colors ); - if ( not defined $bind_ip or $bind_ip =~ 'ssh' ) { - push @server , '-s'; - } else { - push @server, ('-i', "$bind_ip"); - } + push @server, @bind_arguments; if ( defined $port_request ) { push @server, ( '-p', $port_request );