From aab7998583ca16590a32c7bdb80955a18b090700 Mon Sep 17 00:00:00 2001 From: danieldg Date: Tue, 9 Feb 2010 02:22:27 +0000 Subject: Add random number generation functions to InspIRCd class. Default implementation uses libc random(), which can be better than rand(). If gnutls is loaded, gcrypt will be used to provide random numbers. git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@12404 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/dns.cpp | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) (limited to 'src/dns.cpp') diff --git a/src/dns.cpp b/src/dns.cpp index dee83d3ac..8526d5be2 100644 --- a/src/dns.cpp +++ b/src/dns.cpp @@ -242,11 +242,9 @@ DNSRequest* DNS::AddQuery(DNSHeader *header, int &id, const char* original) return NULL; /* Create an id */ - id = this->PRNG() & DNS::MAX_REQUEST_ID; - - /* If this id is already 'in flight', pick another. */ - while (requests[id]) - id = this->PRNG() & DNS::MAX_REQUEST_ID; + do { + id = ServerInstance->GenRandomInt(DNS::MAX_REQUEST_ID); + } while (requests[id]); DNSRequest* req = new DNSRequest(this, id, original); @@ -1041,14 +1039,3 @@ void DNS::CleanResolvers(Module* module) } } } - -/** Generate pseudo-random number */ -unsigned long DNS::PRNG() -{ - unsigned long val = 0; - serverstats* s = ServerInstance->stats; - val = (rand() ^ this->currid++ ^ s->statsAccept) + ServerInstance->Time_ns(); - val += (s->statsCollisions ^ s->statsDnsGood) * s->statsDnsBad; - val += (s->statsConnects ^ (unsigned long)s->statsSent ^ (unsigned long)s->statsRecv); - return val; -} -- cgit v1.2.3