Skip to content

Commit 2ce03a7

Browse files
committed
Ethernet - complete API (setHostname, dnsIP(n), hostByName, ...)
1 parent 6ee152f commit 2ce03a7

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

libraries/Ethernet/src/Ethernet.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,20 @@ int CEthernet::begin(IPAddress local_ip, IPAddress subnet, IPAddress gateway, IP
6464
return 1;
6565
}
6666

67+
/* -------------------------------------------------------------------------- */
68+
void CEthernet::setHostname(const char* hostname) {
69+
/* -------------------------------------------------------------------------- */
70+
if (ni != nullptr) {
71+
ni->setHostname(hostname);
72+
}
73+
}
74+
75+
/* -------------------------------------------------------------------------- */
76+
void CEthernet::setDnsServerIP(IPAddress dns_server) {
77+
/* -------------------------------------------------------------------------- */
78+
setDNS(dns_server);
79+
}
80+
6781
/* -------------------------------------------------------------------------- */
6882
void CEthernet::setDNS(IPAddress dns_server) {
6983
/* -------------------------------------------------------------------------- */
@@ -178,6 +192,11 @@ void CEthernet::MACAddress(uint8_t *mac) {
178192
CLwipIf::getInstance().getMacAddress(NI_ETHERNET, mac);
179193
}
180194

195+
uint8_t* CEthernet::macAddress(uint8_t *mac) {
196+
CLwipIf::getInstance().getMacAddress(NI_ETHERNET, mac);
197+
return mac;
198+
}
199+
181200
IPAddress CEthernet::localIP() {
182201
if(ni != nullptr) {
183202
return IPAddress(ni->getIpAdd());
@@ -203,4 +222,14 @@ IPAddress CEthernet::dnsServerIP() {
203222
return CLwipIf::getInstance().getDns();
204223
}
205224

225+
IPAddress CEthernet::dnsIP(int n) {
226+
return CLwipIf::getInstance().getDns(n);
227+
}
228+
229+
/* -------------------------------------------------------------------------- */
230+
int CEthernet::hostByName(const char* hostname, IPAddress& result) {
231+
/* -------------------------------------------------------------------------- */
232+
return CLwipIf::getInstance().getHostByName(hostname, result);
233+
}
234+
206235
CEthernet Ethernet;

libraries/Ethernet/src/EthernetC33.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ class CEthernet {
5454
int begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet, unsigned long timeout = 60000, unsigned long responseTimeout = 4000);
5555
EthernetHardwareStatus hardwareStatus();
5656

57+
void setHostname(const char* hostname);
58+
void setDnsServerIP(const IPAddress dns_server); // legacy Ethernet API
5759
void setDNS(IPAddress dns_server);
5860

5961
int disconnect(void);
@@ -62,11 +64,15 @@ class CEthernet {
6264

6365

6466
uint8_t *MACAddress(void);
65-
void MACAddress(uint8_t *mac);
67+
void MACAddress(uint8_t *mac); // legacy Ethernet API
68+
uint8_t* macAddress(uint8_t* mac);
6669
IPAddress localIP();
6770
IPAddress subnetMask();
6871
IPAddress gatewayIP();
69-
IPAddress dnsServerIP();
72+
IPAddress dnsServerIP(); // legacy Ethernet API
73+
IPAddress dnsIP(int n = 0);
74+
75+
int hostByName(const char* hostname, IPAddress& result);
7076

7177
friend class EthernetClient;
7278
friend class EthernetServer;

0 commit comments

Comments
 (0)