clean: move packet header (type and code) verifications from packet_compare to packet_check

This commit is contained in:
2025-11-19 09:15:34 -06:00
parent d902a4b48a
commit 214abd7ddd

View File

@ -46,9 +46,6 @@ int packet_compare(const char *sent, const char *received, size_t packet_size)
const struct icmphdr *sent_hdr = (const struct icmphdr*) sent; const struct icmphdr *sent_hdr = (const struct icmphdr*) sent;
const struct icmphdr *received_hdr = (const struct icmphdr*) received; const struct icmphdr *received_hdr = (const struct icmphdr*) received;
if (received_hdr->type != 0 || received_hdr->code != 8)
return 1;
if (received_hdr->un.echo.sequence == sent_hdr->un.echo.sequence) if (received_hdr->un.echo.sequence == sent_hdr->un.echo.sequence)
return 2; return 2;
@ -62,6 +59,9 @@ int packet_check(char *packet, size_t packet_size)
{ {
struct icmphdr *hdr = (struct icmphdr *) packet; struct icmphdr *hdr = (struct icmphdr *) packet;
if (hdr->type != 0 || hdr->code != 8)
return 1;
const uint16_t checksum_bak = hdr->checksum; const uint16_t checksum_bak = hdr->checksum;
hdr->checksum = 0; hdr->checksum = 0;
int tmp = checksum(packet, packet_size); int tmp = checksum(packet, packet_size);