mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-07 14:44:32 +02:00
fix(lwip): Remove if_indextoname() impl in favor of LWIP_NETIF_API
ESP-IDF already hardcodes LWIP_NETIF_API=1, so the related netif APIs are defined unconditionally.
This commit is contained in:
committed by
David Čermák
parent
86089be928
commit
42d2a131f6
@@ -26,33 +26,6 @@
|
|||||||
#include "ping/ping_sock.h"
|
#include "ping/ping_sock.h"
|
||||||
#include "esp_check.h"
|
#include "esp_check.h"
|
||||||
|
|
||||||
#ifndef CONFIG_LWIP_NETIF_API
|
|
||||||
// If POSIX NETIF_API not enabled, we need to supply the implementation of if_indextoname()
|
|
||||||
// using tcpip_api_call()
|
|
||||||
#include "lwip/priv/tcpip_priv.h"
|
|
||||||
|
|
||||||
struct tcpip_netif_name {
|
|
||||||
struct tcpip_api_call_data call;
|
|
||||||
u8_t ifindex;
|
|
||||||
char *ifname;
|
|
||||||
};
|
|
||||||
|
|
||||||
static err_t do_netif_index_to_name(struct tcpip_api_call_data *msg)
|
|
||||||
{
|
|
||||||
struct tcpip_netif_name *params = __containerof(msg, struct tcpip_netif_name, call);
|
|
||||||
return netif_index_to_name(params->ifindex, params->ifname) ? ERR_OK : ERR_IF;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *if_indextoname(unsigned int ifindex, char *ifname)
|
|
||||||
{
|
|
||||||
struct tcpip_netif_name params = { .ifindex = ifindex, .ifname = ifname };
|
|
||||||
if (tcpip_api_call(do_netif_index_to_name, ¶ms.call) != ERR_OK) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return ifname;
|
|
||||||
}
|
|
||||||
#endif // CONFIG_LWIP_NETIF_API == 0
|
|
||||||
|
|
||||||
const static char *TAG = "ping_sock";
|
const static char *TAG = "ping_sock";
|
||||||
|
|
||||||
#define PING_TIME_DIFF_MS(_end, _start) ((uint32_t)(((_end).tv_sec - (_start).tv_sec) * 1000 + \
|
#define PING_TIME_DIFF_MS(_end, _start) ((uint32_t)(((_end).tv_sec - (_start).tv_sec) * 1000 + \
|
||||||
|
@@ -46,11 +46,7 @@ static void app_multiple_handle(esp_ip4_addr_t *ip4_addr, esp_netif_t *esp_netif
|
|||||||
*/
|
*/
|
||||||
#if CONFIG_EXAMPLE_BIND_SOCKET_TO_NETIF_NAME
|
#if CONFIG_EXAMPLE_BIND_SOCKET_TO_NETIF_NAME
|
||||||
struct ifreq ifr;
|
struct ifreq ifr;
|
||||||
#if !CONFIG_LWIP_NETIF_API
|
|
||||||
esp_netif_get_netif_impl_name(esp_netif, ifr.ifr_name);
|
|
||||||
#else
|
|
||||||
if_indextoname(esp_netif_get_netif_impl_index(esp_netif), ifr.ifr_name);
|
if_indextoname(esp_netif_get_netif_impl_index(esp_netif), ifr.ifr_name);
|
||||||
#endif
|
|
||||||
int ret = setsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE, (void*)&ifr, sizeof(struct ifreq));
|
int ret = setsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE, (void*)&ifr, sizeof(struct ifreq));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
ESP_LOGE(TAG, "\"%s\" Unable to bind socket to specified interface: errno %d", netif_name, errno);
|
ESP_LOGE(TAG, "\"%s\" Unable to bind socket to specified interface: errno %d", netif_name, errno);
|
||||||
|
Reference in New Issue
Block a user