「🔨」 fix: random crash when user skill issue
This commit is contained in:
@ -18,7 +18,8 @@ typedef enum {
|
||||
SIZE,
|
||||
TIMEOUT,
|
||||
LINGER,
|
||||
INTERVAL
|
||||
INTERVAL,
|
||||
TTL
|
||||
} options_nb_t;
|
||||
|
||||
static struct options options[] = {
|
||||
@ -39,7 +40,7 @@ static struct options options[] = {
|
||||
#undef GRP
|
||||
};
|
||||
|
||||
#define OPT_NB 10
|
||||
#define OPT_NB 9
|
||||
|
||||
#define FT_PING_V "0.1"
|
||||
|
||||
|
@ -76,7 +76,7 @@ int opt_parse(char **av, args_t *args) {
|
||||
;
|
||||
char **old = args->hosts;
|
||||
args->hosts = reallocarray(old, i + 2, sizeof(char *));
|
||||
if (args->hosts == NULL)
|
||||
if (args->hosts == NULL)
|
||||
return EXIT_FAILURE;
|
||||
args->hosts[i] = *av;
|
||||
args->hosts[i + 1] = NULL;
|
||||
|
@ -28,7 +28,7 @@ int init_socket(options_t opt) {
|
||||
linger.l_onoff = true;
|
||||
if (setsockopt(sock, SOL_SOCKET, SO_LINGER, &linger, sizeof(linger)) < 0) {
|
||||
fprintf(stderr,
|
||||
"can't setsockopt for the linger maybe try a different one");
|
||||
"can't setsockopt for the linger maybe try a different one\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -38,8 +38,7 @@ int init_socket(options_t opt) {
|
||||
|
||||
if (setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &tv_out, sizeof(tv_out)) <
|
||||
0) {
|
||||
perror("setsockopt");
|
||||
fprintf(stderr, "can't setsockopt for the receive timeout");
|
||||
fprintf(stderr, "can't setsockopt for the receive timeout\n");
|
||||
return -1;
|
||||
}
|
||||
return sock;
|
||||
|
@ -41,7 +41,6 @@ options_t init_opt(args_t *args) {
|
||||
opt.interval =
|
||||
args->arg[INTERVAL] != -1 ? args->arg[INTERVAL] : DEFAULT_INTERVAL;
|
||||
opt.linger = args->arg[LINGER] != -1 ? args->arg[LINGER] : DEFAULT_LINGER;
|
||||
|
||||
return opt;
|
||||
}
|
||||
|
||||
@ -76,8 +75,7 @@ int send_ping(int socket, struct sockaddr_in *dest, options_t opt) {
|
||||
}
|
||||
}
|
||||
} else
|
||||
process_icmp(recvbuf, bytes, &addr, seq, &pkt_start,
|
||||
&pkt_end);
|
||||
process_icmp(recvbuf, bytes, &addr, seq, &pkt_start, &pkt_end);
|
||||
if (check_for_count(opt)) {
|
||||
print_stats();
|
||||
return EXIT_SUCCESS;
|
||||
@ -99,22 +97,22 @@ int ping(args_t *args) {
|
||||
for (int i = 0; args->hosts[i] != NULL; i++) {
|
||||
address = args->hosts[i];
|
||||
struct sockaddr_in addr;
|
||||
struct addrinfo hints, *res;
|
||||
struct addrinfo hints, *res;
|
||||
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
hints.ai_family = AF_INET;
|
||||
hints.ai_socktype = SOCK_RAW;
|
||||
hints.ai_protocol = IPPROTO_ICMP;
|
||||
hints.ai_family = AF_INET;
|
||||
hints.ai_socktype = SOCK_RAW;
|
||||
hints.ai_protocol = IPPROTO_ICMP;
|
||||
|
||||
int status = getaddrinfo(address, NULL, &hints, &res);
|
||||
if (status != 0) {
|
||||
fprintf(stderr, "Bad address: %s\n", address);
|
||||
ret = EXIT_FAILURE;
|
||||
continue;
|
||||
}
|
||||
if (status != 0) {
|
||||
fprintf(stderr, "Bad address: %s\n", address);
|
||||
ret = EXIT_FAILURE;
|
||||
continue;
|
||||
}
|
||||
|
||||
memcpy(&addr, res->ai_addr, res->ai_addrlen);
|
||||
freeaddrinfo(res);
|
||||
freeaddrinfo(res);
|
||||
|
||||
sock = init_socket(opt);
|
||||
if (sock < 0) {
|
||||
|
Reference in New Issue
Block a user