From def1304b4ac551e66d9b5b7a471393d2d904dd09 Mon Sep 17 00:00:00 2001 From: David Cermak Date: Tue, 29 Sep 2020 16:14:25 +0200 Subject: [PATCH] examples: Fix socket examples to uses IPv6 scoped addresses from tcpip_adapter API --- examples/protocols/sockets/tcp_client/main/tcp_client.c | 8 +++++++- examples/protocols/sockets/udp_client/main/udp_client.c | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/examples/protocols/sockets/tcp_client/main/tcp_client.c b/examples/protocols/sockets/tcp_client/main/tcp_client.c index b0e623effa..3d8a6759a3 100644 --- a/examples/protocols/sockets/tcp_client/main/tcp_client.c +++ b/examples/protocols/sockets/tcp_client/main/tcp_client.c @@ -31,6 +31,12 @@ #define HOST_IP_ADDR CONFIG_EXAMPLE_IPV6_ADDR #endif +#ifdef CONFIG_EXAMPLE_CONNECT_ETHERNET +#define EXAMPLE_INTERFACE TCPIP_ADAPTER_IF_ETH +#elif CONFIG_EXAMPLE_CONNECT_WIFI +#define EXAMPLE_INTERFACE TCPIP_ADAPTER_IF_STA +#endif + #define PORT CONFIG_EXAMPLE_PORT static const char *TAG = "example"; @@ -59,7 +65,7 @@ static void tcp_client_task(void *pvParameters) dest_addr.sin6_family = AF_INET6; dest_addr.sin6_port = htons(PORT); // Setting scope_id to the connecting interface for correct routing if IPv6 Local Link supplied - dest_addr.sin6_scope_id = esp_netif_get_netif_impl_index(EXAMPLE_INTERFACE); + dest_addr.sin6_scope_id = tcpip_adapter_get_netif_index(EXAMPLE_INTERFACE); addr_family = AF_INET6; ip_protocol = IPPROTO_IPV6; inet6_ntoa_r(dest_addr.sin6_addr, addr_str, sizeof(addr_str) - 1); diff --git a/examples/protocols/sockets/udp_client/main/udp_client.c b/examples/protocols/sockets/udp_client/main/udp_client.c index 3ae24872ab..dfa471231a 100644 --- a/examples/protocols/sockets/udp_client/main/udp_client.c +++ b/examples/protocols/sockets/udp_client/main/udp_client.c @@ -31,6 +31,12 @@ #define HOST_IP_ADDR CONFIG_EXAMPLE_IPV6_ADDR #endif +#ifdef CONFIG_EXAMPLE_CONNECT_ETHERNET +#define EXAMPLE_INTERFACE TCPIP_ADAPTER_IF_ETH +#elif CONFIG_EXAMPLE_CONNECT_WIFI +#define EXAMPLE_INTERFACE TCPIP_ADAPTER_IF_STA +#endif + #define PORT CONFIG_EXAMPLE_PORT static const char *TAG = "example"; @@ -60,7 +66,7 @@ static void udp_client_task(void *pvParameters) dest_addr.sin6_family = AF_INET6; dest_addr.sin6_port = htons(PORT); // Setting scope_id to the connecting interface for correct routing if IPv6 Local Link supplied - dest_addr.sin6_scope_id = esp_netif_get_netif_impl_index(EXAMPLE_INTERFACE); + dest_addr.sin6_scope_id = tcpip_adapter_get_netif_index(EXAMPLE_INTERFACE); addr_family = AF_INET6; ip_protocol = IPPROTO_IPV6; inet6_ntoa_r(dest_addr.sin6_addr, addr_str, sizeof(addr_str) - 1);