From 4f123e2d5a049afa0ea2aa000464f73579f4139c Mon Sep 17 00:00:00 2001 From: Raphael Date: Mon, 30 Mar 2026 15:57:39 +0200 Subject: [PATCH] feat(parsing/sources): stock the ip destination --- parsing/sources/target.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/parsing/sources/target.c b/parsing/sources/target.c index 43762b6..3e9b244 100644 --- a/parsing/sources/target.c +++ b/parsing/sources/target.c @@ -6,21 +6,34 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2026/03/30 12:09:48 by rparodi #+# #+# */ -/* Updated: 2026/03/30 12:33:54 by rparodi ### ########.fr */ +/* Updated: 2026/03/30 15:42:55 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #include "macro.h" +#include "struct.h" #include #include #include +#include +#include #include #include #include #include -void check_target(const char *target) { - struct addrinfo hints = {0}, *res; +char *_ip_addr(struct addrinfo *res) { + char ip_str[INET_ADDRSTRLEN]; + struct sockaddr_in *ip = (struct sockaddr_in *)res->ai_addr; + + inet_ntop(AF_INET, &ip->sin_addr, ip_str, sizeof(ip_str)); + + return strdup(ip_str); +} + +void check_target(t_flags *flags, char *target) { + struct addrinfo hints, *res; + bzero(&hints, sizeof(struct addrinfo)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_RAW; hints.ai_protocol = IPPROTO_ICMP; @@ -30,5 +43,7 @@ void check_target(const char *target) { ERROR_LOG("ft_ping: unknown host"); exit(EXIT_FAILURE); } + flags->input = target; + flags->destination = _ip_addr(res); freeaddrinfo(res); }