/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* target.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2026/03/30 12:09:48 by rparodi #+# #+# */ /* 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 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; int err = getaddrinfo(target, NULL, &hints, &res); if (err != 0) { ERROR_LOG("ft_ping: unknown host"); exit(EXIT_FAILURE); } flags->input = target; flags->destination = _ip_addr(res); freeaddrinfo(res); }