Skip to content

Commit e2b3a8e

Browse files
committed
Ethernet.hostByName added
1 parent f233296 commit e2b3a8e

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

src/Ethernet.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include <Arduino.h>
2121
#include "Ethernet.h"
22+
#include "Dns.h"
2223
#include "utility/Enc28J60Network.h"
2324

2425
extern "C"
@@ -184,6 +185,18 @@ IPAddress UIPEthernetClass::dnsIP(int n) {
184185
return (n == 0) ? _dnsServerAddress : IPAddress();
185186
}
186187

188+
int UIPEthernetClass::hostByName(const char* hostname, IPAddress& result)
189+
{
190+
// Look up the host first
191+
int ret = 0;
192+
#if UIP_UDP
193+
DNSClient dns;
194+
dns.begin(_dnsServerAddress);
195+
ret = dns.getHostByName(hostname, result);
196+
#endif
197+
return ret;
198+
}
199+
187200
void
188201
UIPEthernetClass::tick()
189202
{

src/Ethernet.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ class UIPEthernetClass
104104
void setDnsServerIP(const IPAddress dns_server) { _dnsServerAddress = dns_server; }
105105
void setDNS(IPAddress dns_server) { _dnsServerAddress = dns_server; }
106106

107+
int hostByName(const char* hostname, IPAddress& result);
108+
107109
private:
108110
static bool initialized;
109111
static memhandle in_packet;

src/EthernetClient.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ extern "C"
2525
}
2626
#include "Ethernet.h"
2727
#include "EthernetClient.h"
28-
#include "Dns.h"
2928

3029
#define UIP_TCP_PHYH_LEN UIP_LLH_LEN+UIP_IPTCPH_LEN
3130

@@ -87,11 +86,8 @@ UIPClient::connect(const char *host, uint16_t port)
8786
// Look up the host first
8887
int ret = 0;
8988
#if UIP_UDP
90-
DNSClient dns;
9189
IPAddress remote_addr;
92-
93-
dns.begin(UIPEthernetClass::_dnsServerAddress);
94-
ret = dns.getHostByName(host, remote_addr);
90+
ret = Ethernet.hostByName(host, remote_addr);
9591
if (ret == 1) {
9692
return connect(remote_addr, port);
9793
}

src/EthernetUdp.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
#include "Ethernet.h"
2121
#include "EthernetUdp.h"
22-
#include "Dns.h"
2322

2423
extern "C" {
2524
#include "utility/uip-conf.h"
@@ -149,11 +148,8 @@ UIPUDP::beginPacket(const char *host, uint16_t port)
149148
{
150149
// Look up the host first
151150
int ret = 0;
152-
DNSClient dns;
153151
IPAddress remote_addr;
154-
155-
dns.begin(Ethernet.dnsServerIP());
156-
ret = dns.getHostByName(host, remote_addr);
152+
ret = Ethernet.hostByName(host, remote_addr);
157153
if (ret == 1) {
158154
return beginPacket(remote_addr, port);
159155
} else {

0 commit comments

Comments
 (0)