19 m_Callbacks(
std::move(a_Callbacks)),
20 m_Hostname(a_Hostname)
38 memset(&hints, 0,
sizeof(hints));
39 hints.ai_protocol = IPPROTO_TCP;
40 hints.ai_socktype = SOCK_STREAM;
41 hints.ai_family = AF_UNSPEC;
42 hints.ai_flags = AI_CANONNAME;
45 int ErrCode = getaddrinfo(
Lookup->m_Hostname.c_str(),
nullptr, &hints, &Result);
47 Lookup->Callback(ErrCode, Result);
65 bool HasResolved =
false;
66 addrinfo * OrigAddr = a_Addr;
67 for (;a_Addr !=
nullptr; a_Addr = a_Addr->ai_next)
70 switch (a_Addr->ai_family)
74 sockaddr_in * sin =
reinterpret_cast<sockaddr_in *
>(a_Addr->ai_addr);
81 evutil_inet_ntop(AF_INET, &(sin->sin_addr), IP,
sizeof(IP));
86 sockaddr_in6 * sin =
reinterpret_cast<sockaddr_in6 *
>(a_Addr->ai_addr);
93 evutil_inet_ntop(AF_INET6, &(sin->sin6_addr), IP,
sizeof(IP));
115 freeaddrinfo(OrigAddr);
AString ErrorString(int a_ErrorCode)
Returns the readable form of a getaddressinfo type error code.
std::shared_ptr< cHostnameLookup > cHostnameLookupPtr
cHostnameLookup(const AString &a_Hostname, cNetwork::cResolveNameCallbacksPtr a_Callbacks)
Creates the lookup object.
static void Lookup(const AString &a_Hostname, cNetwork::cResolveNameCallbacksPtr a_Callbacks)
Creates a lookup object and schedules the lookup.
AString m_Hostname
The hostname that was queried (needed for the callbacks).
cNetwork::cResolveNameCallbacksPtr m_Callbacks
The callbacks to call for resolved names / errors.
void Callback(int a_ErrCode, struct addrinfo *a_Addr)
static bool HostnameToIP(const AString &a_Hostname, cResolveNameCallbacksPtr a_Callbacks)
Queues a DNS query to resolve the specified hostname to IP address.
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.