Skip to content
Browse files

More robust option parsing and redo wrapper

  • Loading branch information...
1 parent 0e5fd92 commit 89d1c88bcf652d9afdf68b6a82be245040604f8f @keithw keithw committed Mar 18, 2012
Showing with 8 additions and 6 deletions.
  1. +5 −6 scripts/mosh
  2. +3 −0 src/frontend/mosh-server.cc
View
11 scripts/mosh
@@ -170,14 +170,13 @@ if ( $pid == 0 ) { # child
open STDERR, ">&", $pty_slave->fileno() or die;
close $pty_slave;
- my $s;
+ my @server = ( $server, 'new', '-s' );
+
if ( defined $port_request ) {
- $s = q{sh -c 'MOSH_PORT=$1; shift; MOSH_IP=`set -- $SSH_CONNECTION; echo $3`; exec "$@" $MOSH_IP $MOSH_PORT' -- } . $port_request . ' ' . $server;
- } else {
- # retain compatibility with older server when no port requested
- $s = q{sh -c 'exec "$@" "`set -- $SSH_CONNECTION; echo $3`"' -- } . $server;
+ push @server, ( '-p', $port_request );
}
- exec 'ssh', '-S', 'none', '-o', "ProxyCommand=$0 --fake-proxy -- %h %p", '-t', $userhost, '--', $s;
+
+ exec 'ssh', '-S', 'none', '-o', "ProxyCommand=$0 --fake-proxy -- %h %p", '-t', $userhost, '--', @server;
die "Cannot exec ssh: $!\n";
} else { # server
my ( $ip, $port, $key );
View
3 src/frontend/mosh-server.cc
@@ -80,6 +80,7 @@ string get_SSH_IP( void )
char *SSH_writable = strdup( SSH_CONNECTION );
fatal_assert( SSH_writable );
strtok( SSH_writable, " " );
+ strtok( NULL, " " );
const char *local_interface_IP = strtok( NULL, " " );
fatal_assert( local_interface_IP );
return string( local_interface_IP );
@@ -139,12 +140,14 @@ int main( int argc, char *argv[] )
/* Sanity-check arguments */
if ( desired_ip
&& ( strspn( desired_ip, "0123456789." ) != strlen( desired_ip ) ) ) {
+ fprintf( stderr, "%s: Bad IP address (%s)\n", argv[ 0 ], desired_ip );
print_usage( argv[ 0 ] );
exit( 1 );
}
if ( desired_port
&& ( strspn( desired_ip, "0123456789" ) != strlen( desired_ip ) ) ) {
+ fprintf( stderr, "%s: Bad UDP port (%s)\n", argv[ 0 ], desired_port );
print_usage( argv[ 0 ] );
exit( 1 );
}

0 comments on commit 89d1c88

Please sign in to comment.
Something went wrong with that request. Please try again.