From a4cf7abc1d34e4318d5655b1d1333d933db8cdea Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Wed, 17 Jul 2024 05:55:24 +0200 Subject: [PATCH] Quickfix: bypass faulty DNS by using default values for localhost. --- src/arch/posix/mbed_tcp.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/arch/posix/mbed_tcp.cpp b/src/arch/posix/mbed_tcp.cpp index 6446a4c..db232f9 100644 --- a/src/arch/posix/mbed_tcp.cpp +++ b/src/arch/posix/mbed_tcp.cpp @@ -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) @@ -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;