diff options
author | Sadie Powell <sadie@witchery.services> | 2023-04-28 00:28:16 +0100 |
---|---|---|
committer | Sadie Powell <sadie@witchery.services> | 2023-07-11 16:11:57 +0100 |
commit | 7f8a0c9d33afa26047f02a2032e4d101bfbfac50 (patch) | |
tree | 51ac353f1950a9a61f110f9d0f1008b1c9a0e856 /src | |
parent | cc23f6dc011fa5b548dd4a1416bd6dee107ba7b6 (diff) |
Allow Anope to look up multiple DNS results.
For fixing bug 1756.
Diffstat (limited to 'src')
-rw-r--r-- | src/misc.cpp | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/misc.cpp b/src/misc.cpp index 86d12c462..7e68686a2 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -727,7 +727,13 @@ Anope::string Anope::NormalizeBuffer(const Anope::string &buf) Anope::string Anope::Resolve(const Anope::string &host, int type) { - Anope::string result = host; + std::vector<Anope::string> results = Anope::ResolveMultiple(host, type); + return results.empty() ? host : results[0]; +} + +std::vector<Anope::string> Anope::ResolveMultiple(const Anope::string &host, int type) +{ + std::vector<Anope::string> results; addrinfo hints; memset(&hints, 0, sizeof(hints)); @@ -738,15 +744,19 @@ Anope::string Anope::Resolve(const Anope::string &host, int type) addrinfo *addrresult = NULL; if (getaddrinfo(host.c_str(), NULL, &hints, &addrresult) == 0) { - sockaddrs addr; - memcpy(static_cast<void*>(&addr), addrresult->ai_addr, addrresult->ai_addrlen); - result = addr.addr(); - Log(LOG_DEBUG_2) << "Resolver: " << host << " -> " << result; + for (addrinfo *thisresult = addrresult; thisresult; thisresult = thisresult->ai_next) + { + sockaddrs addr; + memcpy(static_cast<void*>(&addr), thisresult->ai_addr, thisresult->ai_addrlen); + + results.push_back(addr.addr()); + Log(LOG_DEBUG_2) << "Resolver: " << host << " -> " << addr.addr(); + } freeaddrinfo(addrresult); } - return result; + return results; } Anope::string Anope::Random(size_t len) |