diff --git a/Makefile.dep b/Makefile.dep index 289bebf9ccf89b33a34dcfdf064fb0a63c5ecda4..09eda5895331f111724b66b2f88b81bafe6e6a94 100644 --- a/Makefile.dep +++ b/Makefile.dep @@ -379,6 +379,7 @@ ifneq (,$(filter gnrc_pktbuf, $(USEMODULE))) ifeq (,$(filter gnrc_pktbuf_%, $(USEMODULE))) USEMODULE += gnrc_pktbuf_static endif + USEMODULE += gnrc_pkt endif ifneq (,$(filter gnrc_pktbuf_%, $(USEMODULE))) diff --git a/sys/include/net/gnrc/pkt.h b/sys/include/net/gnrc/pkt.h index 7d4ab80dd23ddfc0f20cff215403ff1c9de71a3b..2fb788c5389ce5f2acfba8e6ed5b4e0574ff7503 100644 --- a/sys/include/net/gnrc/pkt.h +++ b/sys/include/net/gnrc/pkt.h @@ -155,6 +155,18 @@ static inline size_t gnrc_pkt_count(const gnrc_pktsnip_t *pkt) return count; } +/** + * @brief Searches the packet for a packet snip of a specific type + * + * @param[in] pkt list of packet snips + * @param[in] type the type to search for + * + * @return the packet snip in @p pkt with @ref gnrc_nettype_t @p type + * @return NULL, if none of the snips in @p pkt is of @p type + */ +gnrc_pktsnip_t *gnrc_pktsnip_search_type(gnrc_pktsnip_t *pkt, + gnrc_nettype_t type); + #ifdef __cplusplus } #endif diff --git a/sys/net/gnrc/Makefile b/sys/net/gnrc/Makefile index 28e2d4f39060004f7b971579a3d365ff2c7442fc..35f8e41e761d13c3568f4355c2660b5abea64ba9 100644 --- a/sys/net/gnrc/Makefile +++ b/sys/net/gnrc/Makefile @@ -73,6 +73,9 @@ endif ifneq (,$(filter gnrc_nomac,$(USEMODULE))) DIRS += link_layer/nomac endif +ifneq (,$(filter gnrc_pkt,$(USEMODULE))) + DIRS += pkt +endif ifneq (,$(filter gnrc_pktbuf_static,$(USEMODULE))) DIRS += pktbuf_static endif diff --git a/sys/net/gnrc/pkt/Makefile b/sys/net/gnrc/pkt/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..60a0221a53e08f891cf61a4c8c35e673a654aeaa --- /dev/null +++ b/sys/net/gnrc/pkt/Makefile @@ -0,0 +1,3 @@ +MODULE := gnrc_pkt + +include $(RIOTBASE)/Makefile.base diff --git a/sys/net/gnrc/pkt/gnrc_pkt.c b/sys/net/gnrc/pkt/gnrc_pkt.c new file mode 100644 index 0000000000000000000000000000000000000000..1a9c51d5de58e8c6bcc78f8902975cdf9fa6e8a1 --- /dev/null +++ b/sys/net/gnrc/pkt/gnrc_pkt.c @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2016 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @{ + * + * @file + * @author Martine Lenders <mlenders@inf.fu-berlin.de> + */ + +#include <assert.h> + +#include "net/gnrc/pkt.h" + +gnrc_pktsnip_t *gnrc_pktsnip_search_type(gnrc_pktsnip_t *ptr, + gnrc_nettype_t type) +{ + while (ptr != NULL) { + if (ptr->type == type) { + return ptr; + } + ptr = ptr->next; + } + return NULL; +} + +/** @} */