MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / netdev_set_if

Function netdev_set_if

components/net/netdev/src/netdev.c:806–839  ·  view source on GitHub ↗

* This function will set network interface device IP, gateway and netmask address according to device name. * * @param netdev_name the network interface device name * @param ip_addr the new IP address * @param gw_addr the new gateway address * @param nm_addr the new netmask address */

Source from the content-addressed store, hash-verified

804 * @param nm_addr the new netmask address
805 */
806void netdev_set_if(char *netdev_name, char *ip_addr, char *gw_addr, char *nm_addr)
807{
808 struct netdev *netdev = RT_NULL;
809 ip_addr_t addr;
810
811 netdev = netdev_get_by_name(netdev_name);
812 if (netdev == RT_NULL)
813 {
814 rt_kprintf("bad network interface device name(%s).\n", netdev_name);
815 return;
816 }
817
818#ifdef RT_LWIP_DHCP
819 netdev_dhcp_close(netdev_name);
820#endif
821
822 /* set IP address */
823 if ((ip_addr != RT_NULL) && inet_aton(ip_addr, &addr))
824 {
825 netdev_set_ipaddr(netdev, &addr);
826 }
827
828 /* set gateway address */
829 if ((gw_addr != RT_NULL) && inet_aton(gw_addr, &addr))
830 {
831 netdev_set_gw(netdev, &addr);
832 }
833
834 /* set netmask address */
835 if ((nm_addr != RT_NULL) && inet_aton(nm_addr, &addr))
836 {
837 netdev_set_netmask(netdev, &addr);
838 }
839}
840
841/**
842 * This function will set callback to be called when the network interface device status has been changed.

Callers 2

test_netdev_config_setFunction · 0.85
ifFunction · 0.85

Calls 6

netdev_get_by_nameFunction · 0.85
rt_kprintfFunction · 0.85
netdev_dhcp_closeFunction · 0.85
netdev_set_ipaddrFunction · 0.85
netdev_set_gwFunction · 0.85
netdev_set_netmaskFunction · 0.85

Tested by 1

test_netdev_config_setFunction · 0.68