feat(parsing/sources): the parsing is now finish

This commit is contained in:
Raphael 2026-03-30 15:59:20 +02:00
parent 42e15e53e5
commit e4f19610c1
No known key found for this signature in database

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */ /* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2026/03/23 14:49:36 by rparodi #+# #+# */ /* Created: 2026/03/23 14:49:36 by rparodi #+# #+# */
/* Updated: 2026/03/30 12:22:07 by rparodi ### ########.fr */ /* Updated: 2026/03/30 15:53:23 by rparodi ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -16,8 +16,12 @@
#include <stdlib.h> #include <stdlib.h>
#include <getopt.h> #include <getopt.h>
static const char *_find_target(int argc, char **argv) { static void _init_flags(t_flags *flags) {
const char *target = NULL; flags->payload_size = ICMP_PAYLOAD;
}
static char *_find_target(int argc, char **argv) {
char *target = NULL;
for (int i = optind; i < argc; i++) { for (int i = optind; i < argc; i++) {
if (argv[i][0] != '-') { if (argv[i][0] != '-') {
@ -26,20 +30,23 @@ static const char *_find_target(int argc, char **argv) {
} }
if (target == NULL || target[0] == '\0') { if (target == NULL || target[0] == '\0') {
dprintf(2, "%s: missing host operand \n Try 'ping --help' or 'ping --usage' for more information.", argv[0]); ERROR_LOG("ft_ping: missing host operand \n Try 'ft_ping --help' or 'ft_ping --usage' for more information.");
exit(64); exit(64);
} }
return (target); return (target);
} }
void parsing_args(int argc, char **argv, t_flags *flags) void parsing_args(int argc, char **argv, t_flags *flags)
{ {
if (argc == 1) { if (argc == 1) {
dprintf(2, "%s: missing host operand \n Try 'ping --help' or 'ping --usage' for more information.", argv[0]); ERROR_LOG("ft_ping: missing host operand \n Try 'ft_ping --help' or 'ft_ping --usage' for more information.");
exit(64); exit(64);
} }
_init_flags(flags);
check_flags(argc, argv, flags); check_flags(argc, argv, flags);
check_target(_find_target(argc, argv)); check_target(flags, _find_target(argc, argv));
SUCCESS_LOG("PARSING finished with success"); SUCCESS_LOG("PARSING finished with success");
printf("FT_PING: %s (%s): %d data bytes\n", flags->input, flags->destination, flags->payload_size);
} }