net: shell: Allow to specify ping payload size
Add -s parameter to the net ping command, allowing to specify the payload size for the Echo Request. Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This commit is contained in:
parent
967a91dce5
commit
2b67e421a0
1 changed files with 22 additions and 11 deletions
|
@ -3913,6 +3913,7 @@ static int ping_ipv6(const struct shell *shell,
|
|||
unsigned int count,
|
||||
unsigned int interval,
|
||||
uint8_t tos,
|
||||
int payload_size,
|
||||
int iface_idx)
|
||||
{
|
||||
struct net_if *iface = net_if_get_by_index(iface_idx);
|
||||
|
@ -3952,15 +3953,13 @@ static int ping_ipv6(const struct shell *shell,
|
|||
PR("PING %s\n", host);
|
||||
|
||||
for (int i = 0; i < count; ++i) {
|
||||
uint32_t time_stamp = htonl(k_cycle_get_32());
|
||||
|
||||
ret = net_icmpv6_send_echo_request(iface,
|
||||
&ipv6_target,
|
||||
sys_rand32_get(),
|
||||
i,
|
||||
tos,
|
||||
&time_stamp,
|
||||
sizeof(time_stamp));
|
||||
NULL,
|
||||
payload_size);
|
||||
if (ret) {
|
||||
break;
|
||||
}
|
||||
|
@ -4044,6 +4043,7 @@ static int ping_ipv4(const struct shell *shell,
|
|||
unsigned int count,
|
||||
unsigned int interval,
|
||||
uint8_t tos,
|
||||
int payload_size,
|
||||
int iface_idx)
|
||||
{
|
||||
struct in_addr ipv4_target;
|
||||
|
@ -4063,15 +4063,13 @@ static int ping_ipv4(const struct shell *shell,
|
|||
PR("PING %s\n", host);
|
||||
|
||||
for (int i = 0; i < count; ++i) {
|
||||
uint32_t time_stamp = htonl(k_cycle_get_32());
|
||||
|
||||
ret = net_icmpv4_send_echo_request(iface,
|
||||
&ipv4_target,
|
||||
sys_rand32_get(),
|
||||
i,
|
||||
tos,
|
||||
&time_stamp,
|
||||
sizeof(time_stamp));
|
||||
NULL,
|
||||
payload_size);
|
||||
if (ret) {
|
||||
break;
|
||||
}
|
||||
|
@ -4134,6 +4132,7 @@ static int cmd_net_ping(const struct shell *shell, size_t argc, char *argv[])
|
|||
int interval = 1000;
|
||||
int iface_idx = -1;
|
||||
int tos = 0;
|
||||
int payload_size = 4;
|
||||
|
||||
for (size_t i = 1; i < argc; ++i) {
|
||||
|
||||
|
@ -4177,6 +4176,16 @@ static int cmd_net_ping(const struct shell *shell, size_t argc, char *argv[])
|
|||
}
|
||||
|
||||
break;
|
||||
|
||||
case 's':
|
||||
payload_size = parse_arg(&i, argc, argv);
|
||||
if (payload_size < 0 || payload_size > UINT16_MAX) {
|
||||
PR_WARNING("Parse error: %s\n", argv[i]);
|
||||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
PR_WARNING("Unrecognized argument: %s\n", argv[i]);
|
||||
return -ENOEXEC;
|
||||
|
@ -4191,7 +4200,8 @@ 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, count, interval, tos, iface_idx);
|
||||
ret = ping_ipv6(shell, host, count, interval, tos, payload_size,
|
||||
iface_idx);
|
||||
if (!ret) {
|
||||
goto wait_reply;
|
||||
} else if (ret == -EIO) {
|
||||
|
@ -4201,7 +4211,8 @@ static int cmd_net_ping(const struct shell *shell, size_t argc, char *argv[])
|
|||
}
|
||||
|
||||
if (IS_ENABLED(CONFIG_NET_IPV4)) {
|
||||
ret = ping_ipv4(shell, host, count, interval, tos, iface_idx);
|
||||
ret = ping_ipv4(shell, host, count, interval, tos, payload_size,
|
||||
iface_idx);
|
||||
if (ret) {
|
||||
if (ret == -EIO || ret == -ENETUNREACH) {
|
||||
PR_WARNING("Cannot send IPv4 ping\n");
|
||||
|
@ -5992,7 +6003,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(net_cmd_vlan,
|
|||
SHELL_STATIC_SUBCMD_SET_CREATE(net_cmd_ping,
|
||||
SHELL_CMD(--help, NULL,
|
||||
"'net ping [-c count] [-i interval ms] [-I <iface index>] "
|
||||
"[-Q tos] <host>' "
|
||||
"[-Q tos] [-s payload size] <host>' "
|
||||
"Send ICMPv4 or ICMPv6 Echo-Request to a network host.",
|
||||
cmd_net_ping),
|
||||
SHELL_SUBCMD_SET_END
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue