diff --git a/srcs/ft_ping.c b/srcs/ft_ping.c index f16c393..3bc1f87 100644 --- a/srcs/ft_ping.c +++ b/srcs/ft_ping.c @@ -6,7 +6,7 @@ /* By: tomoron +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/26 19:54:25 by tomoron #+# #+# */ -/* Updated: 2025/05/22 15:24:43 by tomoron ### ########.fr */ +/* Updated: 2025/05/22 23:01:33 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -85,7 +85,7 @@ int ping_host(t_settings *set, char *host) usleep(100); receive_icmp(set, info, &wl, &stats); } - while(wl && !g_stop) + while(wl && !g_stop && timediff(&set->last_send_time) < set->linger) receive_icmp(set, info, &wl, &stats); ping_end_print(set, host, &stats); freeaddrinfo(info); diff --git a/srcs/icmp.c b/srcs/icmp.c index 84842b2..159214b 100644 --- a/srcs/icmp.c +++ b/srcs/icmp.c @@ -6,7 +6,7 @@ /* By: tomoron +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/24 22:49:22 by tomoron #+# #+# */ -/* Updated: 2025/05/22 15:26:40 by tomoron ### ########.fr */ +/* Updated: 2025/05/22 22:19:36 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ #include "includes/ft_ping.h" @@ -80,6 +80,7 @@ t_waitlist *send_icmp(t_settings *set, struct addrinfo *host, uint16_t *seq, str ret->seq = *seq; ret->next = 0; stats->sent++; + gettimeofday(&set->last_send_time, 0); (*seq)++; return(ret); } diff --git a/srcs/includes/ft_ping.h b/srcs/includes/ft_ping.h index f096c63..34ed678 100644 --- a/srcs/includes/ft_ping.h +++ b/srcs/includes/ft_ping.h @@ -49,21 +49,22 @@ typedef struct s_host_list typedef struct s_settings { - t_host_list *hosts; - int count; // -c (--count) - int timeout; // -w (--timeout) - double interval; //-i (--interval) - int linger; //-W (--linger) - int ttl; // --ttl - short setTtl; // is ttl set + t_host_list *hosts; + int count; // -c (--count) + int timeout; // -w (--timeout) + double interval; //-i (--interval) + int linger; //-W (--linger) + int ttl; // --ttl + short setTtl; // is ttl set - int socket; - uint16_t id; - short stop; - short err; - char *name; + int socket; + uint16_t id; + short stop; + short err; + char *name; + struct timeval last_send_time; - char current_ip[INET_ADDRSTRLEN]; + char current_ip[INET_ADDRSTRLEN]; } t_settings; diff --git a/srcs/parsing.c b/srcs/parsing.c index a51f179..b00777a 100644 --- a/srcs/parsing.c +++ b/srcs/parsing.c @@ -6,7 +6,7 @@ /* By: tomoron +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/26 17:01:53 by tomoron #+# #+# */ -/* Updated: 2025/04/30 00:17:50 by tomoron ### ########.fr */ +/* Updated: 2025/05/22 23:01:05 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ #include "includes/ft_ping.h" @@ -99,7 +99,7 @@ void parse_opt(int *i, t_settings *set, int argc, char **argv) else if(!strcmp(argv[*i], "-w") || !strncmp(argv[*i], "--timeout", 9)) set->timeout = get_set_int(i, argc, argv, 9, set); else if(!strcmp(argv[*i], "-W") || !strncmp(argv[*i], "--linger", 8)) - set->timeout = get_set_int(i, argc, argv, 8, set); + set->linger = get_set_int(i, argc, argv, 8, set); else if(!strcmp(argv[*i], "-i") || !strncmp(argv[*i], "--interval", 10)) set->interval = get_set_float(i, argc, argv, 10, set); else if(!strncmp(argv[*i], "--ttl", 5)) @@ -147,6 +147,7 @@ t_settings parse_args(int argc, char **argv) res.count = -1; res.timeout = -1; res.interval = 1; + res.linger = 10; while(i < argc) { if(*argv[i] == '-')