Clearer error message on invalid port (closes #278)
This commit is contained in:
@@ -73,7 +73,7 @@ int main( int argc, char *argv[] )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char *ip;
|
char *ip, *desired_port;
|
||||||
int port;
|
int port;
|
||||||
|
|
||||||
if ( argc - optind != 2 ) {
|
if ( argc - optind != 2 ) {
|
||||||
@@ -82,7 +82,24 @@ int main( int argc, char *argv[] )
|
|||||||
}
|
}
|
||||||
|
|
||||||
ip = argv[ optind ];
|
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 */
|
/* Read key from environment */
|
||||||
char *env_key = getenv( "MOSH_KEY" );
|
char *env_key = getenv( "MOSH_KEY" );
|
||||||
|
|||||||
Reference in New Issue
Block a user