「🏗️」 wip: work in progress, not done yet.
This commit is contained in:
@ -23,9 +23,7 @@ static options_t options[] = {
|
||||
{"size", 's', "send NUMBER data octets", 1, GRP},
|
||||
{"timeout", 'w', "stop after N seconds", 1, GRP},
|
||||
{"ttl", 't', "specify N as time-to-live", 1, GRP},
|
||||
{"ip-timestamp", 'i',
|
||||
"IP timestamp of type FLAG, which is one of \"tsonly\" and \"tsaddr\"", 1,
|
||||
GRP}
|
||||
{"interval", 'i', "wait NUMBER seconds between sending each packet", 1, GRP}
|
||||
#undef GRP
|
||||
};
|
||||
|
||||
@ -40,23 +38,39 @@ static options_t options[] = {
|
||||
#define OPT_HANDLE(i) \
|
||||
if (options[i].arg_nb == 1) { \
|
||||
if (!(av + 1) || !*(av + 1)) { \
|
||||
print_parse_err(NEED_ARG, (*av) + 1); \
|
||||
return EX_USAGE; \
|
||||
} \
|
||||
args->arg[i] = *(av + 1); \
|
||||
int n = atoi(*(av + 1)); \
|
||||
if (n == 0) { \
|
||||
print_parse_err(ERR_ARG, (*av) + 1); \
|
||||
return EX_USAGE; \
|
||||
} \
|
||||
args->arg[i] = n; \
|
||||
} \
|
||||
args->opts[i] = true; \
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
typedef enum { MISSING_HOST, INVALID_OPT, NEED_ARG } error_t;
|
||||
typedef enum { MISSING_HOST, INVALID_OPT, NEED_ARG, ERR_ARG } error_t;
|
||||
|
||||
/**
|
||||
* @brief Can be used to print the help message if no host (or addr) are
|
||||
* provided
|
||||
* @brief Can be used to print error message when needed
|
||||
* @param err The type of error to print
|
||||
* @param opt The option that cause an error (if applicable)
|
||||
*/
|
||||
void print_parse_err(error_t err, char *opt);
|
||||
|
||||
/**
|
||||
* @brief Can be used to print the help message
|
||||
*/
|
||||
void print_help(void);
|
||||
|
||||
/**
|
||||
* @brief Can be used to print the usage help message
|
||||
*/
|
||||
void print_usage(void);
|
||||
|
||||
/**
|
||||
* @brief Can be used to print the version message
|
||||
*/
|
||||
void print_version(void);
|
||||
|
Reference in New Issue
Block a user