diff --git a/src/main.c b/src/main.c index 72c6d3c..f3d524c 100644 --- a/src/main.c +++ b/src/main.c @@ -216,7 +216,7 @@ int main(int ac, char **av) if (ret >= (ssize_t) sizeof(struct icmphdr) && ((struct icmphdr *) buffer + sizeof(struct iphdr))->type == 0) { stats.packets_received++; - print_recv(&settings, (struct icmphdr*) (buffer + sizeof(struct iphdr)), &start, &stop, &sender); + print_recv(&settings, buffer, &start, &stop, &sender); } sleep(1); diff --git a/src/print.c b/src/print.c index 5744e0d..638dd68 100644 --- a/src/print.c +++ b/src/print.c @@ -68,13 +68,16 @@ static const char *get_message_description(const uint8_t type, const uint8_t cod return (NULL); } -void print_recv(const struct setting *settings, const struct icmphdr *header, const struct timeval *start, const struct timeval *stop, struct sockaddr_in const *sender) +void print_recv(const struct setting *settings, const char *packet, const struct timeval *start, const struct timeval *stop, struct sockaddr_in const *sender) { + const struct iphdr *ip_hdr = (const struct iphdr *) packet; + const struct icmphdr *icmp_hdr = (const struct icmphdr *) packet + sizeof(struct iphdr); + char *ipstr = inet_ntoa(sender->sin_addr); - printf("%zu", settings->payload_size + sizeof(struct icmphdr) + ((header->type == 0) ? 0 : sizeof(struct iphdr))); + printf("%ld bozo", ntohs(ip_hdr->tot_len) - sizeof(struct iphdr)); printf(" bytes from %s: ", ipstr); - printf(get_message_description(header->type, header->code), - htons(header->un.echo.sequence), + printf(get_message_description(icmp_hdr->type, icmp_hdr->code), + htons(icmp_hdr->un.echo.sequence), settings->ttl, get_interval(start, stop) ); diff --git a/src/print.h b/src/print.h index b3241cb..fd431b6 100644 --- a/src/print.h +++ b/src/print.h @@ -9,4 +9,4 @@ void print_err(const char *format, ...); void print_header(struct setting const *settings); void print_statistics(struct statistics const *stats, struct setting const *settings); -void print_recv(const struct setting *settings, const struct icmphdr *header, const struct timeval *start, const struct timeval *stop, struct sockaddr_in const *sender); \ No newline at end of file +void print_recv(const struct setting *settings, const char *packet, const struct timeval *start, const struct timeval *stop, struct sockaddr_in const *sender); \ No newline at end of file