mirror of
https://github.com/espressif/esp-protocols.git
synced 2025-11-16 15:29:25 +01:00
feat(console_ping): Add support for interface argument
This commit is contained in:
@@ -48,7 +48,7 @@ For more details refer [IDF Component Manager](https://docs.espressif.com/projec
|
|||||||
|
|
||||||
### ping:
|
### ping:
|
||||||
```
|
```
|
||||||
ping [-W <t>] [-i <t>] [-s <n>] [-c <n>] [-Q <n>] [-T <n>] <host>
|
ping [-W <t>] [-i <t>] [-s <n>] [-c <n>] [-Q <n>] [-T <n>] [-I <n>] <host>
|
||||||
send ICMP ECHO_REQUEST to network hosts
|
send ICMP ECHO_REQUEST to network hosts
|
||||||
-W, --timeout=<t> Time to wait for a response, in seconds
|
-W, --timeout=<t> Time to wait for a response, in seconds
|
||||||
-i, --interval=<t> Wait interval seconds between sending each packet
|
-i, --interval=<t> Wait interval seconds between sending each packet
|
||||||
@@ -56,6 +56,7 @@ ping [-W <t>] [-i <t>] [-s <n>] [-c <n>] [-Q <n>] [-T <n>] <host>
|
|||||||
-c, --count=<n> Stop after sending count packets
|
-c, --count=<n> Stop after sending count packets
|
||||||
-Q, --tos=<n> Set Type of Service related bits in IP datagrams
|
-Q, --tos=<n> Set Type of Service related bits in IP datagrams
|
||||||
-T, --ttl=<n> Set Time to Live related bits in IP datagrams
|
-T, --ttl=<n> Set Time to Live related bits in IP datagrams
|
||||||
|
-I, --interface=<n> Set Interface number 0=no-interface selected, >0 netif number + 1 (1 is usually 'lo0')
|
||||||
<host> Host address
|
<host> Host address
|
||||||
|
|
||||||
getaddrinfo [-f <AF>] [-F <FLAGS>]... [-p <port>] <hostname>
|
getaddrinfo [-f <AF>] [-F <FLAGS>]... [-p <port>] <hostname>
|
||||||
@@ -121,8 +122,8 @@ getaddrinfo -f AF_INET -F AI_PASSIVE www.example.com
|
|||||||
ping www.example.com
|
ping www.example.com
|
||||||
```
|
```
|
||||||
|
|
||||||
2. To specify additional options, such as timeout, interval, packet size, etc.:
|
2. To specify additional options, such as timeout, interval, packet size, interface, etc.:
|
||||||
|
|
||||||
```
|
```
|
||||||
ping -W 5 -i 1 -s 64 -c 4 -Q 0x10 -T 64 www.example.com
|
ping -W 5 -i 1 -s 64 -c 4 -Q 0x10 -T 64 -I 0 www.example.com
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@@ -99,6 +99,7 @@ static struct {
|
|||||||
struct arg_int *count;
|
struct arg_int *count;
|
||||||
struct arg_int *tos;
|
struct arg_int *tos;
|
||||||
struct arg_int *ttl;
|
struct arg_int *ttl;
|
||||||
|
struct arg_int *interface;
|
||||||
struct arg_str *host;
|
struct arg_str *host;
|
||||||
struct arg_end *end;
|
struct arg_end *end;
|
||||||
} ping_args;
|
} ping_args;
|
||||||
@@ -137,6 +138,10 @@ static int do_ping_cmd(int argc, char **argv)
|
|||||||
config.ttl = (uint32_t)(ping_args.ttl->ival[0]);
|
config.ttl = (uint32_t)(ping_args.ttl->ival[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ping_args.interface->count > 0) {
|
||||||
|
config.interface = (uint32_t)(ping_args.interface->ival[0]);
|
||||||
|
}
|
||||||
|
|
||||||
// parse IP address
|
// parse IP address
|
||||||
struct sockaddr_in6 sock_addr6;
|
struct sockaddr_in6 sock_addr6;
|
||||||
ip_addr_t target_addr = {0};
|
ip_addr_t target_addr = {0};
|
||||||
@@ -155,12 +160,12 @@ static int do_ping_cmd(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
if (res->ai_family == AF_INET) {
|
if (res->ai_family == AF_INET) {
|
||||||
#if CONFIG_LWIP_IPV4
|
#if CONFIG_LWIP_IPV4
|
||||||
struct in_addr addr4 = ((struct sockaddr_in *) (res->ai_addr))->sin_addr;
|
struct in_addr addr4 = ((struct sockaddr_in *)(res->ai_addr))->sin_addr;
|
||||||
inet_addr_to_ip4addr(ip_2_ip4(&target_addr), &addr4);
|
inet_addr_to_ip4addr(ip_2_ip4(&target_addr), &addr4);
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
#if CONFIG_LWIP_IPV6
|
#if CONFIG_LWIP_IPV6
|
||||||
struct in6_addr addr6 = ((struct sockaddr_in6 *) (res->ai_addr))->sin6_addr;
|
struct in6_addr addr6 = ((struct sockaddr_in6 *)(res->ai_addr))->sin6_addr;
|
||||||
inet6_addr_to_ip6addr(ip_2_ip6(&target_addr), &addr6);
|
inet6_addr_to_ip6addr(ip_2_ip6(&target_addr), &addr6);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -204,6 +209,7 @@ esp_err_t console_cmd_ping_register(void)
|
|||||||
ping_args.count = arg_int0("c", "count", "<n>", "Stop after sending count packets");
|
ping_args.count = arg_int0("c", "count", "<n>", "Stop after sending count packets");
|
||||||
ping_args.tos = arg_int0("Q", "tos", "<n>", "Set Type of Service related bits in IP datagrams");
|
ping_args.tos = arg_int0("Q", "tos", "<n>", "Set Type of Service related bits in IP datagrams");
|
||||||
ping_args.ttl = arg_int0("T", "ttl", "<n>", "Set Time to Live related bits in IP datagrams");
|
ping_args.ttl = arg_int0("T", "ttl", "<n>", "Set Time to Live related bits in IP datagrams");
|
||||||
|
ping_args.interface = arg_int0("I", "interface", "<n>", "Set Interface number");
|
||||||
ping_args.host = arg_str1(NULL, NULL, "<host>", "Host address");
|
ping_args.host = arg_str1(NULL, NULL, "<host>", "Host address");
|
||||||
ping_args.end = arg_end(1);
|
ping_args.end = arg_end(1);
|
||||||
const esp_console_cmd_t ping_cmd = {
|
const esp_console_cmd_t ping_cmd = {
|
||||||
|
|||||||
Reference in New Issue
Block a user