net-tools/src/main.c
2026-03-12 16:12:18 +01:00

44 lines
818 B
C

#include <libgen.h>
#include <stdlib.h>
#include <string.h>
#include "cli.h"
#include "ping.h"
#include "version_gen.h"
/* Forward declarations */
static int init_prog_name(char *name);
t_prog_name g_prog_name = {NULL, NULL};
/* -------------------- */
int
main(int argc, char **argv)
{
t_ping_config config;
int ret;
if (0 != init_prog_name(argv[0]))
return EXIT_FAILURE;
ret = cli_parse_arguments(argc, argv, &config);
if (ret != CLI_SUCCESS)
goto cleanup;
ret = ping_run(&config);
cleanup:
cli_config_free(&config);
free(g_prog_name.alloc);
return (ret == CLI_ERROR) ? EXIT_FAILURE : EXIT_SUCCESS;
}
static int
init_prog_name(char *name)
{
char *path_dup = strdup(name);
if (NULL == path_dup)
return 1;
g_prog_name.alloc = path_dup;
g_prog_name.name = basename(path_dup);
return 0;
}