Properly check for duplicate dns id's from the PRNG

git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4667 e03df62e-2008-0410-955e-edbf42e46eb7
This commit is contained in:
brain 2006-08-03 13:46:42 +00:00
parent 30911b2ae8
commit bcc3c8566c

View File

@ -202,7 +202,13 @@ int DNSRequest::SendRequests(const DNSHeader *header, const int length, QueryTyp
/* Add a query with a predefined header, and allocate an ID for it. */
DNSRequest* DNS::AddQuery(DNSHeader *header, int &id)
{
id = DNS::PRNG() & 0xFFFF;
id = this->PRNG() & 0xFFFF;
/* This id is already 'in flight', pick another.
* -- Thanks jilles
*/
while (requests.find(id) != requests.end())
id = this->PRNG() & 0xFFFF;
DNSRequest* req = new DNSRequest(this->myserver);
@ -215,8 +221,10 @@ DNSRequest* DNS::AddQuery(DNSHeader *header, int &id)
header->nscount = 0;
header->arcount = 0;
if (requests.find(id) == requests.end())
requests[id] = req;
/* At this point we already know the id doesnt exist,
* so there needs to be no second check for the ::end()
*/
requests[id] = req;
/* According to the C++ spec, new never returns NULL. */
return req;