Add packet_build.cpp support imitate_tcp_packet() / imitate_udp_packet()

This commit is contained in:
luwenpeng
2024-04-24 11:40:00 +08:00
parent ffead24e45
commit d8963af5f8
16 changed files with 444 additions and 441 deletions

View File

@@ -7,31 +7,9 @@ extern "C"
#include <stdint.h>
// https://datatracker.ietf.org/doc/html/rfc1071
static inline uint16_t checksum(char *data, int len)
{
long sum = 0;
uint16_t *addr = (uint16_t *)data;
while (len > 1)
{
sum += *addr++;
len -= 2;
}
if (len > 0)
{
sum += *(unsigned char *)addr;
}
// Fold 32-bit sum to 16 bits
while (sum >> 16)
{
sum = (sum & 0xffff) + (sum >> 16);
}
return (uint16_t)(~sum);
}
uint16_t checksum(const char *data, uint16_t len);
uint16_t checksum_v4(const void *l4_hdr_ptr, uint16_t l4_total_len, uint8_t l4_proto, struct in_addr *src_addr, struct in_addr *dst_addr);
uint16_t checksum_v6(const void *l4_hdr_ptr, uint16_t l4_total_len, uint8_t l4_proto, struct in6_addr *src_addr, struct in6_addr *dst_addr);
#ifdef __cplusplus
}