mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-27 07:21:18 +01:00
gnrc_pkt: introduce packet list operations
Up until now `utlist.h` is used to manipulate the packet list within a GNRC pkt snip. Since I always wanted to see if there would be an advantage when using `core`'s `list.h`, I provide this `gnrc_pktsnip_t`-specific API to manipulate the packet list. It has the additional advantage of type safety and that future steps could encapsulate those operations.
This commit is contained in:
parent
2df92b0d61
commit
d491e827fb
@ -27,6 +27,7 @@
|
||||
|
||||
#include "kernel_types.h"
|
||||
#include "net/gnrc/nettype.h"
|
||||
#include "utlist.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -122,6 +123,23 @@ typedef struct gnrc_pktsnip {
|
||||
#endif
|
||||
} gnrc_pktsnip_t;
|
||||
|
||||
/**
|
||||
* @brief Returns the snip before a given snip in a packet
|
||||
*
|
||||
* @param[in] pkt A packet.
|
||||
* @param[in] snip The snip for which the predecessor in @p pkt is searched for.
|
||||
*
|
||||
* @return The snip before @p snip in @p pkt if @p snip is in @p pkt.
|
||||
* @return `NULL`, if @p snip is not in @p pkt.
|
||||
*/
|
||||
static inline gnrc_pktsnip_t *gnrc_pkt_prev_snip(gnrc_pktsnip_t *pkt,
|
||||
gnrc_pktsnip_t *snip)
|
||||
{
|
||||
gnrc_pktsnip_t *prev;
|
||||
LL_SEARCH_SCALAR(pkt, prev, next, snip);
|
||||
return prev;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Calculates length of a packet in byte.
|
||||
*
|
||||
@ -141,6 +159,52 @@ static inline size_t gnrc_pkt_len(const gnrc_pktsnip_t *pkt)
|
||||
return len;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Appends a snip to a packet.
|
||||
*
|
||||
* @param[in] pkt A packet.
|
||||
* @param[in] snip A snip.
|
||||
*
|
||||
* @return The new head of @p pkt.
|
||||
*/
|
||||
static inline gnrc_pktsnip_t *gnrc_pkt_append(gnrc_pktsnip_t *pkt,
|
||||
gnrc_pktsnip_t *snip)
|
||||
{
|
||||
LL_APPEND(pkt, snip);
|
||||
return pkt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Prepends a snip to a packet.
|
||||
*
|
||||
* @param[in] pkt A packet.
|
||||
* @param[in] snip A snip.
|
||||
*
|
||||
* @return The new head of @p pkt.
|
||||
*/
|
||||
static inline gnrc_pktsnip_t *gnrc_pkt_prepend(gnrc_pktsnip_t *pkt,
|
||||
gnrc_pktsnip_t *snip)
|
||||
{
|
||||
LL_PREPEND(pkt, snip);
|
||||
return pkt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Deletes a snip from a packet.
|
||||
*
|
||||
* @param[in] pkt A packet.
|
||||
* @param[in] snip A snip.
|
||||
*
|
||||
* @return The new head of @p pkt.
|
||||
*/
|
||||
static inline gnrc_pktsnip_t *gnrc_pkt_delete(gnrc_pktsnip_t *pkt,
|
||||
gnrc_pktsnip_t *snip)
|
||||
{
|
||||
LL_DELETE(pkt, snip);
|
||||
return pkt;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Calculates length of a packet in byte up to (including) a snip with the given type.
|
||||
*
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user