From 79579d740da03f2cccb1bf89f72e8c8e2f85bc7a Mon Sep 17 00:00:00 2001 From: VirensCn <595170292@qq.com> Date: Tue, 26 Mar 2024 15:52:12 +0800 Subject: [PATCH] feat: add "toString" function to IPAddress (#2306) Signed-off-by: Virens --- cores/arduino/IPAddress.cpp | 6 ++++++ cores/arduino/IPAddress.h | 1 + 2 files changed, 7 insertions(+) diff --git a/cores/arduino/IPAddress.cpp b/cores/arduino/IPAddress.cpp index 68439d1a5a..d0b82f3adb 100644 --- a/cores/arduino/IPAddress.cpp +++ b/cores/arduino/IPAddress.cpp @@ -107,3 +107,9 @@ size_t IPAddress::printTo(Print &p) const return n; } +String IPAddress::toString() const +{ + char szRet[16]; + sprintf(szRet, "%u.%u.%u.%u", _address.bytes[0], _address.bytes[1], _address.bytes[2], _address.bytes[3]); + return String(szRet); +} diff --git a/cores/arduino/IPAddress.h b/cores/arduino/IPAddress.h index c73f011982..b8b1092d3b 100644 --- a/cores/arduino/IPAddress.h +++ b/cores/arduino/IPAddress.h @@ -82,6 +82,7 @@ class IPAddress : public Printable { IPAddress &operator=(uint32_t address); virtual size_t printTo(Print &p) const; + String toString() const; friend class EthernetClass; friend class UDP;