net-tools/includes/cli.h
lohhiiccc 2fc8d92e98 refactor(cli): replace runtime size vars with compile-time enum constants
Replace g_options_len and g_opt_str_len extern variables with
CLI_OPT_LEN and CLI_OPT_STR_LEN enum constants computed via X-macros.

Disables Variable Length Arrays (VLA) by enforcing the use of the -Wvla
flag in strict mode.
2026-03-03 09:06:28 +01:00

50 lines
1.3 KiB
C

#ifndef PING_CLI_H
#define PING_CLI_H
#include "ft_ping.h"
#define CLI_SUCCESS 0
#define CLI_ERROR 1
#define CLI_EXIT_SUCCESS -1
typedef int (*t_option_handler)(const char *arg, t_ping_config *config);
typedef enum e_option_arg_type
{
OPT_ARG_NONE = 0,
OPT_ARG_INT,
OPT_ARG_UINT,
OPT_ARG_SECONDS,
OPT_ARG_BYTES,
OPT_ARG_TTL,
OPT_ARG_STRING
} t_option_arg_type;
typedef struct s_option_descriptor
{
int short_opt;
const char *long_opt;
int has_arg;
t_option_handler handler;
t_option_arg_type arg_type;
const char *description;
} t_option_descriptor;
extern const t_option_descriptor g_options[];
int cli_handle_count(const char *arg, t_ping_config *config);
int cli_handle_flood(const char *arg, t_ping_config *config);
int cli_handle_help(const char *arg, t_ping_config *config);
int cli_handle_interval(const char *arg, t_ping_config *config);
int cli_handle_quiet(const char *arg, t_ping_config *config);
int cli_handle_size(const char *arg, t_ping_config *config);
int cli_handle_timeout(const char *arg, t_ping_config *config);
int cli_handle_ttl(const char *arg, t_ping_config *config);
int cli_handle_version(const char *arg, t_ping_config *config);
int cli_handle_verbose(const char *arg, t_ping_config *config);
int cli_parse_uint64(const char *s, uint64_t *out);
int cli_parse_float(const char *s, float *out);
#endif