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