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 <wengzhe@xiaomi.com>
This commit is contained in:
Zhe Weng 2022-12-28 17:47:30 +08:00 committed by Xiang Xiao
parent 19958f0428
commit 8f10dde6ad
2 changed files with 12 additions and 2 deletions

View File

@ -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:

View File

@ -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