From 9662a59d94397c03d50055c7c70125b539762b58 Mon Sep 17 00:00:00 2001 From: Virens Date: Mon, 25 Mar 2024 20:23:14 +0800 Subject: [PATCH 1/2] add ipv4 toString function --- cores/arduino/IPAddress.cpp | 7 +++++++ cores/arduino/IPAddress.h | 1 + 2 files changed, 8 insertions(+) diff --git a/cores/arduino/IPAddress.cpp b/cores/arduino/IPAddress.cpp index 68439d1a5a..693c62f4c0 100644 --- a/cores/arduino/IPAddress.cpp +++ b/cores/arduino/IPAddress.cpp @@ -107,3 +107,10 @@ 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; From f3e39e8095164a55bf24fe5272c4b33f3272380e Mon Sep 17 00:00:00 2001 From: Virens Date: Mon, 25 Mar 2024 20:41:23 +0800 Subject: [PATCH 2/2] Delete extra empty lines at the end --- cores/arduino/IPAddress.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/cores/arduino/IPAddress.cpp b/cores/arduino/IPAddress.cpp index 693c62f4c0..d0b82f3adb 100644 --- a/cores/arduino/IPAddress.cpp +++ b/cores/arduino/IPAddress.cpp @@ -113,4 +113,3 @@ String IPAddress::toString() const sprintf(szRet, "%u.%u.%u.%u", _address.bytes[0], _address.bytes[1], _address.bytes[2], _address.bytes[3]); return String(szRet); } -