@@ -62,11 +62,16 @@ static void cmd_ping_on_ping_end(esp_ping_handle_t hdl, void *args)
6262 } else {
6363 loss = 0 ;
6464 }
65+ #ifdef CONFIG_LWIP_IPV4
6566 if (IP_IS_V4 (& target_addr )) {
6667 printf ("\n--- %s ping statistics ---\n" , inet_ntoa (* ip_2_ip4 (& target_addr )));
67- } else {
68+ }
69+ #endif
70+ #ifdef CONFIG_LWIP_IPV6
71+ if (IP_IS_V6 (& target_addr )) {
6872 printf ("\n--- %s ping statistics ---\n" , inet6_ntoa (* ip_2_ip6 (& target_addr )));
6973 }
74+ #endif
7075 printf ("%" PRIu32 " packets transmitted, %" PRIu32 " received, %" PRIu32 "%% packet loss, time %" PRIu32 "ms\n" ,
7176 transmitted , received , loss , total_time_ms );
7277 // delete the ping sessions, so that we clean up all resources and can create a new ping session
@@ -81,6 +86,7 @@ static struct {
8186 struct arg_int * count ;
8287 struct arg_int * tos ;
8388 struct arg_int * ttl ;
89+ struct arg_int * interface ;
8490 struct arg_str * host ;
8591 struct arg_end * end ;
8692} ping_args ;
@@ -119,6 +125,10 @@ static int do_ping_cmd(int argc, char **argv)
119125 config .ttl = (uint32_t )(ping_args .ttl -> ival [0 ]);
120126 }
121127
128+ if (ping_args .interface -> count > 0 ) {
129+ config .interface = (uint32_t )(ping_args .interface -> ival [0 ]);
130+ }
131+
122132 // parse IP address
123133 struct sockaddr_in6 sock_addr6 ;
124134 ip_addr_t target_addr ;
@@ -136,13 +146,18 @@ static int do_ping_cmd(int argc, char **argv)
136146 printf ("ping: unknown host %s\n" , ping_args .host -> sval [0 ]);
137147 return 1 ;
138148 }
149+ #ifdef CONFIG_LWIP_IPV4
139150 if (res -> ai_family == AF_INET ) {
140151 struct in_addr addr4 = ((struct sockaddr_in * ) (res -> ai_addr ))-> sin_addr ;
141152 inet_addr_to_ip4addr (ip_2_ip4 (& target_addr ), & addr4 );
142- } else {
153+ }
154+ #endif
155+ #ifdef CONFIG_LWIP_IPV6
156+ if (res -> ai_family == AF_INET6 ) {
143157 struct in6_addr addr6 = ((struct sockaddr_in6 * ) (res -> ai_addr ))-> sin6_addr ;
144158 inet6_addr_to_ip6addr (ip_2_ip6 (& target_addr ), & addr6 );
145159 }
160+ #endif
146161 freeaddrinfo (res );
147162 }
148163 config .target_addr = target_addr ;
@@ -169,6 +184,7 @@ static void register_ping(void)
169184 ping_args .count = arg_int0 ("c" , "count" , "<n>" , "Stop after sending count packets" );
170185 ping_args .tos = arg_int0 ("Q" , "tos" , "<n>" , "Set Type of Service related bits in IP datagrams" );
171186 ping_args .ttl = arg_int0 ("T" , "ttl" , "<n>" , "Set Time to Live related bits in IP datagrams" );
187+ ping_args .interface = arg_int0 ("I" , "interface" , "<n>" , "Set Interface number" );
172188 ping_args .host = arg_str1 (NULL , NULL , "<host>" , "Host address" );
173189 ping_args .end = arg_end (1 );
174190 const esp_console_cmd_t ping_cmd = {
@@ -232,6 +248,9 @@ void app_main(void)
232248 /* automatic connection per menuconfig */
233249 ESP_ERROR_CHECK (example_connect ());
234250#endif
251+ struct ifreq ifr ;
252+ ESP_ERROR_CHECK (esp_netif_get_netif_impl_name (EXAMPLE_INTERFACE , ifr .ifr_name ));
253+ printf ("Connected on interface: %s (%d)" , ifr .ifr_name , esp_netif_get_netif_impl_index (EXAMPLE_INTERFACE ));
235254
236255 /* register command `ping` */
237256 register_ping ();
0 commit comments