Add tools packet_parser

This commit is contained in:
luwenpeng
2024-05-29 17:55:44 +08:00
parent ba1e651876
commit 963aa259b1
9 changed files with 299 additions and 20 deletions

View File

@@ -6,6 +6,7 @@ extern "C"
{
#endif
#include <stdio.h>
#include <arpa/inet.h>
#define __FAVOR_BSD 1
#include <netinet/udp.h>
@@ -72,6 +73,14 @@ static inline void udp_hdr_set_checksum(struct udphdr *hdr, uint16_t sum)
hdr->uh_sum = htons(sum);
}
static inline int udp_hdr_to_str(const struct udphdr *hdr, char *buf, size_t size)
{
memset(buf, 0, size);
return snprintf(buf, size, "UDP: src_port=%u dst_port=%u total_len=%u checksum=%u",
udp_hdr_get_src_port(hdr), udp_hdr_get_dst_port(hdr),
udp_hdr_get_total_len(hdr), udp_hdr_get_checksum(hdr));
}
#ifdef __cplusplus
}
#endif