net-tools/includes/internal/cli/options.h

112 lines
2.1 KiB
C

#ifndef PING_CLI_OPT_H
#define PING_CLI_OPT_H
#include <getopt.h>
#include "ft_ping_flags.h"
#define TRACK_DUP_OPT(descriptor, tracker, opt_name, opts_array) \
do { \
bitmask_index = (size_t)((descriptor) - (opts_array)); \
if (HAS_FLAG(tracker, (1ULL << bitmask_index))) \
{ \
error_duplicate_opt(opt_name); \
return CLI_ERROR; \
} \
SET_FLAG(tracker, (1ULL << bitmask_index)); \
} while (0)
#define CLI_OPTIONS_LIST \
X( \
'h', \
"help", \
no_argument, \
cli_handle_help, \
OPT_ARG_NONE, \
"Display this help and exit" \
) \
X( \
'V', \
"version", \
no_argument, \
cli_handle_version, \
OPT_ARG_NONE, \
"Display version information and exit" \
) \
X( \
'v', \
"verbose", \
no_argument, \
cli_handle_verbose, \
OPT_ARG_NONE, \
"Verbose output" \
) \
X( \
'q', \
"quiet", \
no_argument, \
cli_handle_quiet, \
OPT_ARG_NONE, \
"Quiet mode (only show summary)" \
) \
X( \
'c', \
"count", \
required_argument, \
cli_handle_count, \
OPT_ARG_UINT, \
"Stop after sending N packets" \
) \
X( \
'i', \
"interval", \
required_argument, \
cli_handle_interval, \
OPT_ARG_SECONDS, \
"Wait N seconds between packets" \
) \
X( \
't', \
"ttl", \
required_argument, \
cli_handle_ttl, \
OPT_ARG_TTL, \
"Set Time To Live" \
) \
X( \
's', \
"size", \
required_argument, \
cli_handle_size, \
OPT_ARG_BYTES, \
"Packet size in bytes" \
) \
X( \
'W', \
"timeout", \
required_argument, \
cli_handle_timeout, \
OPT_ARG_SECONDS, \
"Timeout for replies in seconds" \
) \
X( \
'f', \
"flood", \
no_argument, \
cli_handle_flood, \
OPT_ARG_NONE, \
"Flood mode" \
)
#undef X
#define X(short_opt, long_opt, has_arg, handler, arg_type, desc) + 1
enum { CLI_OPT_LEN = (0 CLI_OPTIONS_LIST) };
#undef X
#define X(short_opt, long_opt, has_arg, handler, arg_type, desc) \
+ (1 * (has_arg == no_argument) \
+ (2 * (has_arg == required_argument) \
+ (3 * (has_arg == optional_argument))))
enum { CLI_OPT_STR_LEN = (1 CLI_OPTIONS_LIST) };
/* +1 for ':' to disable getopt error messages */
#endif