linger flag seems to work now
This commit is contained in:
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
||||
|
@ -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] == '-')
|
||||
|
Reference in New Issue
Block a user