From ae83ab52af2b92557791e6cef6b6d7ce631ea3be Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Tue, 16 Jun 2015 17:32:34 +0200 Subject: [PATCH] net/ng_pkt: added function to count snips in pkt --- sys/include/net/ng_pkt.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/sys/include/net/ng_pkt.h b/sys/include/net/ng_pkt.h index 08ae84c0b33b..497bbf195e06 100644 --- a/sys/include/net/ng_pkt.h +++ b/sys/include/net/ng_pkt.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2014, 2015 Martine Lenders + * 2015 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 @@ -16,6 +17,7 @@ * @brief General definitions for network packets * * @author Martine Lenders + * @author Hauke Petersen */ #ifndef NG_PKT_H_ #define NG_PKT_H_ @@ -129,6 +131,25 @@ static inline size_t ng_pkt_len(ng_pktsnip_t *pkt) return len; } +/** + * @brief Count the numbers of snips in the given packet + * + * @param[in] pkt first snip in the packet + * + * @return number of snips in the given packet + */ +static inline size_t ng_pkt_count(const ng_pktsnip_t *pkt) +{ + size_t count = 0; + + while (pkt) { + ++count; + pkt = pkt->next; + } + + return count; +} + #ifdef __cplusplus } #endif