Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 23 additions & 16 deletions subsys/net/ip/net_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -2786,6 +2786,7 @@ static int cmd_net_ping(const struct shell *shell, size_t argc, char *argv[])
return -EOPNOTSUPP;
#else
char *host;
int times = 1;
int ret;

ARG_UNUSED(argc);
Expand All @@ -2799,26 +2800,32 @@ static int cmd_net_ping(const struct shell *shell, size_t argc, char *argv[])

shell_for_ping = shell;

if (IS_ENABLED(CONFIG_NET_IPV6)) {
ret = ping_ipv6(shell, host);
if (!ret) {
goto wait_reply;
} else if (ret == -EIO) {
PR_WARNING("Cannot send IPv6 ping\n");
return -ENOEXEC;
}
if (argv[2]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if argv[i] are set to NULL by default, if not, we need check argc as well.
if ((argc > 2) && argv[2])

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @easonxiang.
Just refer to argv [1] above.

Well.We might follow another PR Jukkar memtioned.

times = atoi(argv[2]);
}

if (IS_ENABLED(CONFIG_NET_IPV4)) {
ret = ping_ipv4(shell, host);
if (ret) {
if (ret == -EIO) {
PR_WARNING("Cannot send IPv4 ping\n");
} else if (ret == -EINVAL) {
PR_WARNING("Invalid IP address\n");
while (times--) {
if (IS_ENABLED(CONFIG_NET_IPV6)) {
ret = ping_ipv6(shell, host);
if (!ret) {
goto wait_reply;
} else if (ret == -EIO) {
PR_WARNING("Cannot send IPv6 ping\n");
return -ENOEXEC;
}
}

return -ENOEXEC;
if (IS_ENABLED(CONFIG_NET_IPV4)) {
ret = ping_ipv4(shell, host);
if (ret) {
if (ret == -EIO) {
PR_WARNING("Cannot send IPv4 ping\n");
} else if (ret == -EINVAL) {
PR_WARNING("Invalid IP address\n");
}

return -ENOEXEC;
}
}
}

Expand Down