🔨」 fix: random crash when user skill issue

This commit is contained in:
2025-08-17 22:43:46 +02:00
parent 8c1c83229b
commit ab28a6d0e7
4 changed files with 17 additions and 19 deletions

View File

@ -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) {