Skip to content

Commit ffe6b03

Browse files
authored
Merge pull request #849 from JAndrassy/lwip_dns_fix
SocketWrapper - use DNS of specific netif, not global
2 parents 54326dd + 1a96ac7 commit ffe6b03

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

libraries/SocketWrapper/src/MbedClient.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ int arduino::MbedClient::connect(IPAddress ip, uint16_t port) {
129129
int arduino::MbedClient::connect(const char *host, uint16_t port) {
130130
SocketAddress socketAddress = SocketAddress();
131131
socketAddress.set_port(port);
132-
getNetwork()->gethostbyname(host, &socketAddress);
132+
SocketHelpers::gethostbyname(getNetwork(), host, &socketAddress);
133133
return connect(socketAddress);
134134
}
135135

@@ -199,7 +199,7 @@ int arduino::MbedClient::connectSSL(const char *host, uint16_t port, bool disabl
199199

200200
SocketAddress socketAddress = SocketAddress();
201201
socketAddress.set_port(port);
202-
getNetwork()->gethostbyname(host, &socketAddress);
202+
SocketHelpers::gethostbyname(getNetwork(), host, &socketAddress);
203203
return connectSSL(socketAddress);
204204
}
205205

libraries/SocketWrapper/src/MbedUdp.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ int arduino::MbedUDP::beginPacket(IPAddress ip, uint16_t port) {
6363
int arduino::MbedUDP::beginPacket(const char *host, uint16_t port) {
6464
_host = SocketAddress(host, port);
6565
txBuffer.clear();
66-
getNetwork()->gethostbyname(host, &_host);
66+
SocketHelpers::gethostbyname(getNetwork(), host, &_host);
6767
//If IP is null and port is 0 the initialization failed
6868
return (_host.get_ip_address() == nullptr && _host.get_port() == 0) ? 0 : 1;
6969
}

libraries/SocketWrapper/src/SocketHelpers.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ String arduino::MbedSocketClass::macAddress() {
1717

1818
int arduino::MbedSocketClass::hostByName(const char* aHostname, IPAddress& aResult) {
1919
SocketAddress socketAddress = SocketAddress();
20-
nsapi_error_t returnCode = getNetwork()->gethostbyname(aHostname, &socketAddress);
20+
nsapi_error_t returnCode = gethostbyname(getNetwork(), aHostname, &socketAddress);
2121
nsapi_addr_t address = socketAddress.get_addr();
2222
aResult[0] = address.bytes[0];
2323
aResult[1] = address.bytes[1];
@@ -120,6 +120,11 @@ SocketAddress arduino::MbedSocketClass::socketAddressFromIpAddress(arduino::IPAd
120120
return SocketAddress(convertedIP, port);
121121
}
122122

123+
nsapi_error_t arduino::MbedSocketClass::gethostbyname(NetworkInterface* interface, const char* aHostname, SocketAddress* socketAddress) {
124+
char ifname[5] {};
125+
interface->get_interface_name(ifname);
126+
return interface->gethostbyname(aHostname, socketAddress, NSAPI_UNSPEC, ifname);
127+
}
123128

124129
// Download helper
125130

libraries/SocketWrapper/src/SocketHelpers.h

+1
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ class MbedSocketClass {
154154

155155
static arduino::IPAddress ipAddressFromSocketAddress(SocketAddress socketAddress);
156156
static SocketAddress socketAddressFromIpAddress(arduino::IPAddress ip, uint16_t port);
157+
static nsapi_error_t gethostbyname(NetworkInterface* interface, const char* aHostname, SocketAddress* socketAddress);
157158
};
158159

159160
using SocketHelpers = MbedSocketClass;

0 commit comments

Comments
 (0)