]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Allocate request id's in sequence, which means we wont get a duplicate id until 65536...
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Wed, 2 Aug 2006 21:39:12 +0000 (21:39 +0000)
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Wed, 2 Aug 2006 21:39:12 +0000 (21:39 +0000)
Much safer than rand()

git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4659 e03df62e-2008-0410-955e-edbf42e46eb7

include/dns.h
src/dns.cpp

index 9d5906d3bcf8050e33ca852da55638b328efd132..834f401aefaa8099261e349e73bb339534d691d5 100644 (file)
@@ -164,6 +164,7 @@ class DNS : public Extensible
        requestlist requests;
        insp_inaddr myserver;
        static int MasterSocket;
+       int currid;
        Resolver* Classes[MAX_REQUEST_ID];
        int MakePayload(const char* name, const QueryType rr, const unsigned short rr_class, unsigned char* payload);
 
index 425c124c4b6e8146881d87eb88d4ddf8a9600a6f..652bd9838ce7b77a526453df1dba839f614fa446 100644 (file)
@@ -202,7 +202,9 @@ 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 = rand() % 65536;
+       id = this->currid++;
+       this->currid &= 0xFFFF;
+
        DNSRequest* req = new DNSRequest(this->myserver);
 
        header->id[0] = req->id[0] = id >> 8;
@@ -234,10 +236,9 @@ DNS::DNS()
        /* Clear the Resolver class table */
        memset(Classes,0,sizeof(Classes));
 
-       /* Seed random number generator, we use this to generate
-        * dns packet id's
+       /* Set the id of the next request to 0
         */
-       srand((unsigned int)time(NULL));
+       currid = 0;
 
        /* Clear the namesever address */
        memset(&myserver,0,sizeof(insp_inaddr));