From 219fd0641f5bbe6d4555a898632b9fe53afa0616 Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Tue, 16 Jun 2015 17:34:02 +0200 Subject: [PATCH] net/ng_pktbuf: added IOVEC export function --- sys/include/net/ng_pktbuf.h | 21 ++++++++++-- .../ng_pktbuf_static/ng_pktbuf_static.c | 32 +++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/sys/include/net/ng_pktbuf.h b/sys/include/net/ng_pktbuf.h index f790399865..32655d266d 100644 --- a/sys/include/net/ng_pktbuf.h +++ b/sys/include/net/ng_pktbuf.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2014 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 @@ -24,6 +25,7 @@ * and layers can allocate space for packets here. * * @author Martine Lenders + * @author Hauke Petersen */ #ifndef NG_PKTBUF_H_ #define NG_PKTBUF_H_ @@ -156,11 +158,26 @@ void ng_pktbuf_release(ng_pktsnip_t *pkt); * @param[in] pkt The packet you want to write into. * * @return The (new) pointer to the pkt. - * @return NULL, if ng_pktsnip_t::users of @p pkt > 1 and if there is not enough - * space in the packet buffer. + * @return NULL, if ng_pktsnip_t::users of @p pkt > 1 and if there is not + * enough space in the packet buffer. */ ng_pktsnip_t *ng_pktbuf_start_write(ng_pktsnip_t *pkt); +/** + * @brief Create a IOVEC representation of the packet pointed to by *pkt* + * + * @details This function will create a new packet snip in the packet buffer, + * which points to the given *pkt* and contains a IOVEC representation + * of the referenced packet in its data section. + * + * @param[in] pkt Packet to export as IOVEC + * @param[out] len Number of elements in the IOVEC + * + * @return Pointer to the 'IOVEC packet snip' + * @return NULL, if packet is empty of the packet buffer is full + */ +ng_pktsnip_t *ng_pktbuf_get_iovec(ng_pktsnip_t *pkt, size_t *len); + /** * @brief Deletes a snip from a packet and the packet buffer. * diff --git a/sys/net/crosslayer/ng_pktbuf_static/ng_pktbuf_static.c b/sys/net/crosslayer/ng_pktbuf_static/ng_pktbuf_static.c index 20cc35a7b1..7a1fe9ef01 100644 --- a/sys/net/crosslayer/ng_pktbuf_static/ng_pktbuf_static.c +++ b/sys/net/crosslayer/ng_pktbuf_static/ng_pktbuf_static.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "mutex.h" #include "od.h" @@ -232,6 +233,37 @@ ng_pktsnip_t *ng_pktbuf_start_write(ng_pktsnip_t *pkt) return pkt; } +ng_pktsnip_t *ng_pktbuf_get_iovec(ng_pktsnip_t *pkt, size_t *len) +{ + size_t length; + ng_pktsnip_t *head; + struct iovec *vec; + + if (pkt == NULL) { + *len = 0; + return NULL; + } + + /* count the number of snips in the packet and allocate the IOVEC */ + length = ng_pkt_count(pkt); + head = ng_pktbuf_add(pkt, NULL, (length * sizeof(struct iovec)), + NG_NETTYPE_IOVEC); + if (head == NULL) { + *len = 0; + return NULL; + } + vec = (struct iovec *)(head->data); + /* fill the IOVEC */ + while (pkt != NULL) { + vec->iov_base = pkt->data; + vec->iov_len = pkt->size; + ++vec; + pkt = pkt->next; + } + *len = length; + return head; +} + #ifdef DEVELHELP #ifdef MODULE_OD static inline void _print_chunk(void *chunk, size_t size, int num)