summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/anope.h7
-rw-r--r--src/misc.cpp22
2 files changed, 23 insertions, 6 deletions
diff --git a/include/anope.h b/include/anope.h
index f65acad48..ed894c4ce 100644
--- a/include/anope.h
+++ b/include/anope.h
@@ -548,6 +548,13 @@ namespace Anope
*/
extern Anope::string Resolve(const Anope::string &host, int type);
+ /** Does a blocking dns query and returns all IPs.
+ * @param host host to look up
+ * @param type inet addr type
+ * @return A list of all IPs that the host resolves to
+ */
+ extern std::vector<Anope::string> ResolveMultiple(const Anope::string &host, int type);
+
/** Generate a string of random letters and numbers
* @param len The length of the string returned
*/
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)