39 lines
1 KiB
C
39 lines
1 KiB
C
#include <string.h>
|
|
#include <getopt.h>
|
|
|
|
#include "ping/cli.h"
|
|
#include "ping/ft_ping_const.h"
|
|
#include "internal/ping/cli_handlers.h"
|
|
#include "internal/ping/parse_utils.h"
|
|
#include "internal/cli/options.h"
|
|
|
|
/* Forward declaration */
|
|
static void init_config(struct ping_config *config);
|
|
/* ------------------- */
|
|
|
|
enum cli_code
|
|
cli_parse_arguments(int argc, char **argv, struct ping_config *config)
|
|
{
|
|
char opt_str[PING_OPTSTR_LEN];
|
|
struct option long_opts[PING_OPT_LEN + 1];
|
|
enum cli_code ret;
|
|
|
|
init_config(config);
|
|
ret = cli_parse(argc, argv, config, g_options, PING_OPT_LEN,
|
|
opt_str, long_opts);
|
|
if (CLI_SUCCESS != ret)
|
|
return ret;
|
|
return cli_parse_destinations(argc, argv, optind, config);
|
|
}
|
|
|
|
static void
|
|
init_config(struct ping_config *config)
|
|
{
|
|
memset(config, 0, sizeof(struct ping_config));
|
|
config->count = DEFAULT_COUNT;
|
|
config->preload = DEFAULT_PRELOAD;
|
|
config->interval = DEFAULT_INTERVAL;
|
|
config->ttl = DEFAULT_TTL;
|
|
config->packet_size = DEFAULT_PACKET_SIZE;
|
|
config->timeout = DEFAULT_TIMEOUT;
|
|
}
|