From 123bfed2ce68974321ca14dc4972fff309b12529 Mon Sep 17 00:00:00 2001 From: Daniel De Graaf Date: Sun, 25 Apr 2010 02:04:02 -0500 Subject: Change DNS binding to avoid BindSocket which could use the wrong address family --- src/dns.cpp | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) (limited to 'src/dns.cpp') diff --git a/src/dns.cpp b/src/dns.cpp index 5efa6e9b9..aec1cf45a 100644 --- a/src/dns.cpp +++ b/src/dns.cpp @@ -293,12 +293,9 @@ int DNS::PruneCache() void DNS::Rehash() { - int portpass = 0; - if (this->GetFd() > -1) { - if (ServerInstance && ServerInstance->SE) - ServerInstance->SE->DelFd(this); + ServerInstance->SE->DelFd(this); ServerInstance->SE->Shutdown(this, 2); ServerInstance->SE->Close(this); this->SetFd(-1); @@ -323,29 +320,23 @@ void DNS::Rehash() { ServerInstance->SE->SetReuse(s); ServerInstance->SE->NonBlocking(s); - /* Bind the port - port 0 INADDR_ANY */ - if (!ServerInstance->BindSocket(this->GetFd(), portpass, "", false)) + irc::sockets::sockaddrs bindto; + memset(&bindto, 0, sizeof(bindto)); + bindto.sa.sa_family = myserver.sa.sa_family; + if (ServerInstance->SE->Bind(this->GetFd(), bindto) < 0) { /* Failed to bind */ - ServerInstance->Logs->Log("RESOLVER",DEBUG,"Error binding dns socket"); + ServerInstance->Logs->Log("RESOLVER",SPARSE,"Error binding dns socket - hostnames will NOT resolve"); ServerInstance->SE->Shutdown(this, 2); ServerInstance->SE->Close(this); this->SetFd(-1); } - - if (this->GetFd() >= 0) + else if (!ServerInstance->SE->AddFd(this, FD_WANT_POLL_READ | FD_WANT_NO_WRITE)) { - /* Hook the descriptor into the socket engine */ - if (ServerInstance && ServerInstance->SE) - { - if (!ServerInstance->SE->AddFd(this, FD_WANT_POLL_READ | FD_WANT_NO_WRITE)) - { - ServerInstance->Logs->Log("RESOLVER",SPARSE,"Internal error starting DNS - hostnames will NOT resolve."); - ServerInstance->SE->Shutdown(this, 2); - ServerInstance->SE->Close(this); - this->SetFd(-1); - } - } + ServerInstance->Logs->Log("RESOLVER",SPARSE,"Internal error starting DNS - hostnames will NOT resolve."); + ServerInstance->SE->Shutdown(this, 2); + ServerInstance->SE->Close(this); + this->SetFd(-1); } } else -- cgit v1.3.1-10-gc9f91