Skip to content

Commit

Permalink
Clearer error message on invalid port (closes #278)
Browse files Browse the repository at this point in the history
  • Loading branch information
keithw committed May 24, 2012
1 parent 682bbdf commit 78a5eaf
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/frontend/mosh-client.cc
Expand Up @@ -73,7 +73,7 @@ int main( int argc, char *argv[] )
}
}

char *ip;
char *ip, *desired_port;
int port;

if ( argc - optind != 2 ) {
Expand All @@ -82,7 +82,24 @@ int main( int argc, char *argv[] )
}

ip = argv[ optind ];
port = myatoi( argv[ optind + 1 ] );
desired_port = argv[ optind + 1 ];

/* Sanity-check arguments */
if ( ip
&& ( strspn( ip, "0123456789." ) != strlen( ip ) ) ) {
fprintf( stderr, "%s: Bad IP address (%s)\n\n", argv[ 0 ], ip );
usage( argv[ 0 ] );
exit( 1 );
}

if ( desired_port
&& ( strspn( desired_port, "0123456789" ) != strlen( desired_port ) ) ) {
fprintf( stderr, "%s: Bad UDP port (%s)\n\n", argv[ 0 ], desired_port );
usage( argv[ 0 ] );
exit( 1 );
}

port = myatoi( desired_port );

/* Read key from environment */
char *env_key = getenv( "MOSH_KEY" );
Expand Down

1 comment on commit 78a5eaf

@nealmcb
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick work!!
The check is appropriate for ipv4 addresses, and you don't support ipv6 yet (issue #81). So until you add ipv6 support, you might want to make the error message a bit more helpful by e.g. adding - "Only ipv4 is currently supported"

Please sign in to comment.