show ping response lines and stats lines

This commit is contained in:
2025-05-02 01:17:18 +02:00
parent b4afb26076
commit e3a2901370
8 changed files with 233 additions and 117 deletions

View File

@ -13,6 +13,8 @@
#include <ctype.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/param.h>
#include <math.h>
#include <fcntl.h>
@ -21,14 +23,16 @@
#define HELP_MESSAGE " [OPTION...] HOST ...\n\
Send ICMP ECHO_REQUEST packets to network hosts.\n\
\n\
-c, --count=NUMBER stop after sending NUMBER packets\n\
-n, --numeric do not resolve host addresses\n\
-c, --count=N stop after sending NUMBER packets\n\
--ttl=N specify N as time-to-live\n\
-w, --timeout=N stop after N seconds\n\
-i, --interval=N wait N seconds between sending each packet\n\
-W, --linger=N number of seconds to wait for response\n\
\n\
-f, --flood flood ping (root only)\n\
-?, --help give this help list\n"
extern int g_stop;
typedef struct s_waitlist
{
struct timeval time;
@ -57,6 +61,8 @@ typedef struct s_settings
short stop;
short err;
char *name;
char current_ip[INET_ADDRSTRLEN];
} t_settings;
@ -72,6 +78,19 @@ typedef struct s_icmp_echo
uint8_t data[40];
} t_icmp_echo;
typedef struct s_stats
{
size_t sent;
size_t received;
double min;
double avg;
double max;
double sqr_diff;
double prev;
} t_stats;
t_icmp_echo prepare_icmp_echo(uint16_t sequence, uint16_t identifier);
int add_host(t_settings *res, char *host);
void free_hosts(t_host_list *list);
@ -79,5 +98,12 @@ t_settings parse_args(int argc, char **argv);
void show_help(t_settings *set, char *name);
void send_pings(t_settings *set);
uint16_t calc_checksum(void *ptr, size_t len);
double timediff(struct timeval *from);
void waitlist_remove(t_waitlist **lst, uint16_t seq, t_settings *set, t_stats *stats);
void show_ping_res_line(t_waitlist *cur, t_settings *set, uint16_t seq, t_stats *stats);
void waitlist_free(t_waitlist *lst);
t_waitlist *send_icmp(t_settings *set, struct addrinfo *host, uint16_t *seq, struct timeval *last, t_stats *stats);
void waitlist_add(t_waitlist **waitlist, t_waitlist *elem);
void receive_icmp(t_settings *set, struct addrinfo *info, t_waitlist **wl, t_stats *stats);
#endif