Skip to content

Commit 9012f64

Browse files
committed
Add option to print the zone at the end of IPv6
@TD-er
1 parent 726496c commit 9012f64

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

cores/esp32/IPAddress.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ IPAddress::IPAddress(uint32_t address)
6767
{
6868
// IPv4 only
6969
_type = IPv4;
70+
_zone = IP6_NO_ZONE;
7071
memset(_address.bytes, 0, sizeof(_address.bytes));
7172
_address.dword[IPADDRESS_V4_DWORD_INDEX] = address;
7273

@@ -104,10 +105,10 @@ IPAddress::IPAddress(const IPAddress& address)
104105
*this = address;
105106
}
106107

107-
String IPAddress::toString() const
108+
String IPAddress::toString(bool includeZone) const
108109
{
109110
StreamString s;
110-
printTo(s);
111+
printTo(s, includeZone);
111112
return String(s);
112113
}
113114

@@ -303,6 +304,11 @@ uint8_t& IPAddress::operator[](int index) {
303304
}
304305

305306
size_t IPAddress::printTo(Print& p) const
307+
{
308+
return printTo(p, false);
309+
}
310+
311+
size_t IPAddress::printTo(Print& p, bool includeZone) const
306312
{
307313
size_t n = 0;
308314

@@ -355,12 +361,12 @@ size_t IPAddress::printTo(Print& p) const
355361
}
356362
}
357363
// add a zone if zone-id is non-zero
358-
// if(_zone > 0){
359-
// n += p.print('%');
360-
// char if_name[NETIF_NAMESIZE];
361-
// netif_index_to_name(_zone, if_name);
362-
// n += p.print(if_name);
363-
// }
364+
if(_zone > 0 && includeZone){
365+
n += p.print('%');
366+
char if_name[NETIF_NAMESIZE];
367+
netif_index_to_name(_zone, if_name);
368+
n += p.print(if_name);
369+
}
364370
return n;
365371
}
366372

cores/esp32/IPAddress.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ class IPAddress : public Printable {
9393
IPAddress& operator=(const IPAddress& address);
9494

9595
virtual size_t printTo(Print& p) const;
96-
String toString() const;
96+
size_t printTo(Print& p, bool includeZone) const;
97+
String toString(bool includeZone = false) const;
9798

9899
IPType type() const { return _type; }
99100

libraries/Ethernet/src/ETH.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,7 @@ void ETHClass::printInfo(Print & out){
10551055
for (int i = 0; i < v6addrs; ++i){
10561056
out.print(" ");
10571057
out.print("inet6 ");
1058-
IPAddress(IPv6, (const uint8_t *)if_ip6[i].addr, if_ip6[i].zone).printTo(out);
1058+
IPAddress(IPv6, (const uint8_t *)if_ip6[i].addr, if_ip6[i].zone).printTo(out, true);
10591059
out.print(" type ");
10601060
out.print(types[esp_netif_ip6_get_addr_type(&if_ip6[i])]);
10611061
out.println();

0 commit comments

Comments
 (0)