67 lines
1.1 KiB
C
67 lines
1.1 KiB
C
#include "sysexits.h"
|
|
#include <help.h>
|
|
#include <opt_parse.h>
|
|
#include <ping.h>
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
char *exec_name;
|
|
double *times = NULL;
|
|
int rx_count = 0;
|
|
int tx_count = 0;
|
|
|
|
void init_args_t(args_t *args) {
|
|
OPT_WHILE {
|
|
args->opts[i] = false;
|
|
args->arg[i] = -1;
|
|
i++;
|
|
}
|
|
args->hosts = NULL;
|
|
}
|
|
|
|
int handle_options(args_t *args) {
|
|
if (args->opts[1]) {
|
|
print_help();
|
|
return EXIT_SUCCESS;
|
|
} else if (args->opts[0]) {
|
|
print_usage();
|
|
return EX_USAGE;
|
|
} else if (args->opts[2]) {
|
|
print_version();
|
|
return EXIT_SUCCESS;
|
|
} else if (args->opts[1]) {
|
|
print_help();
|
|
return EXIT_SUCCESS;
|
|
} else {
|
|
return ping(args);
|
|
}
|
|
}
|
|
|
|
int main(int ac, char **av) {
|
|
exec_name = *av;
|
|
|
|
args_t args;
|
|
|
|
init_args_t(&args);
|
|
|
|
if (ac > 1) {
|
|
int ret = opt_parse(av, &args);
|
|
if (ret == -1) {
|
|
free(args.hosts);
|
|
return EXIT_SUCCESS;
|
|
} else if (ret != EXIT_SUCCESS) {
|
|
free(args.hosts);
|
|
return ret;
|
|
} else {
|
|
ret = handle_options(&args);
|
|
free(args.hosts);
|
|
return ret;
|
|
}
|
|
} else {
|
|
print_parse_err(MISSING_HOST, NULL);
|
|
return EX_USAGE;
|
|
}
|
|
return EXIT_SUCCESS;
|
|
}
|