From 2ce03a748040b798d714eb8f9ab6d7b616a843b1 Mon Sep 17 00:00:00 2001 From: Juraj Andrassy Date: Thu, 21 Dec 2023 07:25:57 +0100 Subject: [PATCH] Ethernet - complete API (setHostname, dnsIP(n), hostByName, ...) --- libraries/Ethernet/src/Ethernet.cpp | 29 ++++++++++++++++++++++++++++ libraries/Ethernet/src/EthernetC33.h | 10 ++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/libraries/Ethernet/src/Ethernet.cpp b/libraries/Ethernet/src/Ethernet.cpp index 3151cdcc..409740d1 100644 --- a/libraries/Ethernet/src/Ethernet.cpp +++ b/libraries/Ethernet/src/Ethernet.cpp @@ -64,6 +64,20 @@ int CEthernet::begin(IPAddress local_ip, IPAddress subnet, IPAddress gateway, IP return 1; } +/* -------------------------------------------------------------------------- */ +void CEthernet::setHostname(const char* hostname) { +/* -------------------------------------------------------------------------- */ + if (ni != nullptr) { + ni->setHostname(hostname); + } +} + +/* -------------------------------------------------------------------------- */ +void CEthernet::setDnsServerIP(IPAddress dns_server) { +/* -------------------------------------------------------------------------- */ + setDNS(dns_server); +} + /* -------------------------------------------------------------------------- */ void CEthernet::setDNS(IPAddress dns_server) { /* -------------------------------------------------------------------------- */ @@ -178,6 +192,11 @@ void CEthernet::MACAddress(uint8_t *mac) { CLwipIf::getInstance().getMacAddress(NI_ETHERNET, mac); } +uint8_t* CEthernet::macAddress(uint8_t *mac) { + CLwipIf::getInstance().getMacAddress(NI_ETHERNET, mac); + return mac; +} + IPAddress CEthernet::localIP() { if(ni != nullptr) { return IPAddress(ni->getIpAdd()); @@ -203,4 +222,14 @@ IPAddress CEthernet::dnsServerIP() { return CLwipIf::getInstance().getDns(); } +IPAddress CEthernet::dnsIP(int n) { + return CLwipIf::getInstance().getDns(n); +} + +/* -------------------------------------------------------------------------- */ +int CEthernet::hostByName(const char* hostname, IPAddress& result) { +/* -------------------------------------------------------------------------- */ + return CLwipIf::getInstance().getHostByName(hostname, result); +} + CEthernet Ethernet; diff --git a/libraries/Ethernet/src/EthernetC33.h b/libraries/Ethernet/src/EthernetC33.h index 23f8202d..1bdbe019 100644 --- a/libraries/Ethernet/src/EthernetC33.h +++ b/libraries/Ethernet/src/EthernetC33.h @@ -54,6 +54,8 @@ class CEthernet { int begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet, unsigned long timeout = 60000, unsigned long responseTimeout = 4000); EthernetHardwareStatus hardwareStatus(); + void setHostname(const char* hostname); + void setDnsServerIP(const IPAddress dns_server); // legacy Ethernet API void setDNS(IPAddress dns_server); int disconnect(void); @@ -62,11 +64,15 @@ class CEthernet { uint8_t *MACAddress(void); - void MACAddress(uint8_t *mac); + void MACAddress(uint8_t *mac); // legacy Ethernet API + uint8_t* macAddress(uint8_t* mac); IPAddress localIP(); IPAddress subnetMask(); IPAddress gatewayIP(); - IPAddress dnsServerIP(); + IPAddress dnsServerIP(); // legacy Ethernet API + IPAddress dnsIP(int n = 0); + + int hostByName(const char* hostname, IPAddress& result); friend class EthernetClient; friend class EthernetServer;