Add tools packet_parser
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user