update list_if() and set_if()
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1833 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
parent
a5a7c47d04
commit
dc540968c4
|
@ -293,30 +293,44 @@ rt_err_t eth_system_device_init()
|
||||||
|
|
||||||
#ifdef RT_USING_FINSH
|
#ifdef RT_USING_FINSH
|
||||||
#include <finsh.h>
|
#include <finsh.h>
|
||||||
void set_if(char* ip_addr, char* gw_addr, char* nm_addr)
|
void set_if(char* netif_name, char* ip_addr, char* gw_addr, char* nm_addr)
|
||||||
{
|
{
|
||||||
struct ip_addr *ip;
|
struct ip_addr *ip;
|
||||||
struct in_addr addr;
|
struct in_addr addr;
|
||||||
|
struct netif * netif = netif_list;
|
||||||
|
|
||||||
ip = (struct ip_addr *)&addr;
|
while(netif != RT_NULL)
|
||||||
|
{
|
||||||
|
if(strncmp(netif_name, netif->name, sizeof(netif->name)) == 0)
|
||||||
|
break;
|
||||||
|
|
||||||
/* set ip address */
|
netif = netif->next;
|
||||||
if ((ip_addr != RT_NULL) && inet_aton(ip_addr, &addr))
|
if( netif == netif_list )
|
||||||
{
|
{
|
||||||
netif_set_ipaddr(netif_default, ip);
|
rt_kprintf("network interface: %c%c not found!\r\n", netif->name[0], netif->name[1]);
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* set gateway address */
|
ip = (struct ip_addr *)&addr;
|
||||||
if ((gw_addr != RT_NULL) && inet_aton(gw_addr, &addr))
|
|
||||||
{
|
|
||||||
netif_set_gw(netif_default, ip);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* set netmask address */
|
/* set ip address */
|
||||||
if ((nm_addr != RT_NULL) && inet_aton(nm_addr, &addr))
|
if ((ip_addr != RT_NULL) && inet_aton(ip_addr, &addr))
|
||||||
{
|
{
|
||||||
netif_set_netmask(netif_default, ip);
|
netif_set_ipaddr(netif, ip);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* set gateway address */
|
||||||
|
if ((gw_addr != RT_NULL) && inet_aton(gw_addr, &addr))
|
||||||
|
{
|
||||||
|
netif_set_gw(netif, ip);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* set netmask address */
|
||||||
|
if ((nm_addr != RT_NULL) && inet_aton(nm_addr, &addr))
|
||||||
|
{
|
||||||
|
netif_set_netmask(netif, ip);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
FINSH_FUNCTION_EXPORT(set_if, set network interface address);
|
FINSH_FUNCTION_EXPORT(set_if, set network interface address);
|
||||||
|
|
||||||
|
@ -334,37 +348,53 @@ void set_dns(char* dns_server)
|
||||||
FINSH_FUNCTION_EXPORT(set_dns, set DNS server address);
|
FINSH_FUNCTION_EXPORT(set_dns, set DNS server address);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void list_if()
|
void list_if(void)
|
||||||
{
|
{
|
||||||
rt_ubase_t index;
|
rt_ubase_t index;
|
||||||
|
struct netif * netif;
|
||||||
|
|
||||||
rt_kprintf("Default network interface: %c%c\n", netif_default->name[0], netif_default->name[1]);
|
netif = netif_list;
|
||||||
rt_kprintf("MTU: %d\n", netif_default->mtu);
|
|
||||||
rt_kprintf("MAC: ");
|
while( netif != RT_NULL )
|
||||||
for (index = 0; index < netif_default->hwaddr_len; index ++)
|
{
|
||||||
rt_kprintf("%02x ", netif_default->hwaddr[index]);
|
rt_kprintf("network interface: %c%c%s\n", netif->name[0], netif->name[1], (netif == netif_default)?" (Default)":"");
|
||||||
rt_kprintf("\nFLAGS:");
|
rt_kprintf("MTU: %d\n", netif->mtu);
|
||||||
if (netif_default->flags & NETIF_FLAG_UP) rt_kprintf(" UP");
|
rt_kprintf("MAC: ");
|
||||||
else rt_kprintf(" DOWN");
|
for (index = 0; index < netif->hwaddr_len; index ++)
|
||||||
if (netif_default->flags & NETIF_FLAG_LINK_UP) rt_kprintf(" LINK_UP");
|
rt_kprintf("%02x ", netif->hwaddr[index]);
|
||||||
else rt_kprintf(" LINK_DOWN");
|
rt_kprintf("\nFLAGS:");
|
||||||
if (netif_default->flags & NETIF_FLAG_DHCP) rt_kprintf(" DHCP");
|
if (netif->flags & NETIF_FLAG_UP) rt_kprintf(" UP");
|
||||||
if (netif_default->flags & NETIF_FLAG_POINTTOPOINT) rt_kprintf(" PPP");
|
else rt_kprintf(" DOWN");
|
||||||
if (netif_default->flags & NETIF_FLAG_ETHARP) rt_kprintf(" ETHARP");
|
if (netif->flags & NETIF_FLAG_LINK_UP) rt_kprintf(" LINK_UP");
|
||||||
if (netif_default->flags & NETIF_FLAG_IGMP) rt_kprintf(" IGMP");
|
else rt_kprintf(" LINK_DOWN");
|
||||||
rt_kprintf("\n");
|
if (netif->flags & NETIF_FLAG_DHCP) rt_kprintf(" DHCP");
|
||||||
rt_kprintf("ip address: %s\n", inet_ntoa(*((struct in_addr*)&(netif_default->ip_addr))));
|
if (netif->flags & NETIF_FLAG_POINTTOPOINT) rt_kprintf(" PPP");
|
||||||
rt_kprintf("gw address: %s\n", inet_ntoa(*((struct in_addr*)&(netif_default->gw))));
|
if (netif->flags & NETIF_FLAG_ETHARP) rt_kprintf(" ETHARP");
|
||||||
rt_kprintf("net mask : %s\n", inet_ntoa(*((struct in_addr*)&(netif_default->netmask))));
|
if (netif->flags & NETIF_FLAG_IGMP) rt_kprintf(" IGMP");
|
||||||
|
rt_kprintf("\n");
|
||||||
|
rt_kprintf("ip address: %s\n", inet_ntoa(*((struct in_addr*)&(netif->ip_addr))));
|
||||||
|
rt_kprintf("gw address: %s\n", inet_ntoa(*((struct in_addr*)&(netif->gw))));
|
||||||
|
rt_kprintf("net mask : %s\n", inet_ntoa(*((struct in_addr*)&(netif->netmask))));
|
||||||
|
rt_kprintf("\r\n");
|
||||||
|
|
||||||
|
netif = netif->next;
|
||||||
|
if( netif == netif_list )
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#if LWIP_DNS
|
#if LWIP_DNS
|
||||||
{
|
{
|
||||||
struct ip_addr ip_addr;
|
struct ip_addr ip_addr;
|
||||||
|
|
||||||
ip_addr = dns_getserver(0);
|
for(index=0; index<DNS_MAX_SERVERS; index++)
|
||||||
rt_kprintf("dns server: %s\n", inet_ntoa(*((struct in_addr*)&(ip_addr))));
|
{
|
||||||
}
|
ip_addr = dns_getserver(index);
|
||||||
#endif
|
rt_kprintf("dns server #%d: %s\n", index, inet_ntoa(*((struct in_addr*)&(ip_addr))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif /**< #if LWIP_DNS */
|
||||||
}
|
}
|
||||||
FINSH_FUNCTION_EXPORT(list_if, list network interface information);
|
FINSH_FUNCTION_EXPORT(list_if, list network interface information);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue