52 lines
1.8 KiB
C
52 lines
1.8 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* parsing.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2026/03/23 14:49:36 by rparodi #+# #+# */
|
|
/* Updated: 2026/03/30 19:07:53 by rparodi ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "parsing.h"
|
|
#include "macro.h"
|
|
#include "struct.h"
|
|
#include <stdlib.h>
|
|
#include <getopt.h>
|
|
|
|
static void _init_flags(t_flags *flags) {
|
|
flags->payload_size = ICMP_PAYLOAD;
|
|
}
|
|
|
|
static char *_find_target(int argc, char **argv) {
|
|
char *target = NULL;
|
|
|
|
for (int i = optind; i < argc; i++) {
|
|
if (argv[i][0] != '-') {
|
|
target = argv[i];
|
|
}
|
|
}
|
|
|
|
if (target == NULL) {
|
|
ERROR_LOG("ft_ping: missing host operand\nTry 'ft_ping --help' or 'ft_ping --usage' for more information.");
|
|
exit(64);
|
|
}
|
|
|
|
return (target);
|
|
}
|
|
|
|
void parsing_args(int argc, char **argv, t_flags *flags)
|
|
{
|
|
if (argc == 1) {
|
|
ERROR_LOG("ft_ping: missing host operand\nTry 'ft_ping --help' or 'ft_ping --usage' for more information.");
|
|
exit(64);
|
|
}
|
|
|
|
_init_flags(flags);
|
|
check_flags(argc, argv, flags);
|
|
check_target(flags, _find_target(argc, argv));
|
|
SUCCESS_LOG("PARSING finished with success");
|
|
printf("FT_PING: %s (%s): %d data bytes\n", flags->input, flags->destination, flags->payload_size);
|
|
}
|