refactor: remove unnecessary wrapper functions and redundant checks

This commit is contained in:
lohhiiccc 2026-01-27 21:34:41 +01:00
parent e57d43de33
commit 06305696da
3 changed files with 3 additions and 24 deletions

View file

@ -8,8 +8,6 @@
/* Forward declarations */
static void write_icmp_header(struct icmp_header *hdr, uint8_t type,
uint8_t code, uint32_t header_rest);
static void copy_payload(void *dest, const void *src, size_t len);
static void compute_and_set_checksum(struct icmp_header *hdr, size_t total_len);
/* -------------------- */
int
@ -26,12 +24,10 @@ icmp_build_packet(void *buffer, size_t buffer_len, uint8_t type, uint8_t code,
write_icmp_header(h, type, code, header_rest);
if (payload_len > 0)
{
copy_payload((unsigned char*)buffer + sizeof(struct icmp_header),
payload, payload_len);
}
memcpy((unsigned char*)buffer + sizeof(struct icmp_header), payload,
payload_len);
compute_and_set_checksum(h, required_len);
h->checksum = htons(icmp_checksum(h, required_len));
return (int)required_len;
}
@ -46,16 +42,3 @@ write_icmp_header(struct icmp_header *hdr, uint8_t type, uint8_t code,
hdr->un.gateway = header_rest;
}
static void
copy_payload(void *dest, const void *src, size_t len)
{
if (0 == len)
return;
memcpy(dest, src, len);
}
static void
compute_and_set_checksum(struct icmp_header *hdr, size_t total_len)
{
hdr->checksum = htons(icmp_checksum(hdr, total_len));
}

View file

@ -25,9 +25,6 @@ icmp_parse_icmp_payload(const void *buffer, size_t buffer_len,
extract_icmp_fields(hdr, type, code);
size_t payload_offset = ip_hdr_len + ICMP_HEADER_SIZE;
if (buffer_len < payload_offset)
return -1;
*payload_len = buffer_len - payload_offset;
*payload = (const uint8_t *)buffer + payload_offset;
return 0;

View file

@ -16,7 +16,6 @@ recv_build_reply(icmp_reply_t *reply, uint8_t type, uint8_t code,
reply->payload = (void *)payload;
reply->payload_len = payload_len;
reply->ip_payload = (void *)((const uint8_t *)buffer + ip_hdr_len);
reply->ip_payload_len = 0;
if (icmp_get_time(&reply->timestamp) < 0)
{
reply->timestamp.tv_sec = 0;