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

Function netdev_set_ipaddr

components/net/netdev/src/netdev.c:651–679  ·  view source on GitHub ↗

* This function will set network interface device IP address. * * @param netdev the network interface device to change * @param ip_addr the new IP address * * @return 0: set IP address successfully * -1: set IP address failed */

Source from the content-addressed store, hash-verified

649 * -1: set IP address failed
650 */
651int netdev_set_ipaddr(struct netdev *netdev, const ip_addr_t *ip_addr)
652{
653 int err;
654 RT_ASSERT(netdev);
655 RT_ASSERT(ip_addr);
656
657 if (!netdev->ops || !netdev->ops->set_addr_info)
658 {
659 LOG_E("The network interface device(%s) not support to set IP address.", netdev->name);
660 return -RT_ERROR;
661 }
662
663 if (netdev_is_dhcp_enabled(netdev))
664 {
665 LOG_E("The network interface device(%s) DHCP capability is enable, not support set IP address.", netdev->name);
666 return -RT_ERROR;
667 }
668
669 /* execute network interface device set IP address operations */
670 err = netdev->ops->set_addr_info(netdev, (ip_addr_t *)ip_addr, RT_NULL, RT_NULL);
671
672#if defined(SAL_USING_AF_NETLINK)
673 if (err == 0)
674 rtnl_ip_notify(netdev, RTM_SETLINK);
675#endif
676
677
678 return err;
679}
680
681/**
682 * This function will set network interface device netmask address.

Callers 6

sal_ioctlsocketFunction · 0.85
test_netdev_ifconfig_setFunction · 0.85
test_netdev_config_setFunction · 0.85
set_ipaddr_wrapperFunction · 0.85
utest_tc_cleanupFunction · 0.85
netdev_set_ifFunction · 0.85

Calls

no outgoing calls

Tested by 2

test_netdev_ifconfig_setFunction · 0.68
test_netdev_config_setFunction · 0.68