Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SocketWrapper - use DNS of specific netif, not global #849

Merged
merged 1 commit into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions libraries/SocketWrapper/src/MbedClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ int arduino::MbedClient::connect(IPAddress ip, uint16_t port) {
int arduino::MbedClient::connect(const char *host, uint16_t port) {
SocketAddress socketAddress = SocketAddress();
socketAddress.set_port(port);
getNetwork()->gethostbyname(host, &socketAddress);
SocketHelpers::gethostbyname(getNetwork(), host, &socketAddress);
return connect(socketAddress);
}

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

SocketAddress socketAddress = SocketAddress();
socketAddress.set_port(port);
getNetwork()->gethostbyname(host, &socketAddress);
SocketHelpers::gethostbyname(getNetwork(), host, &socketAddress);
return connectSSL(socketAddress);
}

Expand Down
2 changes: 1 addition & 1 deletion libraries/SocketWrapper/src/MbedUdp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ int arduino::MbedUDP::beginPacket(IPAddress ip, uint16_t port) {
int arduino::MbedUDP::beginPacket(const char *host, uint16_t port) {
_host = SocketAddress(host, port);
txBuffer.clear();
getNetwork()->gethostbyname(host, &_host);
SocketHelpers::gethostbyname(getNetwork(), host, &_host);
//If IP is null and port is 0 the initialization failed
return (_host.get_ip_address() == nullptr && _host.get_port() == 0) ? 0 : 1;
}
Expand Down
7 changes: 6 additions & 1 deletion libraries/SocketWrapper/src/SocketHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ String arduino::MbedSocketClass::macAddress() {

int arduino::MbedSocketClass::hostByName(const char* aHostname, IPAddress& aResult) {
SocketAddress socketAddress = SocketAddress();
nsapi_error_t returnCode = getNetwork()->gethostbyname(aHostname, &socketAddress);
nsapi_error_t returnCode = gethostbyname(getNetwork(), aHostname, &socketAddress);
nsapi_addr_t address = socketAddress.get_addr();
aResult[0] = address.bytes[0];
aResult[1] = address.bytes[1];
Expand Down Expand Up @@ -120,6 +120,11 @@ SocketAddress arduino::MbedSocketClass::socketAddressFromIpAddress(arduino::IPAd
return SocketAddress(convertedIP, port);
}

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

// Download helper

Expand Down
1 change: 1 addition & 0 deletions libraries/SocketWrapper/src/SocketHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ class MbedSocketClass {

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

using SocketHelpers = MbedSocketClass;
Expand Down
Loading