Add packet helpers

This commit is contained in:
luwenpeng
2023-12-18 16:51:17 +08:00
parent dda0cdf104
commit 2e56bd810c
7 changed files with 1110 additions and 25 deletions

View File

@@ -0,0 +1,68 @@
#ifndef _PACKET_HELPERS_H
#define _PACKET_HELPERS_H
#ifdef __cpluscplus
extern "C"
{
#endif
#include "packet.h"
// packet
uint64_t packet_get_zone_id(const struct packet *pkt);
uint16_t packet_get_raw_len(const struct packet *pkt);
const char *packet_get0_raw_data(const struct packet *pkt);
bool paket_is_fragment(const struct packet *pkt);
bool packet_has_tcp(const struct packet *pkt);
bool packet_has_udp(const struct packet *pkt);
// foreach layer
uint8_t packet_get_layer_count(const struct packet *pkt);
enum layer_type packet_get_layer_type(const struct packet *pkt, uint8_t index);
const char *packet_get_layer_hdr_ptr(const struct packet *pkt, uint8_t index);
const char *packet_get_layer_pld_ptr(const struct packet *pkt, uint8_t index);
uint16_t packet_get_layer_hdr_len(const struct packet *pkt, uint8_t index);
uint16_t packet_get_layer_pld_len(const struct packet *pkt, uint8_t index);
// get tcp layer
const struct layer_record *packet_get0_tcp_layer(const struct packet *pkt);
const char *packet_get_tcp_hdr_ptr(const struct packet *pkt);
const char *packet_get_tcp_pld_ptr(const struct packet *pkt);
uint16_t packet_get_tcp_hdr_len(const struct packet *pkt);
uint16_t packet_get_tcp_pld_len(const struct packet *pkt);
uint16_t packet_get_tcp_sport(const struct packet *pkt);
uint16_t packet_get_tcp_dport(const struct packet *pkt);
uint32_t packet_get_tcp_seq(const struct packet *pkt);
uint32_t packet_get_tcp_ack(const struct packet *pkt);
uint8_t packet_get_tcp_flags(const struct packet *pkt);
bool packet_has_tcp_flag_urg(const struct packet *pkt);
bool packet_has_tcp_flag_ack(const struct packet *pkt);
bool packet_has_tcp_flag_psh(const struct packet *pkt);
bool packet_has_tcp_flag_rst(const struct packet *pkt);
bool packet_has_tcp_flag_syn(const struct packet *pkt);
bool packet_has_tcp_flag_fin(const struct packet *pkt);
// get inner udp layer
const struct layer_record *packet_get0_inner_udp_layer(const struct packet *pkt);
const char *packet_get_inner_udp_hdr_ptr(const struct packet *pkt);
const char *packet_get_inner_udp_pld_ptr(const struct packet *pkt);
uint16_t packet_get_inner_udp_hdr_len(const struct packet *pkt);
uint16_t packet_get_inner_udp_pld_len(const struct packet *pkt);
uint16_t packet_get_inner_udp_sport(const struct packet *pkt);
uint16_t packet_get_inner_udp_dport(const struct packet *pkt);
// get outer udp layer
const struct layer_record *packet_get0_outer_udp_layer(const struct packet *pkt);
const char *packet_get_outer_udp_hdr_ptr(const struct packet *pkt);
const char *packet_get_outer_udp_pld_ptr(const struct packet *pkt);
uint16_t packet_get_outer_udp_hdr_len(const struct packet *pkt);
uint16_t packet_get_outer_udp_pld_len(const struct packet *pkt);
uint16_t packet_get_outer_udp_sport(const struct packet *pkt);
uint16_t packet_get_outer_udp_dport(const struct packet *pkt);
#ifdef __cpluscplus
}
#endif
#endif