lwip学习笔记之几个重要的数据结构详解

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保存错误信息。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值