46 lines
764 B
C
46 lines
764 B
C
#include <ping.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
|
|
void append_time(double time) {
|
|
if (times == NULL) {
|
|
times = malloc(sizeof(double));
|
|
times[0] = time;
|
|
} else {
|
|
times = reallocarray(times, rx_count, sizeof(double));
|
|
times[rx_count - 1] = 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;
|
|
}
|