30 lines
718 B
C
30 lines
718 B
C
#include <stdlib.h>
|
|
|
|
#include "ping/cli.h"
|
|
#include "internal/cli/messages.h"
|
|
#include "internal/ping/parse_utils.h"
|
|
|
|
int
|
|
cli_parse_destinations(int argc, char **argv, int first_arg,
|
|
struct ping_config *config)
|
|
{
|
|
if (first_arg >= argc)
|
|
return error_missing_dest();
|
|
|
|
config->nb_destinations = (size_t)(argc - first_arg);
|
|
config->destinations = malloc(config->nb_destinations
|
|
* sizeof(struct in_addr));
|
|
if (NULL == config->destinations)
|
|
return CLI_ERROR;
|
|
|
|
for (int i = first_arg; i < argc; i++)
|
|
{
|
|
if (0 != cli_parse_inet_addr(argv[i], &config->destinations[i - first_arg]))
|
|
{
|
|
free(config->destinations);
|
|
config->destinations = NULL;
|
|
return error_invalid_dest();
|
|
}
|
|
}
|
|
return CLI_SUCCESS;
|
|
}
|