summaryrefslogtreecommitdiff
path: root/drivers/unix
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2021-06-01 18:41:41 +0200
committerGitHub <noreply@github.com>2021-06-01 18:41:41 +0200
commit9990f28d8414e27843eb0626fbf7f0277e6c9130 (patch)
tree762fd01fc385676ed8945006c4e5d1b5581a8069 /drivers/unix
parentc5f237eaf8e46e55699a3e95956daec65f5aa963 (diff)
parentdd8fa11ac182cc5b53746c9148067968d45c5588 (diff)
Merge pull request #49026 from sarchar/multiple-dns-resolves
Diffstat (limited to 'drivers/unix')
-rw-r--r--drivers/unix/ip_unix.cpp22
-rw-r--r--drivers/unix/ip_unix.h2
2 files changed, 17 insertions, 7 deletions
diff --git a/drivers/unix/ip_unix.cpp b/drivers/unix/ip_unix.cpp
index 053e3fd9d6..e8f8ae4717 100644
--- a/drivers/unix/ip_unix.cpp
+++ b/drivers/unix/ip_unix.cpp
@@ -89,7 +89,7 @@ static IPAddress _sockaddr2ip(struct sockaddr *p_addr) {
return ip;
};
-IPAddress IPUnix::_resolve_hostname(const String &p_hostname, Type p_type) {
+void IPUnix::_resolve_hostname(List<IPAddress> &r_addresses, const String &p_hostname, Type p_type) const {
struct addrinfo hints;
struct addrinfo *result = nullptr;
@@ -108,7 +108,7 @@ IPAddress IPUnix::_resolve_hostname(const String &p_hostname, Type p_type) {
int s = getaddrinfo(p_hostname.utf8().get_data(), nullptr, &hints, &result);
if (s != 0) {
ERR_PRINT("getaddrinfo failed! Cannot resolve hostname.");
- return IPAddress();
+ return;
};
if (result == nullptr || result->ai_addr == nullptr) {
@@ -116,14 +116,24 @@ IPAddress IPUnix::_resolve_hostname(const String &p_hostname, Type p_type) {
if (result) {
freeaddrinfo(result);
}
- return IPAddress();
+ return;
};
- IPAddress ip = _sockaddr2ip(result->ai_addr);
+ struct addrinfo *next = result;
- freeaddrinfo(result);
+ do {
+ if (next->ai_addr == NULL) {
+ next = next->ai_next;
+ continue;
+ }
+ IPAddress ip = _sockaddr2ip(next->ai_addr);
+ if (!r_addresses.find(ip)) {
+ r_addresses.push_back(ip);
+ }
+ next = next->ai_next;
+ } while (next);
- return ip;
+ freeaddrinfo(result);
}
#if defined(WINDOWS_ENABLED)
diff --git a/drivers/unix/ip_unix.h b/drivers/unix/ip_unix.h
index e6479be6e5..0d64648b39 100644
--- a/drivers/unix/ip_unix.h
+++ b/drivers/unix/ip_unix.h
@@ -38,7 +38,7 @@
class IPUnix : public IP {
GDCLASS(IPUnix, IP);
- virtual IPAddress _resolve_hostname(const String &p_hostname, IP::Type p_type) override;
+ virtual void _resolve_hostname(List<IPAddress> &r_addresses, const String &p_hostname, Type p_type = TYPE_ANY) const override;
static IP *_create_unix();