mirror of
https://github.com/espressif/esp-protocols.git
synced 2025-07-29 02:07:27 +02:00
fix(mdns): fix compiling issue when disabling IPv4
This commit is contained in:
@ -21,6 +21,12 @@
|
||||
#include "driver/gpio.h"
|
||||
#include "netdb.h"
|
||||
|
||||
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 1, 0)
|
||||
/* CONFIG_LWIP_IPV4 was introduced in IDF v5.1, set CONFIG_LWIP_IPV4 to 1 by default for IDF v5.0 */
|
||||
#ifndef CONFIG_LWIP_IPV4
|
||||
#define CONFIG_LWIP_IPV4 1
|
||||
#endif // CONFIG_LWIP_IPV4
|
||||
#endif // ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 1, 0)
|
||||
|
||||
#define EXAMPLE_MDNS_INSTANCE CONFIG_MDNS_INSTANCE
|
||||
#define EXAMPLE_BUTTON_GPIO CONFIG_MDNS_BUTTON_GPIO
|
||||
@ -227,7 +233,7 @@ static void query_mdns_hosts_async(const char *host_name)
|
||||
vTaskDelay(50 / portTICK_PERIOD_MS);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef CONFIG_LWIP_IPV4
|
||||
static void query_mdns_host(const char *host_name)
|
||||
{
|
||||
ESP_LOGI(TAG, "Query A: %s.local", host_name);
|
||||
@ -247,6 +253,7 @@ static void query_mdns_host(const char *host_name)
|
||||
|
||||
ESP_LOGI(TAG, "Query A: %s.local resolved to: " IPSTR, host_name, IP2STR(&addr));
|
||||
}
|
||||
#endif // CONFIG_LWIP_IPV4
|
||||
|
||||
static void initialise_button(void)
|
||||
{
|
||||
@ -265,7 +272,9 @@ static void check_button(void)
|
||||
bool new_level = gpio_get_level(EXAMPLE_BUTTON_GPIO);
|
||||
if (!new_level && old_level) {
|
||||
query_mdns_hosts_async("esp32-mdns");
|
||||
#ifdef CONFIG_LWIP_IPV4
|
||||
query_mdns_host("esp32");
|
||||
#endif
|
||||
query_mdns_service("_arduino", "_tcp");
|
||||
query_mdns_service("_http", "_tcp");
|
||||
query_mdns_service("_printer", "_tcp");
|
||||
@ -286,7 +295,9 @@ static void mdns_example_task(void *pvParameters)
|
||||
{
|
||||
#if CONFIG_MDNS_RESOLVE_TEST_SERVICES == 1
|
||||
/* Send initial queries that are started by CI tester */
|
||||
#ifdef CONFIG_LWIP_IPV4
|
||||
query_mdns_host("tinytester");
|
||||
#endif
|
||||
query_mdns_host_with_gethostbyname("tinytester-lwip.local");
|
||||
query_mdns_host_with_getaddrinfo("tinytester-lwip.local");
|
||||
#endif
|
||||
@ -362,7 +373,16 @@ static void query_mdns_host_with_gethostbyname(char *host)
|
||||
if (res) {
|
||||
unsigned int i = 0;
|
||||
while (res->h_addr_list[i] != NULL) {
|
||||
ESP_LOGI(TAG, "gethostbyname: %s resolved to: %s", host, inet_ntoa(*(struct in_addr *) (res->h_addr_list[i])));
|
||||
ESP_LOGI(TAG, "gethostbyname: %s resolved to: %s", host,
|
||||
#if defined(CONFIG_LWIP_IPV6) && defined(CONFIG_LWIP_IPV4)
|
||||
res->h_addrtype == AF_INET ? inet_ntoa(*(struct in_addr *) (res->h_addr_list[i])) :
|
||||
inet6_ntoa(*(struct in6_addr *) (res->h_addr_list[i]))
|
||||
#elif defined(CONFIG_LWIP_IPV6)
|
||||
inet6_ntoa(*(struct in6_addr *) (res->h_addr_list[i]))
|
||||
#else
|
||||
inet_ntoa(*(struct in_addr *) (res->h_addr_list[i]))
|
||||
#endif
|
||||
);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
@ -384,10 +404,12 @@ static void query_mdns_host_with_getaddrinfo(char *host)
|
||||
if (!getaddrinfo(host, NULL, &hints, &res)) {
|
||||
while (res) {
|
||||
char *resolved_addr;
|
||||
#if CONFIG_LWIP_IPV6
|
||||
#if defined(CONFIG_LWIP_IPV6) && defined(CONFIG_LWIP_IPV4)
|
||||
resolved_addr = res->ai_family == AF_INET ?
|
||||
inet_ntoa(((struct sockaddr_in *) res->ai_addr)->sin_addr) :
|
||||
inet_ntoa(((struct sockaddr_in6 *) res->ai_addr)->sin6_addr);
|
||||
inet6_ntoa(((struct sockaddr_in6 *) res->ai_addr)->sin6_addr);
|
||||
#elif defined(CONFIG_LWIP_IPV6)
|
||||
resolved_addr = inet6_ntoa(((struct sockaddr_in6 *) res->ai_addr)->sin6_addr);
|
||||
#else
|
||||
resolved_addr = inet_ntoa(((struct sockaddr_in *) res->ai_addr)->sin_addr);
|
||||
#endif // CONFIG_LWIP_IPV6
|
||||
|
Reference in New Issue
Block a user