11/*
2- * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
2+ * SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
33 *
44 * SPDX-License-Identifier: Apache-2.0
55 */
@@ -99,6 +99,7 @@ static struct {
9999 struct arg_int * count ;
100100 struct arg_int * tos ;
101101 struct arg_int * ttl ;
102+ struct arg_int * interface ;
102103 struct arg_str * host ;
103104 struct arg_end * end ;
104105} ping_args ;
@@ -137,6 +138,10 @@ static int do_ping_cmd(int argc, char **argv)
137138 config .ttl = (uint32_t )(ping_args .ttl -> ival [0 ]);
138139 }
139140
141+ if (ping_args .interface -> count > 0 ) {
142+ config .interface = (uint32_t )(ping_args .interface -> ival [0 ]);
143+ }
144+
140145 // parse IP address
141146 struct sockaddr_in6 sock_addr6 ;
142147 ip_addr_t target_addr = {0 };
@@ -155,12 +160,12 @@ static int do_ping_cmd(int argc, char **argv)
155160 }
156161 if (res -> ai_family == AF_INET ) {
157162#if CONFIG_LWIP_IPV4
158- struct in_addr addr4 = ((struct sockaddr_in * ) (res -> ai_addr ))-> sin_addr ;
163+ struct in_addr addr4 = ((struct sockaddr_in * )(res -> ai_addr ))-> sin_addr ;
159164 inet_addr_to_ip4addr (ip_2_ip4 (& target_addr ), & addr4 );
160165#endif
161166 } else {
162167#if CONFIG_LWIP_IPV6
163- struct in6_addr addr6 = ((struct sockaddr_in6 * ) (res -> ai_addr ))-> sin6_addr ;
168+ struct in6_addr addr6 = ((struct sockaddr_in6 * )(res -> ai_addr ))-> sin6_addr ;
164169 inet6_addr_to_ip6addr (ip_2_ip6 (& target_addr ), & addr6 );
165170#endif
166171 }
@@ -204,6 +209,7 @@ esp_err_t console_cmd_ping_register(void)
204209 ping_args .count = arg_int0 ("c" , "count" , "<n>" , "Stop after sending count packets" );
205210 ping_args .tos = arg_int0 ("Q" , "tos" , "<n>" , "Set Type of Service related bits in IP datagrams" );
206211 ping_args .ttl = arg_int0 ("T" , "ttl" , "<n>" , "Set Time to Live related bits in IP datagrams" );
212+ ping_args .interface = arg_int0 ("I" , "interface" , "<n>" , "Set Interface number" );
207213 ping_args .host = arg_str1 (NULL , NULL , "<host>" , "Host address" );
208214 ping_args .end = arg_end (1 );
209215 const esp_console_cmd_t ping_cmd = {
0 commit comments