Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9821ad0

Browse files
pennamper1234
andauthored
Allow creating IPAddress object from string and provide = overload (#174)
* Allow creating IPAddress object from string and provide = overload Co-authored-by: per1234 <accounts@perglass.com>
1 parent e26862e commit 9821ad0

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 fromString 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 fromString function
96+
IPAddress& operator=(const char *address);
9397

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

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /