diff --git a/examples/protocols/sockets/udp_multicast/main/udp_multicast_example_main.c b/examples/protocols/sockets/udp_multicast/main/udp_multicast_example_main.c index e3bb74284..03025125b 100644 --- a/examples/protocols/sockets/udp_multicast/main/udp_multicast_example_main.c +++ b/examples/protocols/sockets/udp_multicast/main/udp_multicast_example_main.c @@ -74,6 +74,8 @@ static int socket_add_ipv4_multicast_group(int sock, bool assign_source_if) err = inet_aton(MULTICAST_IPV4_ADDR, &imreq.imr_multiaddr.s_addr); if (err != 1) { ESP_LOGE(V4TAG, "Configured IPV4 multicast address '%s' is invalid.", MULTICAST_IPV4_ADDR); + // Errors in the return value have to be negative + err = -1; goto err; } ESP_LOGI(TAG, "Configured IPV4 Multicast address %s", inet_ntoa(imreq.imr_multiaddr.s_addr)); @@ -426,6 +428,10 @@ static void mcast_example_task(void *pvParameters) ESP_LOGE(TAG, "getaddrinfo() failed for IPV4 destination address. error: %d", err); break; } + if (res == 0) { + ESP_LOGE(TAG, "getaddrinfo() did not return any addresses"); + break; + } #ifdef CONFIG_EXAMPLE_IPV4_ONLY ((struct sockaddr_in *)res->ai_addr)->sin_port = htons(UDP_PORT); inet_ntoa_r(((struct sockaddr_in *)res->ai_addr)->sin_addr, addrbuf, sizeof(addrbuf)-1);