Skip to content

Commit d7ddc09

Browse files
committed
change toCharArray() to toString()
1 parent 7835a96 commit d7ddc09

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

hardware/esp8266com/esp8266/cores/esp8266/IPAddress.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,10 @@ size_t IPAddress::printTo(Print& p) const {
6464
return n;
6565
}
6666

67-
char *IPAddress::toCharArray()
67+
String IPAddress::toString()
6868
{
69-
static char szRet[20];
70-
String str = String(_address.bytes[0]);
71-
str += ".";
72-
str += String(_address.bytes[1]);
73-
str += ".";
74-
str += String(_address.bytes[2]);
75-
str += ".";
76-
str += String(_address.bytes[3]);
77-
str.toCharArray(szRet, 20);
78-
return szRet;
69+
char szRet[16];
70+
sprintf(szRet,"%u.%u.%u.%u", _address.bytes[0], _address.bytes[1], _address.bytes[2], _address.bytes[3]);
71+
return String(szRet);
7972
}
8073

hardware/esp8266com/esp8266/cores/esp8266/IPAddress.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#define IPAddress_h
2222

2323
#include <stdint.h>
24+
#include <WString.h>
2425
#include <Printable.h>
2526

2627
// A class to make it easier to handle and pass around IP addresses
@@ -70,7 +71,7 @@ class IPAddress: public Printable {
7071
IPAddress& operator=(uint32_t address);
7172

7273
virtual size_t printTo(Print& p) const;
73-
char * toCharArray();
74+
String toString();
7475

7576
friend class EthernetClass;
7677
friend class UDP;

0 commit comments

Comments
 (0)