Refactored packet API to support struct layer (using union to contain different types of encapsulation headers)
This commit is contained in:
23
src/packet/packet_layer.cpp
Normal file
23
src/packet/packet_layer.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#include "packet_priv.h"
|
||||
|
||||
int packet_get_layer(const struct packet *pkt, int idx, struct layer *out)
|
||||
{
|
||||
if (pkt == NULL || out == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (idx < 0 || idx >= pkt->layers_used)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
const struct raw_layer *raw = &pkt->layers[idx];
|
||||
out->proto = raw->proto;
|
||||
out->header_len = raw->hdr_len;
|
||||
out->payload_len = raw->pld_len;
|
||||
out->header.raw = raw->hdr_ptr;
|
||||
out->payload = raw->pld_ptr;
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user