diff options
author | Daniel De Graaf <danieldg@inspircd.org> | 2010-04-25 02:04:02 -0500 |
---|---|---|
committer | Daniel De Graaf <danieldg@inspircd.org> | 2010-04-25 02:04:02 -0500 |
commit | 123bfed2ce68974321ca14dc4972fff309b12529 (patch) | |
tree | b25f9655b71639bbc3c147844f2c19f94db362d4 /src | |
parent | 296d7f50446b6aa4f2db385d514f410a647b25ca (diff) |
Change DNS binding to avoid BindSocket which could use the wrong address family
Diffstat (limited to 'src')
-rw-r--r-- | src/dns.cpp | 31 |
1 files changed, 11 insertions, 20 deletions
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 |