include/net/gnrc/pkt.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014, 2015 Martine Lenders <mlenders@inf.fu-berlin.de>
3  * 2015 Freie Universit├Ąt Berlin
4  *
5  * This file is subject to the terms and conditions of the GNU Lesser
6  * General Public License v2.1. See the file LICENSE in the top level
7  * directory for more details.
8  */
9 
22 #ifndef NET_GNRC_PKT_H
23 #define NET_GNRC_PKT_H
24 
25 #include <inttypes.h>
26 #include <stdlib.h>
27 
28 #include "kernel_types.h"
29 #include "net/gnrc/nettype.h"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
106 /* packed to be aligned correctly in the static packet buffer */
107 typedef struct gnrc_pktsnip {
108  /* the first three fields *MUST* match iolist_t! */
109  struct gnrc_pktsnip *next;
110  void *data;
111  size_t size;
117  unsigned int users;
119 #ifdef MODULE_GNRC_NETERR
120  kernel_pid_t err_sub;
122 #endif
124 
132 static inline size_t gnrc_pkt_len(gnrc_pktsnip_t *pkt)
133 {
134  size_t len = 0;
135 
136  while (pkt != NULL) {
137  len += pkt->size;
138  pkt = pkt->next;
139  }
140 
141  return len;
142 }
143 
153 {
154  size_t len = 0;
155 
156  while (pkt != NULL) {
157  len += pkt->size;
158 
159  if (pkt->type == type) {
160  break;
161  }
162 
163  pkt = pkt->next;
164  }
165 
166  return len;
167 }
168 
176 static inline size_t gnrc_pkt_count(const gnrc_pktsnip_t *pkt)
177 {
178  size_t count = 0;
179 
180  while (pkt != NULL) {
181  ++count;
182  pkt = pkt->next;
183  }
184 
185  return count;
186 }
187 
199 
200 #ifdef __cplusplus
201 }
202 #endif
203 
204 #endif /* NET_GNRC_PKT_H */
205 
Types used by the kernel.
int16_t kernel_pid_t
Unique process identifier.
Definition: kernel_types.h:83
struct gnrc_pktsnip gnrc_pktsnip_t
Type to represent parts (either headers or payload) of a packet, called snips.
static size_t gnrc_pkt_count(const gnrc_pktsnip_t *pkt)
Count the numbers of snips in the given packet.
static size_t gnrc_pkt_len_upto(gnrc_pktsnip_t *pkt, gnrc_nettype_t type)
Calculates length of a packet in byte upto (including) a snip with the given type.
struct gnrc_pktsnip * next
next snip in the packet
unsigned int users
Counter of threads currently having control over this packet.
static size_t gnrc_pkt_len(gnrc_pktsnip_t *pkt)
Calculates length of a packet in byte.
gnrc_pktsnip_t * gnrc_pktsnip_search_type(gnrc_pktsnip_t *pkt, gnrc_nettype_t type)
Searches the packet for a packet snip of a specific type.
gnrc_nettype_t type
protocol of the packet snip
size_t size
the length of the snip in byte
void * data
pointer to the data of the snip
Type to represent parts (either headers or payload) of a packet, called snips.
gnrc_nettype_t
Definition of protocol types in the network stack.
Definition: nettype.h:42
stdlib.h wrapper for MSP430
Protocol type definitions.