More robust option parsing and redo wrapper

This commit is contained in:
Keith Winstein
2012-03-18 03:23:58 -04:00
parent 0e5fd920b1
commit 89d1c88bcf
2 changed files with 8 additions and 6 deletions
+3
View File
@@ -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 );
}