Skip to content

Commit a890aa4

Browse files
authored
Full support of IPv6 zones
by @s-hadinger
1 parent 20630d0 commit a890aa4

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

cores/esp32/IPAddress.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ bool IPAddress::fromString6(const char *address) {
207207
while ((*address != '\0') && (!isdigit(*address))) { // skip all non-digit after '%'
208208
address++;
209209
}
210-
_zone = atol(address);
210+
_zone = atol(address) + 1; // increase by one by convention, so we can have zone '0'
211211
while (*address != '\0') {
212212
address++;
213213
}
@@ -360,7 +360,15 @@ size_t IPAddress::printTo(Print &p, bool includeZone) const {
360360
// In the interim, we just output the index number
361361
if (_zone > 0 && includeZone) {
362362
n += p.print('%');
363-
n += p.print(_zone);
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);
364372
}
365373
return n;
366374
}

0 commit comments

Comments
 (0)