From 3593cb051e2d5cdf5addbd84d170a952161f4786 Mon Sep 17 00:00:00 2001 From: Eric Leblond Date: Thu, 16 Feb 2012 17:46:53 +0100 Subject: [PATCH] decode: add PacketSetData funtion This patch adds a function which can be used to set the payload of a packet when a zero copy mode is used. --- src/decode.c | 21 +++++++++++++++++++++ src/decode.h | 1 + 2 files changed, 22 insertions(+) diff --git a/src/decode.c b/src/decode.c index 443e3091dd..d345c84036 100644 --- a/src/decode.c +++ b/src/decode.c @@ -345,6 +345,27 @@ inline int PacketCopyData(Packet *p, uint8_t *pktdata, int pktlen) SET_PKT_LEN(p, (size_t)pktlen); return PacketCopyDataOffset(p, 0, pktdata, pktlen); } + + +/** + * \brief Set data for Packet and set length when zeo copy is used + * + * \param Pointer to the Packet to modify + * \param Pointer to the data + * \param Length of the data + */ +inline int PacketSetData(Packet *p, uint8_t *pktdata, int pktlen) +{ + SET_PKT_LEN(p, (size_t)pktlen); + if (!pktdata) { + return -1; + } + p->ext_pkt = pktdata; + p->flags |= PKT_ZERO_COPY; + + return 0; +} + /** * @} */ diff --git a/src/decode.h b/src/decode.h index ceff23f4d9..13a75afef2 100644 --- a/src/decode.h +++ b/src/decode.h @@ -777,6 +777,7 @@ Packet *PacketPseudoPktSetup(Packet *parent, uint8_t *pkt, uint16_t len, uint8_t Packet *PacketGetFromQueueOrAlloc(void); Packet *PacketGetFromAlloc(void); int PacketCopyData(Packet *p, uint8_t *pktdata, int pktlen); +int PacketSetData(Packet *p, uint8_t *pktdata, int pktlen); int PacketCopyDataOffset(Packet *p, int offset, uint8_t *data, int datalen); DecodeThreadVars *DecodeThreadVarsAlloc(); -- 2.47.2