diff --git a/includes/ping.h b/includes/ping.h index 11bb7cd..a7f31ac 100644 --- a/includes/ping.h +++ b/includes/ping.h @@ -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 diff --git a/src/ping/send_icmp.c b/src/ping/send_icmp.c index ee7955a..a482b71 100644 --- a/src/ping/send_icmp.c +++ b/src/ping/send_icmp.c @@ -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); } diff --git a/src/ping/send_ping.c b/src/ping/send_ping.c index 29ffcf1..b196dc4 100644 --- a/src/ping/send_ping.c +++ b/src/ping/send_ping.c @@ -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); }