fix: packet size recv

This commit is contained in:
2025-12-16 05:59:53 -06:00
parent bd178a5cda
commit 5617ceb5f6
3 changed files with 9 additions and 6 deletions

View File

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