Contiki-NG
Packet buffer

The packetbuf module does Contiki's buffer management. More...

Macros

#define PACKETBUF_SIZE   128
 The size of the packetbuf, in bytes.
 

Functions

void packetbuf_clear (void)
 Clear and reset the packetbuf. More...
 
int packetbuf_copyfrom (const void *from, uint16_t len)
 Copy from external data into the packetbuf. More...
 
int packetbuf_copyto (void *to)
 Copy the entire packetbuf to an external buffer. More...
 
int packetbuf_hdralloc (int size)
 Extend the header of the packetbuf, for outbound packets. More...
 
int packetbuf_hdrreduce (int size)
 Reduce the header in the packetbuf, for incoming packets. More...
 
void packetbuf_set_datalen (uint16_t len)
 Set the length of the data in the packetbuf. More...
 
void * packetbuf_dataptr (void)
 Get a pointer to the data in the packetbuf. More...
 
void * packetbuf_hdrptr (void)
 Get a pointer to the header in the packetbuf, for outbound packets. More...
 
uint16_t packetbuf_datalen (void)
 Get the length of the data in the packetbuf. More...
 
uint8_t packetbuf_hdrlen (void)
 Get the length of the header in the packetbuf. More...
 
uint16_t packetbuf_totlen (void)
 Get the total length of the header and data in the packetbuf. More...
 
uint16_t packetbuf_remaininglen (void)
 Get the total length of the remaining space in the packetbuf. More...
 
bool packetbuf_holds_broadcast (void)
 Checks whether the current packet is a broadcast. More...
 

Detailed Description

The packetbuf module does Contiki's buffer management.

Function Documentation

◆ packetbuf_clear()

void packetbuf_clear ( void  )

Clear and reset the packetbuf.

        This function clears the packetbuf and resets all
        internal state pointers (header size, header pointer,
        external data pointer). It is used before preparing a
        packet in the packetbuf.

Definition at line 75 of file packetbuf.c.

Referenced by output(), and packetbuf_copyfrom().

◆ packetbuf_copyfrom()

int packetbuf_copyfrom ( const void *  from,
uint16_t  len 
)

Copy from external data into the packetbuf.

Parameters
fromA pointer to the data from which to copy
lenThe size of the data to copy
Return values
Thenumber of bytes that was copied into the packetbuf
        This function copies data from a pointer into the
        packetbuf. If the data that is to be copied is larger
        than the packetbuf, only the data that fits in the
        packetbuf is copied. The number of bytes that could be
        copied into the rimbuf is returned.

Definition at line 84 of file packetbuf.c.

References packetbuf_clear().

◆ packetbuf_copyto()

int packetbuf_copyto ( void *  to)

Copy the entire packetbuf to an external buffer.

Parameters
toA pointer to the buffer to which the data is to be copied
Return values
Thenumber of bytes that was copied to the external buffer
        This function copies the packetbuf to an external
        buffer. Both the data portion and the header portion of
        the packetbuf is copied.

        The external buffer to which the packetbuf is to be
        copied must be able to accomodate at least
        PACKETBUF_SIZE bytes. The number of
        bytes that was copied to the external buffer is
        returned.

Definition at line 96 of file packetbuf.c.

◆ packetbuf_datalen()

uint16_t packetbuf_datalen ( void  )

Get the length of the data in the packetbuf.

Returns
Length of the data in the packetbuf

Definition at line 155 of file packetbuf.c.

Referenced by packetbuf_totlen(), and sixtop_input().

◆ packetbuf_dataptr()

void * packetbuf_dataptr ( void  )

Get a pointer to the data in the packetbuf.

Returns
Pointer to the packetbuf data
        This function is used to get a pointer to the data in
        the packetbuf. The data is either stored in the packetbuf,
        or referenced to an external location.

Definition at line 143 of file packetbuf.c.

Referenced by output(), and sixtop_input().

◆ packetbuf_hdralloc()

int packetbuf_hdralloc ( int  size)

Extend the header of the packetbuf, for outbound packets.

Parameters
sizeThe number of bytes the header should be extended
Return values
Non-zeroif the header could be extended, zero otherwise
        This function is used to allocate extra space in the
        header portion in the packetbuf, when preparing outbound
        packets for transmission. If the function is unable to
        allocate sufficient header space, the function returns
        zero and does not allocate anything.

Definition at line 107 of file packetbuf.c.

◆ packetbuf_hdrlen()

uint8_t packetbuf_hdrlen ( void  )

Get the length of the header in the packetbuf.

Returns
Length of the header in the packetbuf

Definition at line 161 of file packetbuf.c.

Referenced by packetbuf_totlen(), and sixtop_input().

◆ packetbuf_hdrptr()

void * packetbuf_hdrptr ( void  )

Get a pointer to the header in the packetbuf, for outbound packets.

Returns
Pointer to the packetbuf header

Definition at line 149 of file packetbuf.c.

◆ packetbuf_hdrreduce()

int packetbuf_hdrreduce ( int  size)

Reduce the header in the packetbuf, for incoming packets.

Parameters
sizeThe number of bytes the header should be reduced
Return values
Non-zeroif the header could be reduced, zero otherwise
        This function is used to remove the first part of the
        header in the packetbuf, when processing incoming
        packets. If the function is unable to remove the
        requested amount of header space, the function returns
        zero and does not allocate anything.

Definition at line 124 of file packetbuf.c.

◆ packetbuf_holds_broadcast()

bool packetbuf_holds_broadcast ( void  )

Checks whether the current packet is a broadcast.

Return values
trueiff the current packet is a broadcast

Definition at line 231 of file packetbuf.c.

References linkaddr_cmp().

◆ packetbuf_remaininglen()

uint16_t packetbuf_remaininglen ( void  )

Get the total length of the remaining space in the packetbuf.

Returns
Length of the remaining space in the packetbuf

Definition at line 173 of file packetbuf.c.

References PACKETBUF_SIZE, and packetbuf_totlen().

◆ packetbuf_set_datalen()

void packetbuf_set_datalen ( uint16_t  len)

Set the length of the data in the packetbuf.

Parameters
lenThe length of the data

Definition at line 136 of file packetbuf.c.

◆ packetbuf_totlen()

uint16_t packetbuf_totlen ( void  )

Get the total length of the header and data in the packetbuf.

Returns
Length of data and header in the packetbuf

Definition at line 167 of file packetbuf.c.

References packetbuf_datalen(), and packetbuf_hdrlen().

Referenced by packetbuf_remaininglen().