summaryrefslogtreecommitdiff
path: root/src/misc.cpp
diff options
context:
space:
mode:
authorSadie Powell <sadie@witchery.services>2023-08-06 13:36:27 +0100
committerSadie Powell <sadie@witchery.services>2023-08-06 13:36:27 +0100
commitadf820c08a0cdd404ce266da38c240390b43f0d0 (patch)
treebf17318745c9d16b739ce72e873c880b21dd2e55 /src/misc.cpp
parent377ba87d52ce131ffba3a78f877da7230c9a1330 (diff)
parent0715db71829786ec98c6922a9e32077ae396c87e (diff)
Merge branch 2.0 into 2.1.
Diffstat (limited to 'src/misc.cpp')
-rw-r--r--src/misc.cpp22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/misc.cpp b/src/misc.cpp
index 36e6d5b1f..0728daab1 100644
--- a/src/misc.cpp
+++ b/src/misc.cpp
@@ -705,7 +705,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));
@@ -716,15 +722,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)