net/ng_pktbuf: added IOVEC export function
This commit is contained in:
parent
b7705feeff
commit
219fd0641f
@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2014 Martine Lenders <mlenders@inf.fu-berlin.de>
|
* Copyright (C) 2014 Martine Lenders <mlenders@inf.fu-berlin.de>
|
||||||
|
* 2015 Freie Universität Berlin
|
||||||
*
|
*
|
||||||
* This file is subject to the terms and conditions of the GNU Lesser
|
* 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
|
* 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.
|
* and layers can allocate space for packets here.
|
||||||
*
|
*
|
||||||
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
|
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
|
||||||
|
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
||||||
*/
|
*/
|
||||||
#ifndef NG_PKTBUF_H_
|
#ifndef NG_PKTBUF_H_
|
||||||
#define 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.
|
* @param[in] pkt The packet you want to write into.
|
||||||
*
|
*
|
||||||
* @return The (new) pointer to the pkt.
|
* @return The (new) pointer to the pkt.
|
||||||
* @return NULL, if ng_pktsnip_t::users of @p pkt > 1 and if there is not enough
|
* @return NULL, if ng_pktsnip_t::users of @p pkt > 1 and if there is not
|
||||||
* space in the packet buffer.
|
* enough space in the packet buffer.
|
||||||
*/
|
*/
|
||||||
ng_pktsnip_t *ng_pktbuf_start_write(ng_pktsnip_t *pkt);
|
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.
|
* @brief Deletes a snip from a packet and the packet buffer.
|
||||||
*
|
*
|
||||||
|
|||||||
@ -22,6 +22,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <sys/uio.h>
|
||||||
|
|
||||||
#include "mutex.h"
|
#include "mutex.h"
|
||||||
#include "od.h"
|
#include "od.h"
|
||||||
@ -232,6 +233,37 @@ ng_pktsnip_t *ng_pktbuf_start_write(ng_pktsnip_t *pkt)
|
|||||||
return 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 DEVELHELP
|
||||||
#ifdef MODULE_OD
|
#ifdef MODULE_OD
|
||||||
static inline void _print_chunk(void *chunk, size_t size, int num)
|
static inline void _print_chunk(void *chunk, size_t size, int num)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user