diff --git a/srcs/ft_ping.c b/srcs/ft_ping.c index d0a627f..b21e037 100644 --- a/srcs/ft_ping.c +++ b/srcs/ft_ping.c @@ -6,7 +6,7 @@ /* By: tomoron +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/26 19:54:25 by tomoron #+# #+# */ -/* Updated: 2025/08/20 15:58:48 by tomoron ### ########.fr */ +/* Updated: 2025/08/22 15:45:44 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -58,7 +58,10 @@ void ping_end_print(t_settings *set, char *host, t_stats *stats) if(isnan(stddev) || isinf(stddev)) stddev = 0.0f; printf("--- %s ping statistics ---\n", host); - percent = ((double)(stats->sent - stats->received) / stats->sent) * 100.0; + if(stats->sent) + percent = ((double)(stats->sent - stats->received) / stats->sent) * 100.0; + else + percent = 0; printf("%lu packets transmitted, %lu packets received, %d%% packet loss\n", stats->sent, stats->received, percent); if(stats->received) printf("round-trip min/avg/max/stddev = %.3f/%.3f/%.3f/%.3f ms\n", stats->min, stats->avg, stats->max, stddev); @@ -83,7 +86,7 @@ int ping_host(t_settings *set, char *host) wl = 0; inet_ntop(info->ai_family, (void *)&((struct sockaddr_in *)(info->ai_addr))->sin_addr, set->current_ip, sizeof(set->current_ip)); ping_start_print(set, host); - while((seq < set->count || set->count == 0) && !g_stop) + while ((seq < set->count || set->count == 0) && !g_stop) { tmp = send_icmp(set, info, &seq, &last_sent, &stats); if(tmp)