From dcd34d37287adb6aa03d32edd17fc8015b52feb8 Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 15 Dec 2012 01:33:31 -0500 Subject: Move DNS handling to a module --- src/misc.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/misc.cpp') diff --git a/src/misc.cpp b/src/misc.cpp index 417849df4..3f74888ee 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -18,10 +18,13 @@ #include "bots.h" #include "language.h" #include "regexpr.h" +#include "sockets.h" #include #include #include +#include +#include NumberList::NumberList(const Anope::string &list, bool descending) : is_valid(true), desc(descending) { @@ -652,3 +655,31 @@ Anope::string Anope::NormalizeBuffer(const Anope::string &buf) return newbuf; } +Anope::string Anope::Resolve(const Anope::string &host, int type) +{ + Anope::string result = host; + + addrinfo hints; + memset(&hints, 0, sizeof(hints)); + hints.ai_family = type; + + Log(LOG_DEBUG_2) << "Resolver: BlockingQuery: Looking up " << host; + + addrinfo *addrresult = NULL; + if (getaddrinfo(host.c_str(), NULL, &hints, &addrresult) == 0) + { + sockaddrs addr; + memcpy(&addr, addrresult->ai_addr, addrresult->ai_addrlen); + try + { + result = addr.addr(); + Log(LOG_DEBUG_2) << "Resolver: " << host << " -> " << result; + } + catch (const SocketException &) { } + + freeaddrinfo(addrresult); + } + + return result; +} + -- cgit