From 30911b2ae8c8d8bdf741fc642f49956b8c9b98c0 Mon Sep 17 00:00:00 2001 From: brain Date: Thu, 3 Aug 2006 13:28:12 +0000 Subject: Improve PRNG git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4666 e03df62e-2008-0410-955e-edbf42e46eb7 --- include/dns.h | 7 +++++++ src/dns.cpp | 16 +++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/include/dns.h b/include/dns.h index 7c128602f..41f42f46a 100644 --- a/include/dns.h +++ b/include/dns.h @@ -279,6 +279,13 @@ class DNS : public Extensible * Destructor */ ~DNS(); + + /** Portable random number generator, generates + * its random number from the ircd stats counters, + * effective user id, time of day and the rollover + * counter (currid) + */ + unsigned long PRNG(); }; #endif diff --git a/src/dns.cpp b/src/dns.cpp index d5c593e37..993da5381 100644 --- a/src/dns.cpp +++ b/src/dns.cpp @@ -202,9 +202,7 @@ 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) { - timeval n; - gettimeofday(&n,NULL); - id = (n.tv_usec ^ getpid() ^ geteuid() ^ (currid++)) & 0xFFFF; + id = DNS::PRNG() & 0xFFFF; DNSRequest* req = new DNSRequest(this->myserver); @@ -732,3 +730,15 @@ bool DNS::AddResolverClass(Resolver* r) } } +unsigned long DNS::PRNG() +{ + unsigned long val = 0; + timeval n; + serverstats* s = ServerInstance->stats; + gettimeofday(&n,NULL); + val = (n.tv_usec ^ getpid() ^ geteuid() ^ (this->currid++)) ^ s->statsAccept + n.tv_sec; + val = val + s->statsCollisions ^ s->statsDnsGood - s->statsDnsBad; + val += (s->statsConnects ^ (unsigned long)s->statsSent ^ (unsigned long)s->statsRecv) - s->BoundPortCount; + return val; +} + -- cgit v1.2.3