struct pbuf {
/** next pbuf in singly linked pbuf chain */
struct pbuf *next;
/** pointer to the actual data in the buffer */
void *payload;
/**
* total length of this buffer and all next buffers in chain
* belonging to the same packet.
*
* For non-queue packet chains this is the invariant:
* p->tot_len == p->len + (p->next? p->next->tot_len: 0)
*/
u16_t tot_len;
/* length of this buffer */
u16_t len;
/* flags telling the type of pbuf */
u16_t flags;
/**
* the reference count always equals the number of pointers
* that refer to this pbuf. This can be pointers from an application,
* the stack itself, or pbuf->next pointers from a chain.
*/
u16_t ref;
};
pbuf数据结构用来存储网络中传输的每一个数据包。
next:指向同一个连接中的下一个数据包;
playload:指向数据包中的实际数据部分,即不包含各层数据包头;
tot_len:从本数据包(包含本数据包)起到后面链接的所有数据包,包含的所有实际数据部分的总长度;
len:该数据包中实际数据部分的长度;
struct netbuf {
struct pbuf *p, *ptr;
struct ip_addr *fromaddr;
u16_t fromport;
err_t err;
};
netbuf存储的是本地某个(IP,PORT)与远程某个(IP,PORT)连接之间的数据信息,可以理解为它是一个含有多个pbuf的链表。
指针p和ptr分别指向一个packet buf,p指向netbuf中的首个pbuf,ptr是一个移动的指针,指向当前访问的pbuf;
fromaddr用来保存该连接远程的IP地址;
fromport存储该连接远程端的端口号;
err保存错误信息。