「🔨」 fix: fixe the lasts sus prints
This commit is contained in:
2
Makefile
2
Makefile
@ -33,7 +33,7 @@ endif
|
|||||||
all: $(NAME)
|
all: $(NAME)
|
||||||
|
|
||||||
$(NAME): $(OBJS)
|
$(NAME): $(OBJS)
|
||||||
@$(CC) $(FLAGS) $(OBJS) -o $(NAME)
|
@$(CC) $(FLAGS) -lm $(OBJS) -o $(NAME)
|
||||||
@printf "$(YELLOW)「✨」($(NAME)) Program compiled\n"
|
@printf "$(YELLOW)「✨」($(NAME)) Program compiled\n"
|
||||||
|
|
||||||
$(OBJSDIR)/%.o: $(SRCDIR)/%.c
|
$(OBJSDIR)/%.o: $(SRCDIR)/%.c
|
||||||
|
@ -61,7 +61,6 @@ void process_icmp(char *buf, int bytes, struct sockaddr_in *addr, int seq,
|
|||||||
|
|
||||||
append_time(rtt);
|
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,
|
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),
|
inet_ntoa(addr->sin_addr), ntohs(icmp->un.echo.sequence),
|
||||||
ip->ip_ttl, rtt);
|
ip->ip_ttl, rtt);
|
||||||
|
13
src/utils.c
13
src/utils.c
@ -4,6 +4,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
void append_time(double time) {
|
void append_time(double time) {
|
||||||
if (times == NULL) {
|
if (times == NULL) {
|
||||||
@ -46,7 +47,11 @@ double get_avg_rtt(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
double get_stddev_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;
|
return stddev;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,12 +66,10 @@ bool check_for_timeout(struct timeval start, options_t opt) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: fix the packet loss
|
|
||||||
void print_stats(void) {
|
void print_stats(void) {
|
||||||
printf("--- %s ping statistics ---\n", address);
|
printf("--- %s ping statistics ---\n", address);
|
||||||
printf("%d packets transmitted, %d packets received, %.0f%% packet loss\n",
|
printf("%d packets transmitted, %d packets received, %d%% packet loss\n",
|
||||||
tx_count, rx_count, (tx_count - rx_count / 2.0) * 100);
|
tx_count, rx_count, (100 * (tx_count - rx_count) / tx_count));
|
||||||
// TODO: fix this shit
|
|
||||||
printf("round-trip min/avg/max/stddev = %.3f/%.3f/%.3f/%.3f\n",
|
printf("round-trip min/avg/max/stddev = %.3f/%.3f/%.3f/%.3f\n",
|
||||||
get_min_rtt(), get_avg_rtt(), get_max_rtt(), get_stddev_rtt());
|
get_min_rtt(), get_avg_rtt(), get_max_rtt(), get_stddev_rtt());
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user