The friendly Operating System for the Internet of Things
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 GNRC_PKT_H
23 #define 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 
102 /* packed to be aligned correctly in the static packet buffer */
103 typedef struct gnrc_pktsnip {
109  unsigned int users;
110  struct gnrc_pktsnip *next;
111  void *data;
112  size_t size;
114 #ifdef MODULE_GNRC_NETERR
115  kernel_pid_t err_sub;
117 #endif
119 
127 static inline size_t gnrc_pkt_len(gnrc_pktsnip_t *pkt)
128 {
129  size_t len = 0;
130 
131  while (pkt) {
132  len += pkt->size;
133  pkt = pkt->next;
134  }
135 
136  return len;
137 }
138 
148 {
149  size_t len = 0;
150 
151  while (pkt) {
152  len += pkt->size;
153 
154  if (pkt->type == type) {
155  break;
156  }
157 
158  pkt = pkt->next;
159  }
160 
161  return len;
162 }
163 
171 static inline size_t gnrc_pkt_count(const gnrc_pktsnip_t *pkt)
172 {
173  size_t count = 0;
174 
175  while (pkt) {
176  ++count;
177  pkt = pkt->next;
178  }
179 
180  return count;
181 }
182 
194 
195 #ifdef __cplusplus
196 }
197 #endif
198 
199 #endif /* GNRC_PKT_H */
200 
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.
Adds include for missing inttype definitions.
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.