/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* stats.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: tomoron +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/05/01 17:41:42 by tomoron #+# #+# */ /* Updated: 2025/05/02 23:53:28 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ #include "includes/ft_ping.h" void update_stats(t_stats *stats, double time) { double tmp; stats->received++; tmp = 0; 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; 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); }