diff options
author | Attila Molnar <attilamolnar@hush.com> | 2015-04-21 15:00:01 +0200 |
---|---|---|
committer | Attila Molnar <attilamolnar@hush.com> | 2015-04-21 15:00:01 +0200 |
commit | 8950aeda9a42ec795ce4edf87b40135047f55f6d (patch) | |
tree | 32ec6f36e1f9b55748351d4b57b64cfa68597e02 | |
parent | 987dee3fdea29dcfa0035747c43ee22886a707fb (diff) |
core_dns Allow usage of id 0
-rw-r--r-- | src/coremods/core_dns.cpp | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/coremods/core_dns.cpp b/src/coremods/core_dns.cpp index 61d524ada..f4559c08f 100644 --- a/src/coremods/core_dns.cpp +++ b/src/coremods/core_dns.cpp @@ -473,32 +473,34 @@ class MyManager : public Manager, public Timer, public EventHandler /* 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; |