replace parsing to use getopt (safer), change count opt behavior, close socket when needed

This commit is contained in:
2025-08-15 02:17:19 +02:00
parent c230dc6d86
commit 01c4d7cc51
6 changed files with 110 additions and 125 deletions

View File

@ -16,6 +16,7 @@
#include <sys/param.h>
#include <math.h>
#include <netinet/ip.h>
#include <getopt.h>
#include <fcntl.h>
@ -29,8 +30,9 @@ Send ICMP ECHO_REQUEST packets to network hosts.\n\
-i, --interval=N Wait N seconds between sending each packet\n\
-w, --timeout=N Stop after N seconds\n\
-W, --linger=N Number of seconds to wait for response\n\
-v, --verbose Enable verbose mode\n\
\n\
-?, --help Give this help list\n"
-h, --help Print this usage info\n"
extern int g_stop;
@ -56,7 +58,7 @@ typedef struct s_settings
int linger; //-W (--linger)
int ttl; // --ttl
short setTtl; // is ttl set
short verbose; // -v (--verbose)
int verbose; // -v (--verbose)
int socket;
uint16_t id;
@ -102,8 +104,8 @@ typedef struct s_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);
t_settings parse_args(int argc, char **argv);
void show_help(t_settings *set, char *name);
int parse_args(int argc, char **argv, t_settings *set);
void show_help(t_settings *set);
void send_pings(t_settings *set);
uint16_t calc_checksum(void *ptr, size_t len);
double timediff(struct timeval *from);