🔨」 fix: fixed address in first print and fixed size displayed

This commit is contained in:
2025-08-17 22:56:27 +02:00
parent ab28a6d0e7
commit 7799f10460
3 changed files with 11 additions and 4 deletions

View File

@ -36,7 +36,7 @@ typedef struct {
#define DEFAULT_VERBOSE false
#define DEFAULT_SIZE 64
#define DEFAULT_SIZE 56
#define DEFAULT_INTERVAL 1
#define DEFAULT_TIMEOUT -1
#define DEFAULT_COUNT -1

View File

@ -77,7 +77,7 @@ void process_icmp(char *buf, int bytes, struct sockaddr_in *addr, int seq,
append_time(rtt);
printf("%d bytes from %s: icmp_seq=%d ttl=%d time=%.3f\n", bytes - len,
printf("%d bytes from %s: icmp_seq=%d ttl=%d time=%.3f\n", bytes,
inet_ntoa(addr->sin_addr), ntohs(icmp->un.echo.sequence),
ip->ip_ttl, rtt);
}

View File

@ -35,7 +35,13 @@ options_t init_opt(args_t *args) {
options_t opt;
verbose = args->opts[VERBOSE] != false ? true : DEFAULT_VERBOSE;
opt.count = args->arg[COUNT] != -1 ? args->arg[COUNT] : DEFAULT_COUNT;
opt.size = args->arg[SIZE] != -1 ? args->arg[SIZE] : DEFAULT_SIZE;
if (args->arg[SIZE] > sizeof(struct icmphdr) || args->arg[SIZE] == -1) {
opt.size = args->arg[SIZE] != -1 ? args->arg[SIZE] : DEFAULT_SIZE;
} else {
fprintf(stderr, "size option is too low defaulting to: %lu",
DEFAULT_SIZE - sizeof(struct icmphdr));
opt.size = args->arg[SIZE] = DEFAULT_SIZE;
}
opt.timeout =
args->arg[TIMEOUT] != -1 ? args->arg[TIMEOUT] : DEFAULT_TIMEOUT;
opt.interval =
@ -119,7 +125,8 @@ int ping(args_t *args) {
break;
}
printf("PING %s (%s): %d data bytes\n", address, address, opt.size);
printf("PING %s (%s): %d data bytes\n", address,
inet_ntoa(addr.sin_addr), opt.size);
ret = send_ping(sock, &addr, opt);
}