diff --git a/Makefile b/Makefile index 0245f58..6b03bff 100644 --- a/Makefile +++ b/Makefile @@ -33,7 +33,7 @@ endif all: $(NAME) $(NAME): $(OBJS) - @$(CC) $(FLAGS) $(OBJS) -o $(NAME) + @$(CC) $(FLAGS) -lm $(OBJS) -o $(NAME) @printf "$(YELLOW)「✨」($(NAME)) Program compiled\n" $(OBJSDIR)/%.o: $(SRCDIR)/%.c diff --git a/src/ping/send_icmp.c b/src/ping/send_icmp.c index a031bfb..bbe7563 100644 --- a/src/ping/send_icmp.c +++ b/src/ping/send_icmp.c @@ -61,7 +61,6 @@ void process_icmp(char *buf, int bytes, struct sockaddr_in *addr, int seq, append_time(rtt); - // TODO: fix the time and put the hostname with the ip printf("%d bytes from %s: icmp_seq=%d ttl=%d time=%.3f\n", bytes - len, inet_ntoa(addr->sin_addr), ntohs(icmp->un.echo.sequence), ip->ip_ttl, rtt); diff --git a/src/utils.c b/src/utils.c index 804be7c..b6e2168 100644 --- a/src/utils.c +++ b/src/utils.c @@ -4,6 +4,7 @@ #include #include #include +#include void append_time(double time) { if (times == NULL) { @@ -46,7 +47,11 @@ double get_avg_rtt(void) { } double get_stddev_rtt(void) { - double stddev = 0; + double stddev = 0.0; + for (int i = 0; i < rx_count; i++) { + stddev += pow(times[i] - get_avg_rtt(), 2); + } + stddev = sqrt(stddev / rx_count); return stddev; } @@ -61,12 +66,10 @@ bool check_for_timeout(struct timeval start, options_t opt) { return false; } -// TODO: fix the packet loss void print_stats(void) { printf("--- %s ping statistics ---\n", address); - printf("%d packets transmitted, %d packets received, %.0f%% packet loss\n", - tx_count, rx_count, (tx_count - rx_count / 2.0) * 100); - // TODO: fix this shit + printf("%d packets transmitted, %d packets received, %d%% packet loss\n", + tx_count, rx_count, (100 * (tx_count - rx_count) / tx_count)); printf("round-trip min/avg/max/stddev = %.3f/%.3f/%.3f/%.3f\n", get_min_rtt(), get_avg_rtt(), get_max_rtt(), get_stddev_rtt()); }