From 8a80bccb3cef3ff3f1c3800643569bbd06b1a08a Mon Sep 17 00:00:00 2001 From: s-hadinger <49731213+s-hadinger@users.noreply.github.com> Date: Wed, 30 Oct 2024 18:18:06 +0100 Subject: [PATCH 1/2] IPv6 restore zone id This PR restores the IPv6 zone-id in String representation of IPv6 address as well as parsing. This follows https://github.com/espressif/arduino-esp32/commit/20a28b58bc3fd5ff613e2860d65e0953446f264b that disabled it due to a crash in `netif_index_to_name()`. The fixed code scans through `netif_list` to find the `netif` name and id. Note: zone-id are incremented by 1 compared to `netif` id. For example internal zoneid value `3` actually translates to `%st2` --- cores/esp32/IPAddress.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/cores/esp32/IPAddress.cpp b/cores/esp32/IPAddress.cpp index 74fabaf0f9c..a6f564637ad 100644 --- a/cores/esp32/IPAddress.cpp +++ b/cores/esp32/IPAddress.cpp @@ -201,7 +201,13 @@ bool IPAddress::fromString6(const char *address) { colons++; acc = 0; } else if (c == '%') { - _zone = netif_name_to_index(address); + // netif_index_to_name crashes on latest esp-idf + // _zone = netif_name_to_index(address); + // in the interim, we parse the suffix as a zone number + while ((*address != '\0') && (!isdigit(*address))) { // skip all non-digit after '%' + address++; + } + _zone = atol(address) + 1; // increase by one by convention, so we can have zone '0' while (*address != '\0') { address++; } @@ -351,6 +357,19 @@ size_t IPAddress::printTo(Print &p, bool includeZone) const { // netif_index_to_name(_zone, if_name); // n += p.print(if_name); // } + // In the interim, we just output the index number + if (_zone > 0 && includeZone) { + n += p.print('%'); + // look for the interface name + for (netif* intf = netif_list; intf != nullptr; intf = intf->next) { + if (_zone - 1 == intf->num) { + n += p.print(intf->name[0]); + n += p.print(intf->name[1]); + break; + } + } + n += p.print(_zone - 1); + } return n; } From a750bdb77818b09f6351f17803c8fc38cb444f05 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Mon, 4 Nov 2024 21:48:18 +0000 Subject: [PATCH 2/2] ci(pre-commit): Apply automatic fixes --- cores/esp32/IPAddress.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cores/esp32/IPAddress.cpp b/cores/esp32/IPAddress.cpp index a6f564637ad..1fd2a08e9c5 100644 --- a/cores/esp32/IPAddress.cpp +++ b/cores/esp32/IPAddress.cpp @@ -204,10 +204,10 @@ bool IPAddress::fromString6(const char *address) { // netif_index_to_name crashes on latest esp-idf // _zone = netif_name_to_index(address); // in the interim, we parse the suffix as a zone number - while ((*address != '\0') && (!isdigit(*address))) { // skip all non-digit after '%' + while ((*address != '\0') && (!isdigit(*address))) { // skip all non-digit after '%' address++; } - _zone = atol(address) + 1; // increase by one by convention, so we can have zone '0' + _zone = atol(address) + 1; // increase by one by convention, so we can have zone '0' while (*address != '\0') { address++; } @@ -361,7 +361,7 @@ size_t IPAddress::printTo(Print &p, bool includeZone) const { if (_zone > 0 && includeZone) { n += p.print('%'); // look for the interface name - for (netif* intf = netif_list; intf != nullptr; intf = intf->next) { + for (netif *intf = netif_list; intf != nullptr; intf = intf->next) { if (_zone - 1 == intf->num) { n += p.print(intf->name[0]); n += p.print(intf->name[1]);