/* Create an id */
unsigned int tries = 0;
+ int id;
do
{
- req->id = ServerInstance->GenRandomInt(DNS::MAX_REQUEST_ID);
+ id = ServerInstance->GenRandomInt(DNS::MAX_REQUEST_ID);
if (++tries == DNS::MAX_REQUEST_ID*5)
{
// If we couldn't find an empty slot this many times, do a sequential scan as a last
// resort. If an empty slot is found that way, go on, otherwise throw an exception
- req->id = 0;
- for (int i = 1; i < DNS::MAX_REQUEST_ID; i++)
+ id = -1;
+ for (unsigned int i = 0; i < DNS::MAX_REQUEST_ID; i++)
{
if (!this->requests[i])
{
- req->id = i;
+ id = i;
break;
}
}
- if (req->id == 0)
+ if (id == -1)
throw Exception("DNS: All ids are in use");
break;
}
}
- while (!req->id || this->requests[req->id]);
+ while (this->requests[id]);
+ req->id = id;
this->requests[req->id] = req;
Packet p;
}
}
- void HandleEvent(EventType et, int)
+ void OnEventHandlerError(int errcode) CXX11_OVERRIDE
{
- if (et == EVENT_ERROR)
- {
- ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "UDP socket got an error event");
- return;
- }
+ ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "UDP socket got an error event");
+ }
+ void OnEventHandlerRead() CXX11_OVERRIDE
+ {
unsigned char buffer[524];
irc::sockets::sockaddrs from;
socklen_t x = sizeof(from);
if (length < Packet::HEADER_LENGTH)
return;
+ if (myserver != from)
+ {
+ std::string server1 = from.str();
+ std::string server2 = myserver.str();
+ ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Got a result from the wrong server! Bad NAT or DNS forging attempt? '%s' != '%s'",
+ server1.c_str(), server2.c_str());
+ return;
+ }
+
Packet recv_packet;
try
return;
}
- if (myserver != from)
- {
- std::string server1 = from.str();
- std::string server2 = myserver.str();
- ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Got a result from the wrong server! Bad NAT or DNS forging attempt? '%s' != '%s'",
- server1.c_str(), server2.c_str());
- return;
- }
-
DNS::Request* request = this->requests[recv_packet.id];
if (request == NULL)
{