Skip to content

Commit 549e75c

Browse files
author
Mo Chen
committed
Use host OS gethostbyname
The implementation of DNS lookup inside the ESP8266 firmware causes stack corruption when the name is 64 characters or longer. This change uses the mbed OS implementation of gethostbyname instead to work around this bug.
1 parent cac4d0d commit 549e75c

File tree

2 files changed

+1
-38
lines changed

2 files changed

+1
-38
lines changed

ESP8266Interface.cpp

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -85,29 +85,6 @@ int ESP8266Interface::connect()
8585
return NSAPI_ERROR_OK;
8686
}
8787

88-
nsapi_error_t ESP8266Interface::gethostbyname(const char *name, SocketAddress *address, nsapi_version_t version)
89-
{
90-
if (address->set_ip_address(name)) {
91-
if (version != NSAPI_UNSPEC && address->get_ip_version() != version) {
92-
return NSAPI_ERROR_DNS_FAILURE;
93-
}
94-
95-
return NSAPI_ERROR_OK;
96-
}
97-
98-
char *ipbuff = new char[NSAPI_IP_SIZE];
99-
int ret = 0;
100-
101-
if(!_esp.dns_lookup(name, ipbuff)) {
102-
ret = NSAPI_ERROR_DEVICE_ERROR;
103-
} else {
104-
address->set_ip_address(ipbuff);
105-
}
106-
107-
delete[] ipbuff;
108-
return ret;
109-
}
110-
11188
int ESP8266Interface::set_credentials(const char *ssid, const char *pass, nsapi_security_t security)
11289
{
11390
memset(ap_ssid, 0, sizeof(ap_ssid));

ESP8266Interface.h

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,7 @@ class ESP8266Interface : public NetworkStack, public WiFiInterface
5757
*/
5858
virtual int connect(const char *ssid, const char *pass, nsapi_security_t security = NSAPI_SECURITY_NONE,
5959
uint8_t channel = 0);
60-
61-
/** Translates a hostname to an IP address with specific version
62-
*
63-
* The hostname may be either a domain name or an IP address. If the
64-
* hostname is an IP address, no network transactions will be performed.
65-
*
66-
*
67-
* @param host Hostname to resolve
68-
* @param address Destination for the host SocketAddress
69-
* @param version IP version of address to resolve, NSAPI_UNSPEC indicates
70-
* version is chosen by the stack (defaults to NSAPI_UNSPEC)
71-
* @return 0 on success, negative error code on failure
72-
*/
73-
virtual nsapi_error_t gethostbyname(const char *name, SocketAddress *address, nsapi_version_t version = NSAPI_UNSPEC);
74-
60+
7561
/** Set the WiFi network credentials
7662
*
7763
* @param ssid Name of the network to connect to

0 commit comments

Comments
 (0)