Skip to content

Commit

Permalink
Rename --bind-ip to --bind-server, add =ANY option, add error checking.
Browse files Browse the repository at this point in the history
  • Loading branch information
keithw committed Apr 28, 2013
1 parent fc70612 commit 4792992
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
21 changes: 15 additions & 6 deletions man/mosh.1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 17 additions & 9 deletions scripts/mosh
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
Expand Down

0 comments on commit 4792992

Please sign in to comment.