rename packet_get_layers_number to packet_get_layer_count
This commit is contained in:
@@ -81,7 +81,7 @@ enum packet_direction packet_get_direction(const struct packet *pkt);
|
||||
uint64_t packet_get_session_id(const struct packet *pkt);
|
||||
void packet_prepend_sid_list(struct packet *pkt, const struct sid_list *list);
|
||||
|
||||
int8_t packet_get_layers_number(const struct packet *pkt);
|
||||
int8_t packet_get_layer_count(const struct packet *pkt);
|
||||
const struct packet_layer *packet_get_layer(const struct packet *pkt, int8_t idx);
|
||||
|
||||
const char *packet_get_data(const struct packet *pkt);
|
||||
@@ -93,27 +93,6 @@ uint16_t packet_get_payload_len(const struct packet *pkt);
|
||||
void packet_set_action(struct packet *pkt, enum packet_action action);
|
||||
enum packet_action packet_get_action(const struct packet *pkt);
|
||||
|
||||
/*
|
||||
******************************************************************************
|
||||
* Example: foreach layer in packet
|
||||
******************************************************************************
|
||||
*
|
||||
* // inorder
|
||||
* int8_t layers = packet_get_layers_number(pkt);
|
||||
* for (int8_t i = 0; i < layers; i++)
|
||||
* {
|
||||
* const struct packet_layer *layer = packet_get_layer(pkt, i);
|
||||
* printf("layer[%d]: type=%d, hdr_offset=%d, hdr_len=%d, pld_len=%d\n", i, layer->type, layer->hdr_offset, layer->hdr_len, layer->pld_len);
|
||||
* }
|
||||
*
|
||||
* // reverse
|
||||
* for (int8_t i = layers - 1; i >= 0; i--)
|
||||
* {
|
||||
* const struct packet_layer *layer = packet_get_layer(pkt, i);
|
||||
* printf("layer[%d]: type=%d, hdr_offset=%d, hdr_len=%d, pld_len=%d\n", i, layer->type, layer->hdr_offset, layer->hdr_len, layer->pld_len);
|
||||
* }
|
||||
*/
|
||||
|
||||
struct address
|
||||
{
|
||||
uint8_t family; // AF_INET or AF_INET6
|
||||
@@ -129,7 +108,7 @@ static inline int packet_get_addr(const struct packet *pkt, struct address *src_
|
||||
const struct ip *ip4_hdr = NULL;
|
||||
const struct ip6_hdr *ip6_hdr = NULL;
|
||||
const struct packet_layer *layer = NULL;
|
||||
int8_t num = packet_get_layers_number(pkt);
|
||||
int8_t num = packet_get_layer_count(pkt);
|
||||
for (int8_t i = num - 1; i >= 0; i--)
|
||||
{
|
||||
layer = packet_get_layer(pkt, i);
|
||||
@@ -173,7 +152,7 @@ static inline int packet_get_port(const struct packet *pkt, uint16_t *src_port,
|
||||
const struct tcphdr *tcp_hdr = NULL;
|
||||
const struct udphdr *udp_hdr = NULL;
|
||||
const struct packet_layer *layer = NULL;
|
||||
int8_t num = packet_get_layers_number(pkt);
|
||||
int8_t num = packet_get_layer_count(pkt);
|
||||
for (int8_t i = num - 1; i >= 0; i--)
|
||||
{
|
||||
layer = packet_get_layer(pkt, i);
|
||||
@@ -196,86 +175,6 @@ static inline int packet_get_port(const struct packet *pkt, uint16_t *src_port,
|
||||
return -1;
|
||||
}
|
||||
|
||||
static inline int packet_get_ip_hdr(const struct packet *pkt, struct ip *hdr)
|
||||
{
|
||||
const struct packet_layer *layer = NULL;
|
||||
int8_t num = packet_get_layers_number(pkt);
|
||||
for (int8_t i = num - 1; i >= 0; i--)
|
||||
{
|
||||
layer = packet_get_layer(pkt, i);
|
||||
if (layer->type == LAYER_PROTO_IPV4)
|
||||
{
|
||||
if (hdr != NULL)
|
||||
{
|
||||
memcpy(hdr, layer->hdr_ptr, sizeof(struct ip));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static inline int packet_get_ip6_hdr(const struct packet *pkt, struct ip6_hdr *hdr)
|
||||
{
|
||||
const struct packet_layer *layer = NULL;
|
||||
int8_t num = packet_get_layers_number(pkt);
|
||||
for (int8_t i = num - 1; i >= 0; i--)
|
||||
{
|
||||
layer = packet_get_layer(pkt, i);
|
||||
if (layer->type == LAYER_PROTO_IPV6)
|
||||
{
|
||||
if (hdr != NULL)
|
||||
{
|
||||
memcpy(hdr, layer->hdr_ptr, sizeof(struct ip6_hdr));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static inline int packet_get_tcp_hdr(const struct packet *pkt, struct tcphdr *hdr)
|
||||
{
|
||||
const struct packet_layer *layer = NULL;
|
||||
int8_t num = packet_get_layers_number(pkt);
|
||||
for (int8_t i = num - 1; i >= 0; i--)
|
||||
{
|
||||
layer = packet_get_layer(pkt, i);
|
||||
if (layer->type == LAYER_PROTO_TCP)
|
||||
{
|
||||
if (hdr != NULL)
|
||||
{
|
||||
memcpy(hdr, layer->hdr_ptr, sizeof(struct tcphdr));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static inline int packet_get_udp_hdr(const struct packet *pkt, struct udphdr *hdr)
|
||||
{
|
||||
const struct packet_layer *layer = NULL;
|
||||
int8_t num = packet_get_layers_number(pkt);
|
||||
for (int8_t i = num - 1; i >= 0; i--)
|
||||
{
|
||||
layer = packet_get_layer(pkt, i);
|
||||
if (layer->type == LAYER_PROTO_UDP)
|
||||
{
|
||||
if (hdr != NULL)
|
||||
{
|
||||
memcpy(hdr, layer->hdr_ptr, sizeof(struct udphdr));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -23,7 +23,7 @@ enum packet_origin packet_get_origin(const struct packet *pkt)
|
||||
return pkt->origin;
|
||||
}
|
||||
|
||||
int8_t packet_get_layers_number(const struct packet *pkt)
|
||||
int8_t packet_get_layer_count(const struct packet *pkt)
|
||||
{
|
||||
return pkt->layers_used;
|
||||
}
|
||||
|
||||
@@ -236,7 +236,7 @@ static int build_tcp_packet(const struct packet *first, uint16_t ip_id, uint8_t
|
||||
struct packet_layer *curr;
|
||||
struct packet_layer *last;
|
||||
int len = packet_get_len(first);
|
||||
int8_t layers = packet_get_layers_number(first);
|
||||
int8_t layers = packet_get_layer_count(first);
|
||||
|
||||
if ((tcp_pld == NULL && pld_len > 0) || (tcp_pld != NULL && pld_len <= 0))
|
||||
{
|
||||
@@ -323,7 +323,7 @@ static int build_udp_packet(const struct packet *first, const char *udp_pld, int
|
||||
struct packet_layer *curr;
|
||||
struct packet_layer *last;
|
||||
int len = packet_get_len(first);
|
||||
int8_t layers = packet_get_layers_number(first);
|
||||
int8_t layers = packet_get_layer_count(first);
|
||||
|
||||
if ((udp_pld == NULL && pld_len > 0) || (udp_pld != NULL && pld_len <= 0))
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@ global:
|
||||
packet_get_direction;
|
||||
packet_get_session_id;
|
||||
packet_prepend_sid_list;
|
||||
packet_get_layers_number;
|
||||
packet_get_layer_count;
|
||||
packet_get_layer;
|
||||
packet_get_data;
|
||||
packet_get_len;
|
||||
@@ -13,10 +13,6 @@ global:
|
||||
packet_get_action;
|
||||
packet_get_addr;
|
||||
packet_get_port;
|
||||
packet_get_ip_hdr;
|
||||
packet_get_ip6_hdr;
|
||||
packet_get_tcp_hdr;
|
||||
packet_get_udp_hdr;
|
||||
|
||||
session_exdata_free;
|
||||
stellar_session_exdata_new_index;
|
||||
|
||||
@@ -89,7 +89,7 @@ static void packet_to_tshark_format(const struct packet *pkt, uint64_t idx)
|
||||
char tmp_src_buff[256] = {0};
|
||||
char tmp_dst_buff[256] = {0};
|
||||
|
||||
int8_t num = packet_get_layers_number(pkt);
|
||||
int8_t num = packet_get_layer_count(pkt);
|
||||
for (int8_t i = 0; i < num; i++)
|
||||
{
|
||||
memset(tmp_src_buff, 0, sizeof(tmp_src_buff));
|
||||
|
||||
Reference in New Issue
Block a user