Rename --bind-ip to --bind-server, add =ANY option, add error checking.

Closes #415.
This commit is contained in:
Keith Winstein
2013-04-28 15:33:36 -04:00
parent fc70612de6
commit 4792992afa
2 changed files with 32 additions and 15 deletions
+15 -6
View File
@@ -129,12 +129,21 @@ server. Otherwise, \fBmosh\fP will choose a port between 60000 and
61000. 61000.
.TP .TP
.B \-\-bind\-ip={ssh|\fIIP\fP} .B \-\-bind\-server={ssh|any|\fIIP\fP}
Bind the server to the ip of the ssh client or to IP by passing either the -s Control the IP address that the \fBmosh-server\fP binds to.
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. The default is `ssh', in which case the server will reply from the IP
For example, if ssh is served through \fBsslh\fP, \fBSSH_CONNECTION\fP might be address that the SSH connection came from (as found in the
set to 127.0.0.1, but \fBmosh-server\fP can still be bound to 0.0.0.0. \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 .TP
.B \-\-no\-init .B \-\-no\-init
+16 -8
View File
@@ -71,8 +71,7 @@ qq{Usage: $0 [options] [--] [user@]host [command...]
-p PORT[:PORT2] -p PORT[:PORT2]
--port=PORT[:PORT2] server-side UDP port or range --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 --bind-server={ssh|any|IP} ask the server to reply from an IP address
(example: "0.0.0.0")
(default: "ssh") (default: "ssh")
--ssh=COMMAND ssh command to run when setting up session --ssh=COMMAND ssh command to run when setting up session
@@ -117,7 +116,7 @@ GetOptions( 'client=s' => \$client,
'help' => \$help, 'help' => \$help,
'version' => \$version, 'version' => \$version,
'fake-proxy!' => \my $fake_proxy, '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 $usage if ( defined $help );
die $version_message if ( defined $version ); die $version_message if ( defined $version );
@@ -154,6 +153,19 @@ if ( defined $port_request ) {
delete $ENV{ 'MOSH_PREDICTION_DISPLAY' }; 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 ) { if ( defined $fake_proxy ) {
use Errno qw(EINTR); use Errno qw(EINTR);
use IO::Socket::INET; use IO::Socket::INET;
@@ -232,11 +244,7 @@ if ( $pid == 0 ) { # child
push @server, ( '-c', $colors ); push @server, ( '-c', $colors );
if ( not defined $bind_ip or $bind_ip =~ 'ssh' ) { push @server, @bind_arguments;
push @server , '-s';
} else {
push @server, ('-i', "$bind_ip");
}
if ( defined $port_request ) { if ( defined $port_request ) {
push @server, ( '-p', $port_request ); push @server, ( '-p', $port_request );