55 lines
1.7 KiB
C
55 lines
1.7 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", 1,
|
|
GRP},
|
|
{"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}
|
|
#undef GRP
|
|
};
|
|
|
|
#define OPT_NB 9
|
|
|
|
#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);
|