* 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 */
| 804 | * @param nm_addr the new netmask address |
| 805 | */ |
| 806 | void 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. |