* This function will set network interface device gateway address. * * @param netdev the network interface device to change * @param gw the new gateway address * * @return 0: set gateway address successfully * -1: set gateway address failed */
| 718 | * -1: set gateway address failed |
| 719 | */ |
| 720 | int netdev_set_gw(struct netdev *netdev, const ip_addr_t *gw) |
| 721 | { |
| 722 | RT_ASSERT(netdev); |
| 723 | RT_ASSERT(gw); |
| 724 | |
| 725 | if (!netdev->ops || !netdev->ops->set_addr_info) |
| 726 | { |
| 727 | LOG_E("The network interface device(%s) not support to set gateway address.", netdev->name); |
| 728 | return -RT_ERROR; |
| 729 | } |
| 730 | |
| 731 | if (netdev_is_dhcp_enabled(netdev)) |
| 732 | { |
| 733 | LOG_E("The network interface device(%s) DHCP capability is enable, not support set gateway address.", netdev->name); |
| 734 | return -RT_ERROR; |
| 735 | } |
| 736 | |
| 737 | /* execute network interface device set gateway address operations */ |
| 738 | return netdev->ops->set_addr_info(netdev, RT_NULL, RT_NULL, (ip_addr_t *)gw); |
| 739 | } |
| 740 | |
| 741 | /** |
| 742 | * This function will try to get network device and set DNS server address. |
no outgoing calls