lwip协议之底层硬件数据交互
点对点数据在网络中传输,在不同系统中,如何保证数据传输的可靠性,可识别性,那就必须存在相应的标准,不论接收方,还是发送方,严格按照标准封装或者解封装数据,在网络中传输后,才能够正确有效的将数据提取出来,这个就依赖于tcpip协议,那么出来tcpip协议最底层的数据链路层是如何完成数据的收发呢?这里介绍下lwip链路层上网卡设备如何实现数据包的发送与接收。
在数据链路层,lwip源码中通过一个结构体netif来描述设备的网卡,结构体源码(部分成员,也是主要成员,网卡初始化不可缺少的)如下:
struct netif {
/** pointer to next in linked list */
struct netif *next; //连接netif_list链表
#if LWIP_IPV4 //基于ipv4的互联网协议
/** IP address configuration in network byte order */
ip4_addr_t ip_addr; // 网卡IP地址
ip4_addr_t netmask; // 子网掩码
ip4_addr_t gw; // 网关
#endif /* LWIP_IPV4 */
#if LWIP_IPV6 //基于ipv6的互联网协议
/** Array of IPv6 addresses for this netif. */
ip6_addr_t ip6_addr[LWIP_IPV6_NUM_ADDRESSES];
/** The state of each IPv6 address (Tentative, Preferred, etc).
* @see ip6_addr.h */
u8_t ip6_addr_state[LWIP_IPV6_NUM_ADDRESSES];
#endif /* LWIP_IPV6 */
/** This function is called by the network device driver
* to pass a packet up the TCP/IP stack. */
netif_input_fn input; //从网卡接口提取数据包送往tcpip协议栈
#if LWIP_IPV4
/** This function is called by the IP module when it wants
* to send a packet on the interface. This function typically
* first resolves the hardware address, then sends the packet. */
netif_output_fn output; //从ip层发送数据包到网络接口
#endif /* LWIP_IPV4 */
/** This function is called by the ARP module when it wants
* to send a packet on the interface. This function outputs
* the pbuf as-is on the link medium. */
netif_linkoutput_fn linkoutput; //从arp层发送数据包到网络接口
。。。