Skip to content

Commit a54191c

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

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

Diff for: api/IPAddress.cpp

+11
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

Diff for: api/IPAddress.h

+4
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)