example/classifier/odp_classifier.c
static int parse_args(int argc, char *argv[], appl_args_t *appl_args)
{
	int opt;
	int long_index;
	size_t len;
	int i;
	int interface = 0;
	int policy = 0;
	int ret = 0;

	static const struct option longopts[] = {
		{"count", required_argument, NULL, 'c'},
		{"interface", required_argument, NULL, 'i'},
		{"policy", required_argument, NULL, 'p'},
		{"mode", required_argument, NULL, 'm'},
		{"time", required_argument, NULL, 't'},
		{"ci_pass", required_argument, NULL, 'C'},
		{"promisc_mode", no_argument, NULL, 'P'},
		{"verbose", no_argument, NULL, 'v'},
		{"help", no_argument, NULL, 'h'},
		{NULL, 0, NULL, 0}
	};

	static const char *shortopts = "+c:t:i:p:m:t:C:Pvh";

	appl_args->cpu_count = 1; /* Use one worker by default */
	appl_args->verbose = 0;
	appl_args->promisc_mode = 0;

	while (ret == 0) {
		opt = getopt_long(argc, argv, shortopts,
				  longopts, &long_index);

		if (opt == -1)
			break;	/* No more options */

		switch (opt) {
		case 'c':
			appl_args->cpu_count = atoi(optarg);
			break;
		case 'p':
			if (parse_pmr_policy(appl_args, optarg)) {
				ret = -1;
				break;
			}
			policy = 1;
			break;
		case 't':
			appl_args->time = atoi(optarg);
			break;
		case 'i':
			len = strlen(optarg);
			if (len == 0) {
				ret = -1;
				break;
			}
			len += 1;	/* add room for '\0' */

			appl_args->if_name = malloc(len);
			if (appl_args->if_name == NULL) {
				ret = -1;
				break;
			}

			strcpy(appl_args->if_name, optarg);
			interface = 1;
			break;
		case 'm':
			i = atoi(optarg);
			if (i == 0)
				appl_args->appl_mode = APPL_MODE_DROP;
			else
				appl_args->appl_mode = APPL_MODE_REPLY;
			break;
		case 'C':
			if (parse_policy_ci_pass_count(appl_args, optarg)) {
				ret = -1;
				break;
			}
			break;
		case 'P':
			appl_args->promisc_mode = 1;
			break;
		case 'v':
			appl_args->verbose = 1;
			break;
		case 'h':
			ret = -1;
			break;
		default:
			break;
		}
	}

	if (!interface || !policy)
		ret = -1;

	if (appl_args->if_name == NULL)
		ret = -1;

	if (ret) {
		usage();

		if (appl_args->if_name)
			free(appl_args->if_name);
	}

	/* reset optind from the getopt lib */
	optind = 1;

	return ret;
}
/**
 * Parse and store the command line arguments
 *
 * @param argc       argument count
 * @param argv[]     argument vector
 * @param appl_args  Store application arguments here
 */
