53 lines
1.6 KiB
C
53 lines
1.6 KiB
C
#pragma once
|
|
|
|
#include <stdint.h>
|
|
typedef struct {
|
|
char *name;
|
|
char opt;
|
|
char *doc;
|
|
uint8_t arg_nb;
|
|
uint8_t grp;
|
|
} options_t;
|
|
|
|
static options_t options[] = {
|
|
#define GRP 0 // AKA random useless sh*t
|
|
{"usage", 'u', "give a short usage message", 0, GRP},
|
|
{"help", '?', "give this help list", 0, GRP},
|
|
{"version", 'V', "print program version", 0, GRP},
|
|
#undef GRP
|
|
#define GRP 1 // AKA mandatory
|
|
{"verbose", 'v', "verbose output", 0, GRP},
|
|
#undef GRP
|
|
#define GRP 2 // AKA bonus
|
|
{"count", 'c', "stop after sending NUMBER packets (--count=NUMBER)", 1,
|
|
GRP},
|
|
{"size", 's', "send NUMBER data octets (--size=NUMBER)", 1, GRP},
|
|
{"timeout", 'w', "stop after N seconds (--timeout=N)", 1, GRP}
|
|
#undef GRP
|
|
};
|
|
|
|
#define OPT_NB 5
|
|
|
|
#define FT_PING_V 0.1
|
|
|
|
#define OPT_WHILE \
|
|
int i = 0; \
|
|
while (i < OPT_NB)
|
|
|
|
#define OPT_HANDLE(i) \
|
|
if (options[i].arg_nb == 1) { \
|
|
if (!(av + 1) || !*(av + 1)) { \
|
|
return EX_USAGE; \
|
|
} \
|
|
args->arg[i] = *(av + 1); \
|
|
} \
|
|
args->opts[i] = true;
|
|
|
|
/**
|
|
* @brief Can be used to print the help message if no host (or addr) are
|
|
* provided
|
|
*/
|
|
void print_no_host(char *av);
|
|
|
|
void print_help(void);
|