LWIP network interface structure-netif

Source: Internet
Author: User

In LWIP, the structure netif is used to describe a hardware network interface. In a single Nic, the structure has only one, and multiple NICs can have the same number of NICs, they constitute a data link. The following code is selected from netif. H, which is the Code Description of the netif struct:

/** Generic data structure used for all LWIP network interfaces. * The following fields shocould be filled in by the initialization * function for the device driver: hwaddr_len, hwaddr [], MTU, flags * Common data struct used for all LWIP network interfaces * the device driver function should fill in the following data domains during initialization: hwaddr_len, hwaddr [], MTU, flags. */struct netif {/** pointer to next in linked list */struct netif * Next;/** IP Address Configuration in network byte order */ Struct ip_addr; // ip address struct ip_addr netmask; // subnet mask struct ip_addr GW; // default gateway/** this function is called by the network device driver * to pass a packet up the TCP/IP stack. this function is called by a network device driver. It receives data packets from the network card and passes them to the TCP/IP protocol stack */err_t (* input) (struct pbuf * P, struct netif * indium); // receives a packet of data from the NIC/** this function is called by the IP module when it wants * to send a packet on the interface. this function ty Pically * First resolves the hardware address, then sends the packet. This function is called when the IP Module sends a packet to the interface. This function usually first parses the hardware address and then sends the packet */err_t (* output) (struct netif * netif, struct pbuf * P, // The IP layer calls this function to send a packet of data to the NIC, struct ip_addr * ipaddr ); /** 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. this function is called when the ARP module sends a data packet to the interface. This function outputs a pbuf to the link. */Err_t (* linkoutput) (struct netif * netif, struct pbuf * P ); // The ARP module calls this function to send a packet of data to the NIC # If the lwip_netif_status_callback // This function is called when the netif status is changed, not used/** this function is called when the netif state is set to up or down */void (* status_callback) (struct netif * netif ); # endif/* lwip_netif_status_callback */# If lwip_netif_link_callback // not used/** this function is called when the netif link is set to up or down when the netif connection changes */void (* link_callback) (struct netif * netif); # endif/* lwip_netif_link_callback * // ** this field can be set by the device driver and cocould point * to State information for the device. * This domain can be set through the device driver and point to the Information Status of the device for the user to use */void * State; # If lwip_dhcp // enable DHCP/** the DHCP client state information for this netif */struct DHCP * DHCP; # endif/* lwip_dhcp */# If lwip_autoip/** the autoip client state information for this netif */struct autoip * autoip; # endif # If lwip_netif_hostname/* the hostname for this netif, null is a valid value null is also a valid value */char * hostname; # endif/* lwip_netif_hostname * // ** maximum transfer unit (in bytes) Maximum sending unit (in bytes) Ethernet is 1500 */u16_t MTU; /** number of bytes used in hwaddr hardware address length */u8_t hwaddr_len; /** link level hardware address of this interface connection layer hardware address */u8_t hwaddr [netif_max_hwaddr_len]; // = 6/** flags (see netif_flag _ above) flag */u8_t flags;/** descriptive abbreviation */Char name [2];/** number of this interface Interface ID, if the two network interfaces have the same abbreviation (the name field above), use the num field to distinguish different network interfaces of the same type */u8_t num; # If lwip_snmp/** link type (from "snmp_iftype" enum from SNMP. h) connection type */u8_t link_type;/** (estimate) link speed (estimated) connection speed */u32_t link_speed;/** timestamp at last change made (up/down) the last up/down change timestamp */u32_t ts;/** counters counter */u32_t ifinoctets; u32_t counter; u32_t counter; u32_t counter; u32_t counter; u32_t counter; u32_t counter; u32_t ifoutdiscards; # endif/* lwip_snmp */# If lwip_igmp/* This function cocould be called to add or delete a entry in the multicast filter table of the Ethernet MAC. */err_t (* igmp_mac_filter) (struct netif * netif, struct ip_addr * group, u8_t action); # endif/* lwip_igmp */# If your u8_t * addr_hint; # endif/* lwip_netif_hwaddrhint */# If enable_loopback/* List of packets to be queued for ourselves. */struct pbuf * loop_first; struct pbuf * loop_last; # If your u16_t loop_cnt_current; # endif/* interval */# endif/* enable_loopback */}; // end struct netif

1. the next field points to the next netif struct pointer. This field is used only when a product has multiple NICs. LWIP will form a linked list of all NICs for management.

2. ip_addr, netmask, and GW indicate IP addresses, subnet masks, and Gateway Addresses respectively. The first two fields play an important role in sending and processing data. The third field is currently retained. You do not need to use it for communication within the same LAN. It is an exchange point for communication between one network and another. If you do not understand, you can view related books on computer network.

3. The input field points to a function that submits the data received by the NIC device to the IP layer. In use, point the input pointer to this function. The parameters are of the pbuf and netif types, where pbuf is the received data packet.

4. The output field points to a function, which is closely related to a specific network interface device. It is used to send a packet of data to the network interface at the IP layer. You need to write this function and point output to it. The parameters are of the pbuf, netif, and ip_addr types. ipaddr indicates the address to which the packet is sent, but not necessarily the IP address to which the packet is finally sent. For example, if you want to send an IP packet to a host that is not on the network, the packet will be sent to a vro, where ipaddr is the IP address of the vro.

5. The linkoutput field is similar to the output field, but there are only two parameters. It is called by the ARP module and is used to send a packet of data to the network interface. In fact, output finally calls the linkoutput field function to complete packet sending.

6. The flag field is the NIC status flag and is an important field, including Nic function enabling, broadcast enabling, ARP enabling, and so on.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.