lwIP - A Minimal TCP/IP implementation - Wikia
lwIP - A Minimal TCP/IP implementation - Wikia
lwIP - A Minimal TCP/IP implementation - Wikia
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
6 BUFFER AND MEMORY MANAGEMENT 6.1 Packet buffers — pbufs<br />
next<br />
payload<br />
len<br />
tot_len<br />
flags<br />
ref<br />
Room for link header<br />
Room for <strong>IP</strong> header<br />
Room for <strong>TCP</strong> header<br />
Figure 1. A PBUF RAM pbuf with data in memory managed by the pbuf subsystem.<br />
next<br />
payload<br />
len<br />
tot_len<br />
flags<br />
ref<br />
next<br />
payload<br />
len<br />
tot_len<br />
flags<br />
ref<br />
Figure 2.<br />
memory.<br />
A PBUF RAM pbuf chained with a PBUF ROM pbuf that has data in external<br />
Pbufs of the PBUF RAM type are also used when an application sends data that is dynamically<br />
generated. In this case, the pbuf system allocates memory not only for the application data, but<br />
also for the headers that will be prepended to the data. This is seen in Figure 1. The pbuf system<br />
cannot know in advance what headers will be prepended to the data and assumes the worst case.<br />
The size of the headers is configurable at compile time.<br />
In essence, incoming pbufs are of type PBUF POOL and outgoing pbufs are of the PBUF ROM<br />
or PBUF RAM types.<br />
The internal structure of a pbuf can be seen in the Figures 1 through 3. The pbuf structure<br />
consists of two pointers, two length fields, a flags field, and a reference count. The next field is a<br />
pointer to the next pbuf in case of a pbuf chain. The payload pointer points to the start of the<br />
data in the pbuf. The len field contains the length of the data contents of the pbuf. The tot len<br />
field contains the sum of the length of the current pbuf and all len fields of following pbufs in<br />
the pbuf chain. In other words, the tot len field is the sum of the len field and the value of the<br />
tot len field in the following pbuf in the pbuf chain. The flags field indicates the type of the<br />
pbuf and the ref field contains a reference count. The next and payload fields are native pointers<br />
and the size of those varies depending on the processor architecture used. The two length fields<br />
4