Files
ft_ping/srcs/stats.c

42 lines
1.5 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* stats.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/01 17:41:42 by tomoron #+# #+# */
/* Updated: 2025/05/02 01:03:15 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "includes/ft_ping.h"
void update_stats(t_stats *stats, double time)
{
double tmp;
stats->received++;
tmp = 0;
if(stats->prev)
tmp = time - stats->avg;
stats->min = MIN(stats->min, time);
if(stats->min == 0)
stats->min = time;
stats->max = MAX(stats->max, time);
stats->avg += (time - stats->avg) / stats->received;
if(stats->prev)
stats->sqr_diff += tmp * stats->avg;
stats->prev = time;
}
void show_ping_res_line(t_waitlist *cur, t_settings *set, uint16_t seq, t_stats *stats)
{
double diff;
diff = timediff(&cur->time) * 1000;
update_stats(stats, diff);
printf("%d bytes from %s: icmp_seq=%d ttl=??? time=%.3f ms\n", 64, set->current_ip, seq, diff);
}