Nut/OS  4.10.3
API Reference
Network Buffer

Network buffer support. More...

Collaboration diagram for Network Buffer:

Data Structures

struct  _NBDATA
 Data part of a network buffer structure. More...
struct  _NETBUF
 Network buffer structure. More...

Defines

#define NBAF_REFCNT   0x07
 Reference count mask.
#define NBAF_UNICAST   0x08
 Unicast address.
#define NBAF_DATALINK   0x10
 Datalink buffer allocated flag.
#define NBAF_NETWORK   0x20
 Network buffer allocated flag.
#define NBAF_TRANSPORT   0x40
 Transport buffer allocated flag.
#define NBAF_APPLICATION   0x80
 Application buffer allocated flag.
#define NBAF_ALL   0xf0
 Masks allocated buffer flags flag.

Typedefs

typedef struct _NETBUF NETBUF
 Network buffer type.
typedef struct _NBDATA NBDATA
 Network buffer data type.

Functions

NETBUFNutNetBufAlloc (NETBUF *nb, uint8_t type, int size)
 Allocate or re-allocate a network buffer part.
NETBUFNutNetBufClonePart (NETBUF *nb, uint8_t inserts)
 Create a referencing copy of an existing network buffer structure.
NETBUFNutNetBufClone (NETBUF *nb)
 Create a copy of an existing network buffer structure.
void NutNetBufFree (NETBUF *nb)
 Release a network buffer structure.
int NutNetBufCollect (NETBUF *nbq, int total)
 Collect linked list of network buffers.

Detailed Description

Network buffer support.

The network buffer handling is designed to make life easy when it comes to handling ISO-layered communications. By this we're thinking about communications structures that are hierarchically organized.

The idea is that network buffer structures are allocated every time a new packet is either received or ready for sending. The various fields of the network buffer are then handled by matching layers within the appropriate protocol stack.

Linked list of NETBUF structures:

dot_inline_dotgraph_3.png

Define Documentation

#define NBAF_REFCNT   0x07

Reference count mask.

Definition at line 127 of file netbuf.h.

Referenced by NutNetBufClonePart(), and NutNetBufFree().

#define NBAF_UNICAST   0x08

Unicast address.

Definition at line 129 of file netbuf.h.

Referenced by NutIpInput(), NutTcpInput(), and NutUdpInput().

#define NBAF_DATALINK   0x10

Datalink buffer allocated flag.

Definition at line 131 of file netbuf.h.

Referenced by AhdlcRx(), CSNICrx(), NutEtherOutput(), NutNetBufAlloc(), NutNetBufClonePart(), NutNetBufFree(), and NutPppOutput().

#define NBAF_NETWORK   0x20

Network buffer allocated flag.

Definition at line 132 of file netbuf.h.

Referenced by NutArpAllocNetBuf(), NutIpcpOutput(), NutIpOutput(), NutLcpOutput(), NutNetBufAlloc(), NutNetBufClonePart(), NutNetBufFree(), and NutPapOutput().

#define NBAF_TRANSPORT   0x40

Transport buffer allocated flag.

Definition at line 133 of file netbuf.h.

Referenced by NutIcmpReply(), NutIgmpOutput(), NutNetBufAlloc(), NutNetBufClonePart(), NutNetBufFree(), NutTcpOutput(), and NutUdpOutput().

#define NBAF_APPLICATION   0x80
#define NBAF_ALL   0xf0

Masks allocated buffer flags flag.

Definition at line 135 of file netbuf.h.

Referenced by NutNetBufClone(), and NutNetBufClonePart().


Typedef Documentation

typedef struct _NETBUF NETBUF

Network buffer type.

Definition at line 140 of file netbuf.h.

typedef struct _NBDATA NBDATA

Network buffer data type.

Definition at line 145 of file netbuf.h.


Function Documentation

NETBUF* NutNetBufAlloc ( NETBUF nb,
uint8_t  type,
int  size 
)

Allocate or re-allocate a network buffer part.

Parameters:
nbPoints to an existing network buffer structure or NULL, if a new structure should be created. An existing buffer must not be used any further if this function returns a null pointer.
typePart of the buffer to be allocated. This can be any of the following:
  • NBAF_DATALINK
  • NBAF_NETWORK
  • NBAF_TRANSPORT
  • NBAF_APPLICATION
sizeSize of the part to be allocated.
Returns:
Pointer to the allocated network buffer structure. A null pointer is returned if not enough memory is available and the whole structure is released.

Definition at line 173 of file netbuf.c.

References _NETBUF::nb_ap, _NETBUF::nb_dl, _NETBUF::nb_flags, _NETBUF::nb_nw, _NETBUF::nb_tp, NBAF_APPLICATION, NBAF_DATALINK, NBAF_NETWORK, NBAF_TRANSPORT, NUTASSERT, NutHeapAllocClear, NutHeapFree, NutNetBufFree(), _NBDATA::sz, and _NBDATA::vp.

Referenced by AhdlcRx(), CSNICrx(), IpcpTxConfReq(), LcpTxConfReq(), LcpTxProtRej(), NutArpAllocNetBuf(), NutEtherOutput(), NutIcmpReply(), NutIcmpResponse(), NutIgmpOutput(), NutIpcpOutput(), NutIpOutput(), NutLcpOutput(), NutPapOutput(), NutPppOutput(), NutTcpOutput(), NutUdpOutput(), NutUdpSendTo(), and PapTxAuthReq().

Here is the call graph for this function:

NETBUF* NutNetBufClonePart ( NETBUF nb,
uint8_t  inserts 
)

Create a referencing copy of an existing network buffer structure.

Parameters:
nbPoints to an existing network buffer structure, previously allocated by NutNetBufAlloc().
typePart of the buffer to be additionally allocated. This can be any combination of the following flags:
  • NBAF_DATALINK
  • NBAF_NETWORK
  • NBAF_TRANSPORT
  • NBAF_APPLICATION
Returns:
Pointer to a newly allocated copy.

Definition at line 255 of file netbuf.c.

References memcpy(), _NETBUF::nb_ap, _NETBUF::nb_dl, _NETBUF::nb_flags, _NETBUF::nb_nw, _NETBUF::nb_ref, _NETBUF::nb_tp, NBAF_ALL, NBAF_APPLICATION, NBAF_DATALINK, NBAF_NETWORK, NBAF_REFCNT, NBAF_TRANSPORT, NUTASSERT, NutHeapAllocClear, NutNetBufFree(), _NBDATA::sz, and _NBDATA::vp.

Referenced by NutIpOutput(), NutNetBufClone(), and NutTcpOutput().

Here is the call graph for this function:

NETBUF* NutNetBufClone ( NETBUF nb)

Create a copy of an existing network buffer structure.

Parameters:
nbPoints to an existing network buffer structure, previously allocated by NutNetBufAlloc().
Returns:
Pointer to a newly allocated copy.

Definition at line 349 of file netbuf.c.

References NBAF_ALL, and NutNetBufClonePart().

Here is the call graph for this function:

int NutNetBufCollect ( NETBUF nbq,
int  total 
)

Collect linked list of network buffers.

Parameters:
nbqPoints to an existing network buffer queue.
Returns:
Number of released network buffers.

Definition at line 397 of file netbuf.c.

References memcpy(), _NETBUF::nb_ap, _NETBUF::nb_flags, _NETBUF::nb_next, NBAF_APPLICATION, NutHeapFree, NutNetBufFree(), _NBDATA::sz, and _NBDATA::vp.

Here is the call graph for this function: