summaryrefslogtreecommitdiffstats
path: root/src/OSSupport/HostnameLookup.cpp
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2015-01-18 12:35:02 +0100
committerMattes D <github@xoft.cz>2015-01-22 20:13:02 +0100
commitd4682463a1d503c349ac95e275b11d67d402268c (patch)
treede3167d2b81eb909a419c1355021353e00e71074 /src/OSSupport/HostnameLookup.cpp
parentcNetwork: Split the main cpp file into several files. (diff)
downloadcuberite-d4682463a1d503c349ac95e275b11d67d402268c.tar
cuberite-d4682463a1d503c349ac95e275b11d67d402268c.tar.gz
cuberite-d4682463a1d503c349ac95e275b11d67d402268c.tar.bz2
cuberite-d4682463a1d503c349ac95e275b11d67d402268c.tar.lz
cuberite-d4682463a1d503c349ac95e275b11d67d402268c.tar.xz
cuberite-d4682463a1d503c349ac95e275b11d67d402268c.tar.zst
cuberite-d4682463a1d503c349ac95e275b11d67d402268c.zip
Diffstat (limited to '')
-rw-r--r--src/OSSupport/HostnameLookup.cpp25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/OSSupport/HostnameLookup.cpp b/src/OSSupport/HostnameLookup.cpp
index 9e35f7163..860e0d88f 100644
--- a/src/OSSupport/HostnameLookup.cpp
+++ b/src/OSSupport/HostnameLookup.cpp
@@ -15,10 +15,22 @@
////////////////////////////////////////////////////////////////////////////////
// cHostnameLookup:
-cHostnameLookup::cHostnameLookup(const AString & a_Hostname, cNetwork::cResolveNameCallbacksPtr a_Callbacks):
- m_Callbacks(a_Callbacks),
- m_Hostname(a_Hostname)
+cHostnameLookup::cHostnameLookup(cNetwork::cResolveNameCallbacksPtr a_Callbacks):
+ m_Callbacks(a_Callbacks)
{
+}
+
+
+
+
+
+void cHostnameLookup::Lookup(const AString & a_Hostname)
+{
+ // Store the hostname for the callback:
+ m_Hostname = a_Hostname;
+
+ // Start the lookup:
+ // Note that we don't have to store the LibEvent lookup handle, LibEvent will free it on its own.
evutil_addrinfo hints;
memset(&hints, 0, sizeof(hints));
hints.ai_protocol = IPPROTO_TCP;
@@ -79,7 +91,7 @@ void cHostnameLookup::Callback(int a_ErrCode, evutil_addrinfo * a_Addr, void * a
// If only unsupported families were reported, call the Error handler:
if (!HasResolved)
{
- Self->m_Callbacks->OnError(1);
+ Self->m_Callbacks->OnError(DNS_ERR_NODATA);
}
else
{
@@ -101,7 +113,10 @@ bool cNetwork::HostnameToIP(
cNetwork::cResolveNameCallbacksPtr a_Callbacks
)
{
- return cNetworkSingleton::Get().HostnameToIP(a_Hostname, a_Callbacks);
+ auto Lookup = std::make_shared<cHostnameLookup>(a_Callbacks);
+ cNetworkSingleton::Get().AddHostnameLookup(Lookup);
+ Lookup->Lookup(a_Hostname);
+ return true;
}