Skip to content

Commit 09ca461

Browse files
committed
Add setHostname() method to Ethernet.cpp
1 parent 85f6572 commit 09ca461

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

libraries/Ethernet/src/Ethernet.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ int arduino::EthernetClass::_begin(uint8_t *mac, unsigned long timeout, unsigned
2424
return (linkStatus() == LinkON ? 1 : 0);
2525
}
2626

27+
int arduino::EthernetClass::setHostname(const char* hostname) {
28+
eth_if->set_hostname(hostname);
29+
return 1;
30+
}
31+
32+
int arduino::EthernetClass::begin(const char* hostname) {
33+
eth_if->set_hostname(hostname);
34+
auto ret = begin();
35+
return ret;
36+
}
37+
2738
int arduino::EthernetClass::begin(uint8_t *mac, IPAddress ip) {
2839
IPAddress dns = ip;
2940
dns[3] = 1;

libraries/Ethernet/src/Ethernet.h

+4
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,14 @@ class EthernetClass : public MbedSocketClass {
5656
EthernetClass(EthernetInterface *_if)
5757
: eth_if(_if){};
5858

59+
// When using DHCP the hostname provided will be used.
60+
int setHostname(const char* hostname)
61+
5962
// Initialise the Ethernet shield to use the provided MAC address and
6063
// gain the rest of the configuration through DHCP.
6164
// Returns 0 if the DHCP configuration failed, and 1 if it succeeded
6265
int begin(uint8_t *mac = nullptr, unsigned long timeout = 60000, unsigned long responseTimeout = 4000);
66+
int begin(const char* hostname);
6367
EthernetLinkStatus linkStatus();
6468
EthernetHardwareStatus hardwareStatus();
6569

0 commit comments

Comments
 (0)