Microchip® Advanced Software Framework

netbuf.c File Reference

Network buffer management.

#include "lwip/opt.h"
#include "lwip/netbuf.h"
#include "lwip/memp.h"
#include <string.h>

Functions

voidnetbuf_alloc (struct netbuf *buf, u16_t size)
 Allocate memory for a packet buffer for a given netbuf. More...
 
void netbuf_chain (struct netbuf *head, struct netbuf *tail)
 Chain one netbuf to another (. More...
 
err_t netbuf_data (struct netbuf *buf, void **dataptr, u16_t *len)
 Get the data pointer and length of the data inside a netbuf. More...
 
void netbuf_delete (struct netbuf *buf)
 Deallocate a netbuf allocated by netbuf_new(). More...
 
void netbuf_first (struct netbuf *buf)
 Move the current data pointer of a packet buffer contained in a netbuf to the beginning of the packet. More...
 
void netbuf_free (struct netbuf *buf)
 Free the packet buffer included in a netbuf. More...
 
struct netbuf * netbuf_new (void)
 Create (allocate) and initialize a new netbuf. More...
 
s8_t netbuf_next (struct netbuf *buf)
 Move the current data pointer of a packet buffer contained in a netbuf to the next part. More...
 
err_t netbuf_ref (struct netbuf *buf, const void *dataptr, u16_t size)
 Let a netbuf reference existing (non-volatile) data. More...
 

void* netbuf_alloc ( struct netbuf *  buf,
u16_t  size 
)

Allocate memory for a packet buffer for a given netbuf.

Parameters
bufthe netbuf for which to allocate a packet buffer
sizethe size of the packet buffer to allocate
Returns
pointer to the allocated memory NULL if no memory could be allocated

References LWIP_ASSERT, LWIP_ERROR(), NULL, pbuf_alloc(), pbuf_free(), PBUF_POOL, and PBUF_TRANSPORT.

Referenced by lwip_sendto().

void netbuf_chain ( struct netbuf *  head,
struct netbuf *  tail 
)

Chain one netbuf to another (.

See Also
pbuf_chain)
Parameters
headthe first netbuf
tailnetbuf to chain after head, freed by this function, may not be reference after returning

References LWIP_ERROR(), memp_free(), NULL, and pbuf_cat().

err_t netbuf_data ( struct netbuf *  buf,
void **  dataptr,
u16_t len 
)

Get the data pointer and length of the data inside a netbuf.

Parameters
bufnetbuf to get the data from
dataptrpointer to a void pointer where to store the data pointer
lenpointer to an u16_t where the length of the data is stored
Returns
ERR_OK if the information was retrieved, ERR_BUF on error.

References ERR_ARG, ERR_BUF, ERR_OK, LWIP_ERROR(), and NULL.

Referenced by http_request(), and sta_task().

void netbuf_delete ( struct netbuf *  buf)

Deallocate a netbuf allocated by netbuf_new().

Parameters
bufpointer to a netbuf allocated by netbuf_new()

References memp_free(), NULL, and pbuf_free().

Referenced by free_socket(), http_request(), lwip_recvfrom(), netconn_drain(), recv_raw(), recv_udp(), and sta_task().

void netbuf_first ( struct netbuf *  buf)

Move the current data pointer of a packet buffer contained in a netbuf to the beginning of the packet.

The packet buffer itself is not modified.

Parameters
bufthe netbuf to modify

References LWIP_ERROR(), and NULL.

void netbuf_free ( struct netbuf *  buf)

Free the packet buffer included in a netbuf.

Parameters
bufpointer to the netbuf which contains the packet buffer to free

References LWIP_ERROR(), NULL, and pbuf_free().

Referenced by lwip_sendto().

struct netbuf* netbuf_new ( void  )

Create (allocate) and initialize a new netbuf.

The netbuf doesn't yet contain a packet buffer!

Returns
a pointer to a new netbuf NULL on lack of memory

References ipX_addr_set_any, LWIP_IPV6, memp_malloc(), and NULL.

s8_t netbuf_next ( struct netbuf *  buf)

Move the current data pointer of a packet buffer contained in a netbuf to the next part.

The packet buffer itself is not modified.

Parameters
bufthe netbuf to modify
Returns
-1 if there is no next part 1 if moved to the next part but now there is no next part 0 if moved to the next part and there are still more parts

References LWIP_ERROR(), and NULL.

Referenced by sta_task().

err_t netbuf_ref ( struct netbuf *  buf,
const void dataptr,
u16_t  size 
)

Let a netbuf reference existing (non-volatile) data.

Parameters
bufnetbuf which should reference the data
dataptrpointer to the data to reference
sizesize of the data
Returns
ERR_OK if data is referenced ERR_MEM if data couldn't be referenced due to lack of memory

References ERR_ARG, ERR_MEM, ERR_OK, LWIP_ERROR(), NULL, pbuf_alloc(), pbuf_free(), PBUF_REF, and PBUF_TRANSPORT.

Referenced by lwip_sendto().