Skip to content

Commit

Permalink
Quickfix: bypass faulty DNS by using default values for localhost.
Browse files Browse the repository at this point in the history
  • Loading branch information
aentinger committed Jul 17, 2024
1 parent e203e51 commit a4cf7ab
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/arch/posix/mbed_tcp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,35 @@ int mbed_getnameinfo(struct sockaddr* fd, size_t sa_sz, char* name, size_t host_

int mbed_addrinfo(const char* hostname, const char* portstr, struct addrinfo* hints, struct addrinfo** info)
{
static struct sockaddr ai_addr;
static struct addrinfo res;
bool is_localhost = false;

if (hostname == NULL)
{
static const char * localhost = "localhost";
hostname = localhost;
is_localhost = true;
}

SocketAddress mbed_hints(hostname, atoi(portstr));
mbed_hints.set_ip_address(Ethernet.localIP().toString().c_str());
SocketAddress * mbed_res;

/* Bypass faulty DNS lookup on localhost. */
if (is_localhost)
{
ai_addr.ai = mbed_hints;

memcpy(&res, hints, sizeof(struct addrinfo));

res.ai_addr = &ai_addr;
res.ai_next = NULL;
info[0] = &res;

return UA_STATUSCODE_GOOD;
}

/* rc either holds the number of results uncovered or a negative error code. */
auto rc = NetworkInterface::get_default_instance()->getaddrinfo(hostname, &mbed_hints, &mbed_res);
if (rc < 0)
Expand All @@ -112,10 +131,8 @@ int mbed_addrinfo(const char* hostname, const char* portstr, struct addrinfo* hi
}

/* Note: we currently support only a single address result. */
static struct sockaddr ai_addr;
ai_addr.ai = mbed_res[0];

static struct addrinfo res;
memcpy(&res, hints, sizeof(struct addrinfo));

res.ai_addr = &ai_addr;
Expand Down

0 comments on commit a4cf7ab

Please sign in to comment.