Parse and store the command line arguments
@param argc       argument count
@param argv[]     argument vector
@param appl_args  Store application arguments here
Parse and store the command line arguments @param argc argument count @param argv [] argument vector @param appl_args Store application arguments here
static int parse_args(int argc, char *argv[], appl_args_t *appl_args)
{
	int opt;
	int long_index;
	size_t len;
	int i;
	int interface = 0;
	int policy = 0;
	int ret = 0;
	static const struct option longopts[] = {
		{"count", required_argument, NULL, 'c'},
		{"interface", required_argument, NULL, 'i'},
		{"policy", required_argument, NULL, 'p'},
		{"mode", required_argument, NULL, 'm'},
		{"time", required_argument, NULL, 't'},
		{"ci_pass", required_argument, NULL, 'C'},
		{"promisc_mode", no_argument, NULL, 'P'},
		{"verbose", no_argument, NULL, 'v'},
		{"help", no_argument, NULL, 'h'},
		{NULL, 0, NULL, 0}
	};
	static const char *shortopts = "+c:t:i:p:m:t:C:Pvh";
	appl_args->cpu_count = 1; 
	appl_args->verbose = 0;
	appl_args->promisc_mode = 0;
	while (ret == 0) {
		opt = getopt_long(argc, argv, shortopts,
				  longopts, &long_index);
		if (opt == -1)
			break;	
		switch (opt) {
		case 'c':
			appl_args->cpu_count = atoi(optarg);
			break;
		case 'p':
			if (parse_pmr_policy(appl_args, optarg)) {
				ret = -1;
				break;
			}
			policy = 1;
			break;
		case 't':
			appl_args->time = atoi(optarg);
			break;
		case 'i':
			len = strlen(optarg);
			if (len == 0) {
				ret = -1;
				break;
			}
			len += 1;	
			appl_args->if_name = malloc(len);
			if (appl_args->if_name == NULL) {
				ret = -1;
				break;
			}
			strcpy(appl_args->if_name, optarg);
			interface = 1;
			break;
		case 'm':
			i = atoi(optarg);
			if (i == 0)
				appl_args->appl_mode = APPL_MODE_DROP;
			else
				appl_args->appl_mode = APPL_MODE_REPLY;
			break;
		case 'C':
			if (parse_policy_ci_pass_count(appl_args, optarg)) {
				ret = -1;
				break;
			}
			break;
		case 'P':
			appl_args->promisc_mode = 1;
			break;
		case 'v':
			appl_args->verbose = 1;
			break;
		case 'h':
			ret = -1;
			break;
		default:
			break;
		}
	}
	if (!interface || !policy)
		ret = -1;
	if (appl_args->if_name == NULL)
		ret = -1;
	if (ret) {
		usage();
		if (appl_args->if_name)
			free(appl_args->if_name);
	}
	optind = 1;
	return ret;
}
static int parse_args ( int argc , char * argv [ ] , appl_args_t * appl_args ) { int opt ; int long_index ; size_t len ; int i ; int interface = 0 ; int policy = 0 ; int ret = 0 ; static const struct option longopts [ ] = { { " " , required_argument , NULL , ' ' } , { " " , required_argument , NULL , ' ' } , { " " , required_argument , NULL , ' ' } , { " " , required_argument , NULL , ' ' } , { " " , required_argument , NULL , ' ' } , { " " , required_argument , NULL , ' ' } , { " " , no_argument , NULL , ' ' } , { " " , no_argument , NULL , ' ' } , { " " , no_argument , NULL , ' ' } , { NULL , 0 , NULL , 0 } } ; static const char * shortopts = " " ; appl_args -> cpu_count = 1 ; appl_args -> verbose = 0 ; appl_args -> promisc_mode = 0 ; while ( ret == 0 ) { opt = getopt_long ( argc , argv , shortopts , longopts , & long_index ) ; if ( opt == -1 ) break ; switch ( opt ) { case ' ' : appl_args -> cpu_count = atoi ( optarg ) ; break ; case ' ' : if ( parse_pmr_policy ( appl_args , optarg ) ) { ret = -1 ; break ; } policy = 1 ; break ; case ' ' : appl_args -> time = atoi ( optarg ) ; break ; case ' ' : len = strlen ( optarg ) ; if ( len == 0 ) { ret = -1 ; break ; } len += 1 ; appl_args -> if_name = malloc ( len ) ; if ( appl_args -> if_name == NULL ) { ret = -1 ; break ; } strcpy ( appl_args -> if_name , optarg ) ; interface = 1 ; break ; case ' ' : i = atoi ( optarg ) ; if ( i == 0 ) appl_args -> appl_mode = APPL_MODE_DROP ; else appl_args -> appl_mode = APPL_MODE_REPLY ; break ; case ' ' : if ( parse_policy_ci_pass_count ( appl_args , optarg ) ) { ret = -1 ; break ; } break ; case ' ' : appl_args -> promisc_mode = 1 ; break ; case ' ' : appl_args -> verbose = 1 ; break ; case ' ' : ret = -1 ; break ; default : break ; } } if ( ! interface || ! policy ) ret = -1 ; if ( appl_args -> if_name == NULL ) ret = -1 ; if ( ret ) { usage ( ) ; if ( appl_args -> if_name ) free ( appl_args -> if_name ) ; } optind = 1 ; return ret ; }
Parse and store the command line arguments
 @param argc       argument count
 @param argv[]     argument vector
 @param appl_args  Store application arguments here
Parse and store the command line arguments @param argc argument count @param argv [] argument vector @param appl_args Store application arguments here
/* Use one worker by default */ /* No more options */ /* add room for '\0' */ /* reset optind from the getopt lib */