24 lines
488 B
C++
24 lines
488 B
C++
|
|
#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;
|
||
|
|
}
|