static void init_routing_switch_options( routing_switch_options *options, int *argc, char **argv[] ) { assert( options != NULL ); assert( argc != NULL ); assert( *argc >= 0 ); assert( argv != NULL ); // set default values options->idle_timeout = FLOW_TIMER; int argc_tmp = *argc; char *new_argv[ *argc ]; for ( int i = 0; i <= *argc; ++i ) { new_argv[ i ] = ( *argv )[ i ]; } int c; uint32_t idle_timeout; while ( ( c = getopt_long( *argc, *argv, short_options, long_options, NULL ) ) != -1 ) { switch ( c ) { case 'i': idle_timeout = ( uint32_t ) atoi( optarg ); if ( idle_timeout == 0 || idle_timeout > UINT16_MAX ) { printf( "Invalid idle_timeout value\n" ); usage(); finalize_topology_service_interface_options(); exit( EXIT_SUCCESS ); return; } options->idle_timeout = ( uint16_t ) idle_timeout; break; default: continue; } if ( optarg == 0 || strchr( new_argv[ optind - 1 ], '=' ) != NULL ) { argc_tmp -= 1; new_argv[ optind - 1 ] = NULL; } else { argc_tmp -= 2; new_argv[ optind - 1 ] = NULL; new_argv[ optind - 2 ] = NULL; } } for ( int i = 0, j = 0; i < *argc; ++i ) { if ( new_argv[ i ] != NULL ) { ( *argv )[ j ] = new_argv[ i ]; j++; } } ( *argv )[ *argc ] = NULL; *argc = argc_tmp; reset_getopt(); }
int main( int argc, char *argv[] ) { init_trema( &argc, &argv ); init_topology_service_interface_options( &argc, &argv ); init_libtopology( get_topology_service_interface_name() ); get_all_port_status( print_all_port_status, NULL); start_trema(); finalize_libtopology(); finalize_topology_service_interface_options(); return 0; }
void option_parser( int *argc, char **argv[] ) { int c; int argc_tmp = *argc; char *new_argv[ *argc ]; for ( int i = 0; i <= *argc; ++i ) { new_argv[ i ] = ( *argv )[ i ]; } while ( ( c = getopt_long( *argc, *argv, short_options, long_options, NULL ) ) != -1 ) { switch ( c ) { case 't': xfree( options.name ); options.name = xstrdup( optarg ); break; default: finalize_topology_service_interface_options(); exit( EXIT_SUCCESS ); return; } if ( optarg == 0 || strchr( new_argv[ optind - 1 ], '=' ) != NULL ) { argc_tmp -= 1; new_argv[ optind - 1 ] = NULL; } else { argc_tmp -= 2; new_argv[ optind - 1 ] = NULL; new_argv[ optind - 2 ] = NULL; } } for ( int i = 0, j = 0; i < *argc; ++i ) { if ( new_argv[ i ] != NULL ) { ( *argv )[ j ] = new_argv[ i ]; j++; } } ( *argv )[ *argc ] = NULL; *argc = argc_tmp; reset_getopt(); debug( "topology_service_interface_name=`%s'", options.name ); }
static void init_switch_options( switch_options *options, int *argc, char **argv[] ) { assert( options != NULL ); assert( argc != NULL ); assert( *argc >= 0 ); assert( argv != NULL ); // set default values options->idle_timeout = FLOW_TIMER; options->handle_arp_with_packetout = false; memset( options->slice_db_file, '\0', sizeof( options->slice_db_file ) ); memset( options->filter_db_file, '\0', sizeof( options->filter_db_file ) ); options->mode = 0; int argc_tmp = *argc; char *new_argv[ *argc ]; for ( int i = 0; i <= *argc; ++i ) { new_argv[ i ] = ( *argv )[ i ]; } int c; uint32_t idle_timeout; while ( ( c = getopt_long( *argc, *argv, short_options, long_options, NULL ) ) != -1 ) { switch ( c ) { case 'i': idle_timeout = ( uint32_t ) atoi( optarg ); if ( idle_timeout == 0 || idle_timeout > UINT16_MAX ) { printf( "Invalid idle_timeout value.\n" ); usage(); finalize_topology_service_interface_options(); exit( EXIT_SUCCESS ); return; } options->idle_timeout = ( uint16_t ) idle_timeout; break; case 'A': options->handle_arp_with_packetout = true; break; case 's': if ( optarg != NULL ) { if ( realpath( optarg, options->slice_db_file ) == NULL ) { memset( options->slice_db_file, '\0', sizeof( options->slice_db_file ) ); } } break; case 'a': if ( optarg != NULL ) { if ( realpath( optarg, options->filter_db_file ) == NULL ) { memset( options->filter_db_file, '\0', sizeof( options->filter_db_file ) ); } } break; case 'm': options->mode |= LOOSE_MAC_BASED_SLICING; break; case 'r': options->mode |= RESTRICT_HOSTS_ON_PORT; break; default: continue; } if ( optarg == 0 || strchr( new_argv[ optind - 1 ], '=' ) != NULL ) { argc_tmp -= 1; new_argv[ optind - 1 ] = NULL; } else { argc_tmp -= 2; new_argv[ optind - 1 ] = NULL; new_argv[ optind - 2 ] = NULL; } } if ( strlen( options->filter_db_file ) == 0 ) { printf( "--filter_db option is mandatory.\n" ); usage(); exit( EXIT_FAILURE ); } if ( strlen( options->slice_db_file ) == 0 ) { printf( "--slice_db option is mandatory.\n" ); usage(); exit( EXIT_FAILURE ); } for ( int i = 0, j = 0; i < *argc; ++i ) { if ( new_argv[ i ] != NULL ) { ( *argv )[ j ] = new_argv[ i ]; j++; } } ( *argv )[ *argc ] = NULL; *argc = argc_tmp; reset_getopt(); }
static void init_routing_switch_options( routing_switch_options *options, int *argc, char **argv[] ) { assert( options != NULL ); assert( argc != NULL ); assert( *argc >= 0 ); assert( argv != NULL ); // set default values options->idle_timeout = FLOW_TIMER; memset( options->authorized_host_db, '\0', sizeof( options->authorized_host_db ) ); int argc_tmp = *argc; char *new_argv[ *argc ]; for ( int i = 0; i <= *argc; ++i ) { new_argv[ i ] = ( *argv )[ i ]; } int c; uint32_t idle_timeout; while ( ( c = getopt_long( *argc, *argv, short_options, long_options, NULL ) ) != -1 ) { switch ( c ) { case 'a': if ( optarg ) { strncpy( options->authorized_host_db, optarg, PATH_MAX ); options->authorized_host_db[ PATH_MAX - 1 ] = '\0'; } break; case 'i': idle_timeout = ( uint32_t ) atoi( optarg ); if ( idle_timeout == 0 || idle_timeout > UINT16_MAX ) { printf( "Invalid idle_timeout value.\n" ); usage(); finalize_topology_service_interface_options(); exit( EXIT_FAILURE ); return; } options->idle_timeout = ( uint16_t ) idle_timeout; break; default: continue; } if ( optarg == 0 || strchr( new_argv[ optind - 1 ], '=' ) != NULL ) { argc_tmp -= 1; new_argv[ optind - 1 ] = NULL; } else { argc_tmp -= 2; new_argv[ optind - 1 ] = NULL; new_argv[ optind - 2 ] = NULL; } } if ( strlen( options->authorized_host_db ) == 0 ) { printf( "Authorized host database must be specified\n" ); usage(); finalize_topology_service_interface_options(); exit( EXIT_FAILURE ); } for ( int i = 0, j = 0; i < *argc; ++i ) { if ( new_argv[ i ] != NULL ) { ( *argv )[ j ] = new_argv[ i ]; j++; } } ( *argv )[ *argc ] = NULL; *argc = argc_tmp; reset_getopt(); }