Skip to content

Commit 8a80bcc

Browse files
authored
IPv6 restore zone id
This PR restores the IPv6 zone-id in String representation of IPv6 address as well as parsing. This follows 20a28b5 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`
1 parent 87ad78d commit 8a80bcc

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

Diff for: cores/esp32/IPAddress.cpp

+20-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,13 @@ bool IPAddress::fromString6(const char *address) {
201201
colons++;
202202
acc = 0;
203203
} else if (c == '%') {
204-
_zone = netif_name_to_index(address);
204+
// netif_index_to_name crashes on latest esp-idf
205+
// _zone = netif_name_to_index(address);
206+
// in the interim, we parse the suffix as a zone number
207+
while ((*address != '\0') && (!isdigit(*address))) { // skip all non-digit after '%'
208+
address++;
209+
}
210+
_zone = atol(address) + 1; // increase by one by convention, so we can have zone '0'
205211
while (*address != '\0') {
206212
address++;
207213
}
@@ -351,6 +357,19 @@ size_t IPAddress::printTo(Print &p, bool includeZone) const {
351357
// netif_index_to_name(_zone, if_name);
352358
// n += p.print(if_name);
353359
// }
360+
// In the interim, we just output the index number
361+
if (_zone > 0 && includeZone) {
362+
n += p.print('%');
363+
// look for the interface name
364+
for (netif* intf = netif_list; intf != nullptr; intf = intf->next) {
365+
if (_zone - 1 == intf->num) {
366+
n += p.print(intf->name[0]);
367+
n += p.print(intf->name[1]);
368+
break;
369+
}
370+
}
371+
n += p.print(_zone - 1);
372+
}
354373
return n;
355374
}
356375

0 commit comments

Comments
 (0)