Skip to content

Commit f9fe8b8

Browse files
committed
Allow creating IPAddress object from string and provide = overload
1 parent e26862e commit f9fe8b8

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

api/IPAddress.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ IPAddress::IPAddress(IPType ip_type, const uint8_t *address)
8989
}
9090
}
9191

92+
IPAddress::IPAddress(const char *address)
93+
{
94+
fromString(address);
95+
}
96+
9297
bool IPAddress::fromString(const char *address) {
9398
if (!fromString4(address)) {
9499
return fromString6(address);
@@ -225,6 +230,12 @@ IPAddress& IPAddress::operator=(const uint8_t *address)
225230
return *this;
226231
}
227232

233+
IPAddress& IPAddress::operator=(const char *address)
234+
{
235+
fromString(address);
236+
return *this;
237+
}
238+
228239
IPAddress& IPAddress::operator=(uint32_t address)
229240
{
230241
// IPv4 conversion

api/IPAddress.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ class IPAddress : public Printable {
6767
// Default IPv4
6868
IPAddress(const uint8_t *address);
6969
IPAddress(IPType ip_type, const uint8_t *address);
70+
// If IPv4 fails tries IPv6 see fromSting function
71+
IPAddress(const char *address);
7072

7173
bool fromString(const char *address);
7274
bool fromString(const String &address) { return fromString(address.c_str()); }
@@ -90,6 +92,8 @@ class IPAddress : public Printable {
9092
IPAddress& operator=(const uint8_t *address);
9193
// NOTE: IPv4 only; see implementation note
9294
IPAddress& operator=(uint32_t address);
95+
// If IPv4 fails tries IPv6 see fromSting function
96+
IPAddress& operator=(const char *address);
9397

9498
virtual size_t printTo(Print& p) const;
9599

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy