lwIP Wiki
Advertisement

netbuf_len[]

u16_t netbuf_len ( struct netbuf * aNetBuf );

Get the total length of the data in a netbuf object, taking into account all chain links.

  • in aNetBuf : the netbuf object in question
  • return : the total number of bytes contained in all chains of the netbuf object

This is actually only a macro defined as " ( ( aNetBuf )->p->tot_len )"

Example:

struct netbuf  * xNetBuf;
struct netconn * xNetConn;
...

{netconn_new, _bind, _listen, _accept}
...
if ( netconn_recv ( xNetConn, &xNetBuf ) == ERR_OK )

{   
   UInt16 xLen = netbuf_len ( xNetBuf );  // total length of data in buffer
   String xBuf = mem_malloc ( xLen );

   if ( xBuf != NULL )
      netbuf_copy ( xNetBuf, xBuf, xLen );

   netbuf_delete ( xNetBuf );
   ...
}

(last changed: Sept. 26, 2011)

Advertisement