]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Update DNS engine to C++11 random
authorAmos Jeffries <squid3@treenet.co.nz>
Sun, 8 Feb 2015 06:07:18 +0000 (22:07 -0800)
committerAmos Jeffries <squid3@treenet.co.nz>
Sun, 8 Feb 2015 06:07:18 +0000 (22:07 -0800)
src/dns_internal.cc

index 44b4932126333d4030762e154b7683e841bc5bb6..a3305e8a89c14eb075b9ec217637b9a9a300c94d 100644 (file)
@@ -40,6 +40,7 @@
 #include <arpa/nameser.h>
 #endif
 #include <cerrno>
+#include <random>
 #if HAVE_RESOLV_H
 #include <resolv.h>
 #endif
@@ -1058,11 +1059,14 @@ idnsFindQuery(unsigned short id)
 }
 
 static unsigned short
-idnsQueryID(void)
+idnsQueryID()
 {
-    unsigned short id = squid_random() & 0xFFFF;
+    // NP: apparently ranlux are faster, but not quite as "proven"
+    static std::mt19937 mt(static_cast<uint32_t>(getCurrentTime() & 0xFFFFFFFF));
+    unsigned short id = mt() & 0xFFFF;
     unsigned short first_id = id;
 
+    // ensure temporal uniqueness by looking for an existing use
     while (idnsFindQuery(id)) {
         ++id;