8 #include <event2/util.h>
20 m_Callbacks(
std::move(a_Callbacks)),
38 int salen =
sizeof(sa);
39 memset(&sa, 0,
sizeof(sa));
41 int ErrCode = evutil_parse_sockaddr_port(
Lookup->m_IP.c_str(),
reinterpret_cast<sockaddr *
>(&sa), &salen);
45 LOGD(
"Failed to parse IP address \"%s\".",
Lookup->m_IP.c_str());
46 Lookup->Callback(ErrCode,
nullptr);
50 char Hostname[NI_MAXHOST];
51 char ServInfo[NI_MAXSERV];
53 ErrCode = getnameinfo(
54 reinterpret_cast<sockaddr *
>(&sa),
55 static_cast<socklen_t
>(salen),
56 Hostname,
sizeof(Hostname),
57 ServInfo,
sizeof(ServInfo),
60 Lookup->Callback(ErrCode, Hostname);
71 if ((a_Result != 0) || (a_Address ==
nullptr))
AString ErrorString(int a_ErrorCode)
Returns the readable form of a getaddressinfo type error code.
std::shared_ptr< cIPLookup > cIPLookupPtr
cIPLookup(const AString &a_IP, cNetwork::cResolveNameCallbacksPtr a_Callbacks)
Creates the lookup object.
void Callback(int a_Result, const char *a_Address)
Callback that is called by LibEvent when there's an event for the request.
AString m_IP
The IP that was queried (needed for the callbacks).
cNetwork::cResolveNameCallbacksPtr m_Callbacks
The callbacks to call for resolved names / errors.
static void Lookup(const AString &a_IP, cNetwork::cResolveNameCallbacksPtr a_Callbacks)
Creates a lookup object and schedules the lookup.
static bool IPToHostName(const AString &a_IP, cResolveNameCallbacksPtr a_Callbacks)
Queues a DNS query to resolve the specified IP address to a hostname.
std::shared_ptr< cResolveNameCallbacks > cResolveNameCallbacksPtr
void ScheduleLookup(std::function< void()> a_Lookup)
Schedule a lookup task for execution.
static cNetworkSingleton & Get(void)
Returns the singleton instance of this class.
cNetworkLookup & GetLookupThread()
Returns the thread used to perform hostname and IP lookups.