From 09ca46116410fa7930e7d31859019d0133a91302 Mon Sep 17 00:00:00 2001 From: Channel59 Date: Wed, 10 Jul 2024 00:37:47 +0200 Subject: [PATCH] Add setHostname() method to Ethernet.cpp --- libraries/Ethernet/src/Ethernet.cpp | 11 +++++++++++ libraries/Ethernet/src/Ethernet.h | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/libraries/Ethernet/src/Ethernet.cpp b/libraries/Ethernet/src/Ethernet.cpp index 0f6450a7a..a2e74cb3f 100644 --- a/libraries/Ethernet/src/Ethernet.cpp +++ b/libraries/Ethernet/src/Ethernet.cpp @@ -24,6 +24,17 @@ int arduino::EthernetClass::_begin(uint8_t *mac, unsigned long timeout, unsigned return (linkStatus() == LinkON ? 1 : 0); } +int arduino::EthernetClass::setHostname(const char* hostname) { + eth_if->set_hostname(hostname); + return 1; +} + +int arduino::EthernetClass::begin(const char* hostname) { + eth_if->set_hostname(hostname); + auto ret = begin(); + return ret; +} + int arduino::EthernetClass::begin(uint8_t *mac, IPAddress ip) { IPAddress dns = ip; dns[3] = 1; diff --git a/libraries/Ethernet/src/Ethernet.h b/libraries/Ethernet/src/Ethernet.h index 8783d651c..cdaf80a1d 100644 --- a/libraries/Ethernet/src/Ethernet.h +++ b/libraries/Ethernet/src/Ethernet.h @@ -56,10 +56,14 @@ class EthernetClass : public MbedSocketClass { EthernetClass(EthernetInterface *_if) : eth_if(_if){}; + // When using DHCP the hostname provided will be used. + int setHostname(const char* hostname) + // Initialise the Ethernet shield to use the provided MAC address and // gain the rest of the configuration through DHCP. // Returns 0 if the DHCP configuration failed, and 1 if it succeeded int begin(uint8_t *mac = nullptr, unsigned long timeout = 60000, unsigned long responseTimeout = 4000); + int begin(const char* hostname); EthernetLinkStatus linkStatus(); EthernetHardwareStatus hardwareStatus();