linger flag seems to work now
This commit is contained in:
@ -6,7 +6,7 @@
|
|||||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/26 19:54:25 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);
|
usleep(100);
|
||||||
receive_icmp(set, info, &wl, &stats);
|
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);
|
receive_icmp(set, info, &wl, &stats);
|
||||||
ping_end_print(set, host, &stats);
|
ping_end_print(set, host, &stats);
|
||||||
freeaddrinfo(info);
|
freeaddrinfo(info);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/24 22:49:22 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"
|
#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->seq = *seq;
|
||||||
ret->next = 0;
|
ret->next = 0;
|
||||||
stats->sent++;
|
stats->sent++;
|
||||||
|
gettimeofday(&set->last_send_time, 0);
|
||||||
(*seq)++;
|
(*seq)++;
|
||||||
return(ret);
|
return(ret);
|
||||||
}
|
}
|
||||||
|
@ -62,6 +62,7 @@ typedef struct s_settings
|
|||||||
short stop;
|
short stop;
|
||||||
short err;
|
short err;
|
||||||
char *name;
|
char *name;
|
||||||
|
struct timeval last_send_time;
|
||||||
|
|
||||||
char current_ip[INET_ADDRSTRLEN];
|
char current_ip[INET_ADDRSTRLEN];
|
||||||
} t_settings;
|
} t_settings;
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/26 17:01:53 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"
|
#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))
|
else if(!strcmp(argv[*i], "-w") || !strncmp(argv[*i], "--timeout", 9))
|
||||||
set->timeout = get_set_int(i, argc, argv, 9, set);
|
set->timeout = get_set_int(i, argc, argv, 9, set);
|
||||||
else if(!strcmp(argv[*i], "-W") || !strncmp(argv[*i], "--linger", 8))
|
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))
|
else if(!strcmp(argv[*i], "-i") || !strncmp(argv[*i], "--interval", 10))
|
||||||
set->interval = get_set_float(i, argc, argv, 10, set);
|
set->interval = get_set_float(i, argc, argv, 10, set);
|
||||||
else if(!strncmp(argv[*i], "--ttl", 5))
|
else if(!strncmp(argv[*i], "--ttl", 5))
|
||||||
@ -147,6 +147,7 @@ t_settings parse_args(int argc, char **argv)
|
|||||||
res.count = -1;
|
res.count = -1;
|
||||||
res.timeout = -1;
|
res.timeout = -1;
|
||||||
res.interval = 1;
|
res.interval = 1;
|
||||||
|
res.linger = 10;
|
||||||
while(i < argc)
|
while(i < argc)
|
||||||
{
|
{
|
||||||
if(*argv[i] == '-')
|
if(*argv[i] == '-')
|
||||||
|
Reference in New Issue
Block a user