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

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

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

View File

@@ -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);
void print_recv(const struct setting *settings, const char *packet, const struct timeval *start, const struct timeval *stop, struct sockaddr_in const *sender);