linger flag seems to work now

This commit is contained in:
2025-05-22 23:30:01 +02:00
parent 94085f5bb2
commit 64ac4ba5e0
4 changed files with 21 additions and 18 deletions

View File

@ -6,7 +6,7 @@
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);

View File

@ -6,7 +6,7 @@
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

View File

@ -62,6 +62,7 @@ typedef struct s_settings
short stop;
short err;
char *name;
struct timeval last_send_time;
char current_ip[INET_ADDRSTRLEN];
} t_settings;

View File

@ -6,7 +6,7 @@
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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] == '-')