keygen/src/main.c
/**
 * parse_args() - Parse input parameters
 * @argc: The argumnet count provided by main
 * @argv: The argument vector provided by main
 * @ipv6_network: The IPv6 network name to return
 * @enftun_cfg_file: The enftun config filename to return
 * @api_email: The email to use for authorization (return)
 *
 * Parses input parameters and sets ipv6_network, enftun_cfg_file and api_email to
 * newly allocated char pointers. If a parameter is not found the respective return
 * value will not be written to.
 *
 * Return: 1 on success (all required parameters found) and 0 on failure
 */


Parses input parameters and sets ipv6_network, enftun_cfg_file and api_email to
newly allocated char pointers. If a parameter is not found the respective return
value will not be written to.

1 on success (all required parameters found) and 0 on failure
Parses input parameters and sets ipv6_network enftun_cfg_file and api_email to newly allocated char pointers . If a parameter is not found the respective return value will not be written to . 1 on success ( all required parameters found ) and 0 on failure
static int parse_args(int argc, char **argv, char **ipv6_network, char **enftun_cfg_file, char **api_email, char **enftun_path)
{
    int c;
    const char *enftun_def_path = "/etc/enftun/";
    opterr = 0;
    while ((c = getopt (argc, argv, "a:c:u:e:")) != -1)
        switch (c)
        {
        case 'a':
            *ipv6_network = malloc(strlen(optarg) + 1);
            strcpy(*ipv6_network, optarg);
            break;
        case 'c':
            *enftun_cfg_file = malloc(strlen(optarg) + 1);
            strcpy(*enftun_cfg_file, optarg);
            break;
        case 'u':
            *api_email = malloc(strlen(optarg) + 1);
            strcpy(*api_email, optarg);
            break;
        case 'e':
            *enftun_path = malloc(strlen(optarg) + 1);
            strcpy(*enftun_path, optarg);
            break;
        case '?':
            if (optopt == 'a' || optopt == 'c' || optopt == 'u')
                fprintf (stderr, "Option -%c requires an argument.\n", optopt);
            else if (isprint (optopt))
                fprintf (stderr, "Unknown option `-%c'.\n", optopt);
            else
                fprintf (stderr,
                         "Unknown option character `\\x%x'.\n",
                         optopt);
        default:
            return 1;
        }
    if (!*enftun_path) {
        *enftun_path = malloc(strlen(enftun_def_path) + 1);
        strcpy(*enftun_path, enftun_def_path);
    }
    return *ipv6_network && *enftun_cfg_file && *api_email && *enftun_path;
}
static int parse_args ( int argc , char * * argv , char * * ipv6_network , char * * enftun_cfg_file , char * * api_email , char * * enftun_path ) { int c ; const char * enftun_def_path = " " ; opterr = 0 ; while ( ( c = getopt ( argc , argv , " " ) ) != -1 ) switch ( c ) { case ' ' : * ipv6_network = malloc ( strlen ( optarg ) + 1 ) ; strcpy ( * ipv6_network , optarg ) ; break ; case ' ' : * enftun_cfg_file = malloc ( strlen ( optarg ) + 1 ) ; strcpy ( * enftun_cfg_file , optarg ) ; break ; case ' ' : * api_email = malloc ( strlen ( optarg ) + 1 ) ; strcpy ( * api_email , optarg ) ; break ; case ' ' : * enftun_path = malloc ( strlen ( optarg ) + 1 ) ; strcpy ( * enftun_path , optarg ) ; break ; case ' ' : if ( optopt == ' ' || optopt == ' ' || optopt == ' ' ) fprintf ( stderr , " \n " , optopt ) ; else if ( isprint ( optopt ) ) fprintf ( stderr , " \n " , optopt ) ; else fprintf ( stderr , " \\ \n " , optopt ) ; default : return 1 ; } if ( ! * enftun_path ) { * enftun_path = malloc ( strlen ( enftun_def_path ) + 1 ) ; strcpy ( * enftun_path , enftun_def_path ) ; } return * ipv6_network && * enftun_cfg_file && * api_email && * enftun_path ; }
parse_args() - Parse input parameters
 @argc: The argumnet count provided by main
 @argv: The argument vector provided by main
 @ipv6_network: The IPv6 network name to return
 @enftun_cfg_file: The enftun config filename to return
 @api_email: The email to use for authorization (return)
parse_args () - Parse input parameters @argc : The argumnet count provided by main @argv : The argument vector provided by main @ipv6_network : The IPv6 network name to return @enftun_cfg_file : The enftun config filename to return @api_email : The email to use for authorization ( return )
/* Fall through */ /* Use the default enftun path if none is set */