From 0df3aaad6c4e343547d82c8fba46e8dc276bbbba Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Mon, 15 Jan 2024 12:16:23 +0200 Subject: [PATCH] Fix WiFiUdp not updating mapped v4 address --- libraries/WiFi/src/WiFiGeneric.cpp | 15 ++++++++++++--- libraries/WiFi/src/WiFiUdp.cpp | 1 + 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/libraries/WiFi/src/WiFiGeneric.cpp b/libraries/WiFi/src/WiFiGeneric.cpp index a7fa5957e33..2fade00e450 100644 --- a/libraries/WiFi/src/WiFiGeneric.cpp +++ b/libraries/WiFi/src/WiFiGeneric.cpp @@ -1066,7 +1066,10 @@ esp_err_t WiFiGenericClass::_eventCallback(arduino_event_t *event) clearStatusBits(STA_STARTED_BIT | STA_CONNECTED_BIT | STA_HAS_IP_BIT | STA_HAS_IP6_BIT | STA_HAS_IP6_GLOBAL_BIT); } else if(event->event_id == ARDUINO_EVENT_WIFI_STA_CONNECTED) { if (getStatusBits() & STA_WANT_IP6_BIT){ - esp_netif_create_ip6_linklocal(get_esp_interface_netif(ESP_IF_WIFI_STA)); + esp_err_t err = esp_netif_create_ip6_linklocal(get_esp_interface_netif(ESP_IF_WIFI_STA)); + if(err != ESP_OK){ + log_e("Failed to enable IPv6 Link Local on STA: [%d] %s", err, esp_err_to_name(err)); + } } WiFiSTAClass::_setStatus(WL_IDLE_STATUS); setStatusBits(STA_CONNECTED_BIT); @@ -1127,7 +1130,10 @@ esp_err_t WiFiGenericClass::_eventCallback(arduino_event_t *event) } else if(event->event_id == ARDUINO_EVENT_WIFI_AP_START) { setStatusBits(AP_STARTED_BIT); if (getStatusBits() & AP_WANT_IP6_BIT){ - esp_netif_create_ip6_linklocal(get_esp_interface_netif(ESP_IF_WIFI_AP)); + esp_err_t err = esp_netif_create_ip6_linklocal(get_esp_interface_netif(ESP_IF_WIFI_AP)); + if(err != ESP_OK){ + log_e("Failed to enable IPv6 Link Local on AP: [%d] %s", err, esp_err_to_name(err)); + } } } else if(event->event_id == ARDUINO_EVENT_WIFI_AP_STOP) { clearStatusBits(AP_STARTED_BIT | AP_HAS_CLIENT_BIT); @@ -1145,7 +1151,10 @@ esp_err_t WiFiGenericClass::_eventCallback(arduino_event_t *event) clearStatusBits(ETH_STARTED_BIT | ETH_CONNECTED_BIT | ETH_HAS_IP_BIT | ETH_HAS_IP6_BIT | ETH_HAS_IP6_GLOBAL_BIT); } else if(event->event_id == ARDUINO_EVENT_ETH_CONNECTED) { if (getStatusBits() & ETH_WANT_IP6_BIT){ - esp_netif_create_ip6_linklocal(get_esp_interface_netif(ESP_IF_ETH)); + esp_err_t err = esp_netif_create_ip6_linklocal(get_esp_interface_netif(ESP_IF_ETH)); + if(err != ESP_OK){ + log_e("Failed to enable IPv6 Link Local on ETH: [%d] %s", err, esp_err_to_name(err)); + } } setStatusBits(ETH_CONNECTED_BIT); } else if(event->event_id == ARDUINO_EVENT_ETH_DISCONNECTED) { diff --git a/libraries/WiFi/src/WiFiUdp.cpp b/libraries/WiFi/src/WiFiUdp.cpp index 683ff90067c..5d8b513a2d8 100644 --- a/libraries/WiFi/src/WiFiUdp.cpp +++ b/libraries/WiFi/src/WiFiUdp.cpp @@ -321,6 +321,7 @@ int WiFiUDP::parsePacket(){ if (remote_ip.type() == IPv6 && ip6_addr_isipv4mappedipv6(ip_2_ip6(&addr))) { unmap_ipv4_mapped_ipv6(ip_2_ip4(&addr), ip_2_ip6(&addr)); IP_SET_TYPE_VAL(addr, IPADDR_TYPE_V4); + remote_ip.from_ip_addr_t(&addr); } remote_port = ntohs(si_other.sin6_port); }