* 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 */
| 649 | * -1: set IP address failed |
| 650 | */ |
| 651 | int 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. |
no outgoing calls