From c64342388e70f381f038e918d4b9f133aa92e696 Mon Sep 17 00:00:00 2001 From: patacongo Date: Sat, 21 May 2011 18:25:31 +0000 Subject: [PATCH] Add E1000 PIC NIC driver from Yu Qiang git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3638 42af7a65-404d-4744-a932-0658087f49c3 --- ChangeLog.txt | 4 ++++ nshlib/nsh_netcmds.c | 44 ++++++++++++++++++++++++++++++++++++++++++-- nshlib/nsh_parse.c | 2 +- 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index a17488542..495268cb7 100755 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -49,3 +49,7 @@ on initial check-in. 6.4 2011-xx-xx Gregory Nutt + + * nshlib/nsh_netcmds.c: If a network device name and IP address are provided + with the ifconfig command, then this command will now set the network address. + diff --git a/nshlib/nsh_netcmds.c b/nshlib/nsh_netcmds.c index 1bd1e93e4..6e210c020 100644 --- a/nshlib/nsh_netcmds.c +++ b/nshlib/nsh_netcmds.c @@ -466,8 +466,48 @@ int cmd_get(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) #ifndef CONFIG_NSH_DISABLE_IFCONFIG int cmd_ifconfig(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) { - netdev_foreach(ifconfig_callback, vtbl); - uip_statistics(vtbl); + struct in_addr addr; + in_addr_t ip; + + /* With one or no arguments, ifconfig simply shows the status of ethernet + * device: + * + * ifconfig + * ifconfig [nic_name] + */ + + if (argc <= 2) + { + netdev_foreach(ifconfig_callback, vtbl); + uip_statistics(vtbl); + return OK; + } + + /* If both the network interface name and an IP address are supplied as + * arguments, then ifconfig will set the address of the ethernet device: + * + * ifconfig nic_name ip_address + */ + + /* Set host ip address */ + + ip = addr.s_addr = inet_addr(argv[2]); + uip_sethostaddr(argv[1], &addr); + + /* Set gateway */ + + ip = NTOHL(ip); + ip &= ~0x000000ff; + ip |= 0x00000001; + + addr.s_addr = HTONL(ip); + uip_setdraddr(argv[1], &addr); + + /* Set netmask */ + + addr.s_addr = inet_addr("255.255.255.0"); + uip_setnetmask(argv[1], &addr); + return OK; } #endif diff --git a/nshlib/nsh_parse.c b/nshlib/nsh_parse.c index ef861b2de..f6a778a03 100644 --- a/nshlib/nsh_parse.c +++ b/nshlib/nsh_parse.c @@ -191,7 +191,7 @@ static const struct cmdmap_s g_cmdmap[] = #ifdef CONFIG_NET # ifndef CONFIG_NSH_DISABLE_IFCONFIG - { "ifconfig", cmd_ifconfig, 1, 1, NULL }, + { "ifconfig", cmd_ifconfig, 1, 3, "[nic_name [ip]]" }, # endif #endif