「🏗️」 wip: wut
This commit is contained in:
@ -1,3 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
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);
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "help.h"
|
||||
#include <opt_parse.h>
|
||||
#include <ping.h>
|
||||
#include <utils.h>
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
@ -18,7 +19,7 @@ void sigint(int sig) {
|
||||
printf("--- %s ping statistics ---", address);
|
||||
printf("%d packets transmitted, %d packets received, %f%% packet loss",
|
||||
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) {
|
||||
|
33
src/utils.c
33
src/utils.c
@ -1,6 +1,6 @@
|
||||
#include <ping.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void append_time(double time) {
|
||||
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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user