This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git

commit 8f10dde6ad45c7b01c017a97db6f9c048dc2e373
Author: Zhe Weng <[email protected]>
AuthorDate: Wed Dec 28 17:47:30 2022 +0800

    ifconfig: Allow hostip on first non-option place after inet/inet6
    
    NuttX previous:
    
    ifconfig eth0 10.0.0.1 [inet]
    ifconfig eth0 2022::2 inet6
    
    Try to be compatible with other systems:
    
    Linux:
    ifconfig eth0 [inet] 10.0.0.1
    ifconfig eth0 [inet6] add 2022::2
    
    FreeBSD:
    ifconfig eth0 inet 10.0.0.1
    ifconfig eth0 inet6 2022::2
    
    NuttX newly supported:
    ifconfig eth0 [inet] 10.0.0.1
    ifconfig eth0 inet6 [add] 2022::2
    
    Ref:
    https://man7.org/linux/man-pages/man8/ifconfig.8.html
    https://www.freebsd.org/cgi/man.cgi?ifconfig
    
    Signed-off-by: Zhe Weng <[email protected]>
---
 nshlib/README.md     |  2 +-
 nshlib/nsh_netcmds.c | 12 +++++++++++-
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/nshlib/README.md b/nshlib/README.md
index efbc885cd..7968414dd 100644
--- a/nshlib/README.md
+++ b/nshlib/README.md
@@ -670,7 +670,7 @@ system image.
 
   Dump data in hexadecimal format from a file or character device.
 
-- `ifconfig [nic_name [<ip-address>|dhcp]] [dr|gw|gateway <dr-address>] 
[netmask <net-mask>] [dns <dns-address>] [hw <hw-mac>]`
+- `ifconfig [nic_name [address_family] [<ip-address>|dhcp]] [dr|gw|gateway 
<dr-address>] [netmask <net-mask>] [dns <dns-address>] [hw <hw-mac>]`
 
   Show the current configuration of the network, for example:
 
diff --git a/nshlib/nsh_netcmds.c b/nshlib/nsh_netcmds.c
index 8e804a710..2c2cbd858 100644
--- a/nshlib/nsh_netcmds.c
+++ b/nshlib/nsh_netcmds.c
@@ -698,8 +698,18 @@ int cmd_ifconfig(FAR struct nsh_vtbl_s *vtbl, int argc, 
FAR char **argv)
                     }
                 }
 #endif
-              else if (i == 2)
+              else if (!strcmp(tmp, "add"))
                 {
+                  /* Compatible with linux IPv6 command, do nothing. */
+
+                  continue;
+                }
+              else if (hostip == NULL && i <= 4)
+                {
+                  /* Let first non-option be host ip, to support inet/inet6
+                   * options before address.
+                   */
+
                   hostip = tmp;
                 }
               else

Reply via email to