🏗️」 wip: wut

This commit is contained in:
2025-08-15 18:19:22 +02:00
parent 4c6fc1ecb1
commit 057fb25cf7
3 changed files with 48 additions and 4 deletions

View File

@ -1,3 +1,15 @@
#pragma once #pragma once
void append_time(double time); void append_time(double time);
/**
* @brief Can be used to get the avarage rtt
*/
double get_avg_rtt(void);
/**
* @brief Can be used to get the
*/
double get_min_rtt(void);
double get_max_rtt(void);
double get_stddev_rtt(void);

View File

@ -1,6 +1,7 @@
#include "help.h" #include "help.h"
#include <opt_parse.h> #include <opt_parse.h>
#include <ping.h> #include <ping.h>
#include <utils.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <netinet/in.h> #include <netinet/in.h>
@ -18,7 +19,7 @@ void sigint(int sig) {
printf("--- %s ping statistics ---", address); printf("--- %s ping statistics ---", address);
printf("%d packets transmitted, %d packets received, %f%% packet loss", printf("%d packets transmitted, %d packets received, %f%% packet loss",
tx_count, rx_count, (tx_count - rx_count / 2.0) * 100); tx_count, rx_count, (tx_count - rx_count / 2.0) * 100);
printf("round-trip min/avg/max/stddev = %d/%d/%d/%d"); printf("round-trip min/avg/max/stddev = %f/%f/%f/%f", get_min_rtt(), get_avg_rtt(), get_max_rtt(), get_stddev_rtt());
} }
options_t init_opt(args_t *args) { options_t init_opt(args_t *args) {

View File

@ -1,6 +1,6 @@
#include <ping.h> #include <ping.h>
#include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>
void append_time(double time) { void append_time(double time) {
if (times == NULL) { if (times == NULL) {
@ -12,3 +12,34 @@ void append_time(double time) {
} }
} }
double get_max_rtt(void) {
double max = 0;
for (int i = 0; i < rx_count; i++) {
if (times[i] > max)
max = times[i];
}
return max;
}
double get_min_rtt(void) {
double min = 0;
for (int i = 0; i < rx_count; i++) {
if (times[i] < min)
min = times[i];
}
return min;
}
double get_avg_rtt(void) {
double avg = 0;
for (int i = 0; i < rx_count; i++) {
avg += times[i];
}
avg = avg / rx_count;
return avg;
}
double get_stddev_rtt(void) {
double stddev = 0;
return stddev;
}