From e9dab3203e6f67b74256711011d7465323784a1e Mon Sep 17 00:00:00 2001 From: yuanjm Date: Thu, 5 Aug 2021 10:25:07 +0800 Subject: [PATCH] ping_sock: Fix esp_ping_new_session may return ESP_OK when the error occured Closes https://github.com/espressif/esp-idf/issues/7363 --- components/lwip/apps/ping/ping_sock.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/components/lwip/apps/ping/ping_sock.c b/components/lwip/apps/ping/ping_sock.c index 00595514c5..5a6d04ce99 100644 --- a/components/lwip/apps/ping/ping_sock.c +++ b/components/lwip/apps/ping/ping_sock.c @@ -214,7 +214,7 @@ static void esp_ping_thread(void *args) esp_err_t esp_ping_new_session(const esp_ping_config_t *config, const esp_ping_callbacks_t *cbs, esp_ping_handle_t *hdl_out) { - esp_err_t ret = ESP_OK; + esp_err_t ret = ESP_FAIL; esp_ping_t *ep = NULL; PING_CHECK(config, "ping config can't be null", err, ESP_ERR_INVALID_ARG); PING_CHECK(hdl_out, "ping handle can't be null", err, ESP_ERR_INVALID_ARG); @@ -272,10 +272,12 @@ esp_err_t esp_ping_new_session(const esp_ping_config_t *config, const esp_ping_c if(config->interface) { struct ifreq iface; if(netif_index_to_name(config->interface, iface.ifr_name) == NULL) { - goto err; + ESP_LOGE(TAG, "fail to find interface name with netif index %d", config->interface); + goto err; } if(setsockopt(ep->sock, SOL_SOCKET, SO_BINDTODEVICE, &iface, sizeof(iface) !=0)) { - goto err; + ESP_LOGE(TAG, "fail to setsockopt SO_BINDTODEVICE"); + goto err; } } struct timeval timeout;