feat(parsing/sources): stock the ip destination
This commit is contained in:
parent
56085f5948
commit
4f123e2d5a
1 changed files with 18 additions and 3 deletions
|
|
@ -6,21 +6,34 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netdb.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue