summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-08-02 20:34:23 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-08-02 20:34:23 +0000
commita4b78330738ac8fdc3d4ac0f0a5791082677eb6a (patch)
tree84b68dc3e1fcdc035e66bcfbe8a488fb0d658bf8
parentc0526f1dc2782a5333b6ffffa6c9f6fae6290f19 (diff)
Move more stuff into private members of class DNS
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4654 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--include/dns.h18
-rw-r--r--src/dns.cpp33
2 files changed, 29 insertions, 22 deletions
diff --git a/include/dns.h b/include/dns.h
index 5ef3f60e5..4b5d5df37 100644
--- a/include/dns.h
+++ b/include/dns.h
@@ -57,6 +57,13 @@ enum ResolverError
class DNSRequest;
class DNSHeader;
+class ResourceRecord;
+
+/* A set of requests keyed by request id */
+typedef std::map<int,DNSRequest*> requestlist;
+
+/* An iterator into a set of requests */
+typedef requestlist::iterator requestlist_iter;
/**
* The Resolver class is a high-level abstraction for resolving DNS entries.
@@ -144,17 +151,26 @@ class Resolver : public Extensible
class DNS : public Extensible
{
private:
+
+ requestlist requests;
insp_inaddr myserver;
static int MasterSocket;
Resolver* Classes[65536];
+ int MakePayload(const char * const name, const unsigned short rr, const unsigned short rr_class, unsigned char * const payload);
+
public:
+
+ static void FillResourceRecord(ResourceRecord* rr, const unsigned char *input);
+ static void FillHeader(DNSHeader *header, const unsigned char *input, const int length);
+ static void EmptyHeader(unsigned char *output, const DNSHeader *header, const int length);
static int GetMasterSocket();
+
int GetIP(const char* name);
int GetName(const insp_inaddr* ip);
DNSResult GetResult();
void MarshallReads(int fd);
bool AddResolverClass(Resolver* r);
- DNSRequest* DNSAddQuery(DNSHeader *header, int &id);
+ DNSRequest* AddQuery(DNSHeader *header, int &id);
DNS();
~DNS();
};
diff --git a/src/dns.cpp b/src/dns.cpp
index cf1f02a59..60318dcc3 100644
--- a/src/dns.cpp
+++ b/src/dns.cpp
@@ -135,15 +135,6 @@ class DNSRequest
int SendRequests(const DNSHeader *header, const int length, QueryType qt);
};
-/* A set of requests keyed by request id */
-typedef std::map<int,DNSRequest*> requestlist;
-
-/* An iterator into a set of requests */
-typedef requestlist::iterator requestlist_iter;
-
-/* Declare our map */
-requestlist requests;
-
/*
* Optimized by brain, these were using integer division and modulus.
* We can use logic shifts and logic AND to replace these even divisions
@@ -153,7 +144,7 @@ requestlist requests;
/* Fill a ResourceRecord class based on raw data input */
-inline void DNSFillResourceRecord(ResourceRecord* rr, const unsigned char *input)
+inline void DNS::FillResourceRecord(ResourceRecord* rr, const unsigned char *input)
{
rr->type = (QueryType)((input[0] << 8) + input[1]);
rr->rr_class = (input[2] << 8) + input[3];
@@ -162,7 +153,7 @@ inline void DNSFillResourceRecord(ResourceRecord* rr, const unsigned char *input
}
/* Fill a DNSHeader class based on raw data input of a given length */
-inline void DNSFillHeader(DNSHeader *header, const unsigned char *input, const int length)
+inline void DNS::FillHeader(DNSHeader *header, const unsigned char *input, const int length)
{
header->id[0] = input[0];
header->id[1] = input[1];
@@ -176,7 +167,7 @@ inline void DNSFillHeader(DNSHeader *header, const unsigned char *input, const i
}
/* Empty a DNSHeader class out into raw data, ready for transmission */
-inline void DNSEmptyHeader(unsigned char *output, const DNSHeader *header, const int length)
+inline void DNS::EmptyHeader(unsigned char *output, const DNSHeader *header, const int length)
{
output[0] = header->id[0];
output[1] = header->id[1];
@@ -202,7 +193,7 @@ int DNSRequest::SendRequests(const DNSHeader *header, const int length, QueryTyp
this->rr_class = 1;
this->type = qt;
- DNSEmptyHeader(payload,header,length);
+ DNS::EmptyHeader(payload,header,length);
memset(&addr,0,sizeof(addr));
#ifdef IPV6
@@ -224,7 +215,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::DNSAddQuery(DNSHeader *header, int &id)
+DNSRequest* DNS::AddQuery(DNSHeader *header, int &id)
{
id = rand() % 65536;
DNSRequest* req = new DNSRequest(this->myserver);
@@ -305,7 +296,7 @@ DNS::DNS()
}
}
-int DNSMakePayload(const char * const name, const unsigned short rr, const unsigned short rr_class, unsigned char * const payload)
+int DNS::MakePayload(const char * const name, const unsigned short rr, const unsigned short rr_class, unsigned char * const payload)
{
short payloadpos;
const char * tempchr, * tempchr2;
@@ -351,10 +342,10 @@ int DNS::GetIP(const char *name)
int length;
DNSRequest* req;
- if ((length = DNSMakePayload(name,DNS_QRY_A,1,(unsigned char*)&h.payload)) == -1)
+ if ((length = this->MakePayload(name,DNS_QRY_A,1,(unsigned char*)&h.payload)) == -1)
return -1;
- req = DNSAddQuery(&h, id);
+ req = this->AddQuery(&h, id);
if (req->SendRequests(&h,length,DNS_QRY_A) == -1)
return -1;
@@ -377,10 +368,10 @@ int DNS::GetName(const insp_inaddr *ip)
sprintf(query,"%d.%d.%d.%d.in-addr.arpa",c[3],c[2],c[1],c[0]);
- if ((length = DNSMakePayload(query,DNS_QRY_PTR,1,(unsigned char*)&h.payload)) == -1)
+ if ((length = this->MakePayload(query,DNS_QRY_PTR,1,(unsigned char*)&h.payload)) == -1)
return -1;
- req = DNSAddQuery(&h, id);
+ req = this->AddQuery(&h, id);
if (req->SendRequests(&h,length,DNS_QRY_PTR) == -1)
return -1;
@@ -408,7 +399,7 @@ DNSResult DNS::GetResult()
return std::make_pair(-1,"");
/* Put the read header info into a header class */
- DNSFillHeader(&header,buffer,length - 12);
+ DNS::FillHeader(&header,buffer,length - 12);
/* Get the id of this request.
* Its a 16 bit value stored in two char's,
@@ -536,7 +527,7 @@ DNSInfo DNSRequest::ResultIsReady(DNSHeader &header, int length)
if (length - i < 10)
return std::make_pair((unsigned char*)NULL,"Incorrectly sized DNS reply");
- DNSFillResourceRecord(&rr,&header.payload[i]);
+ DNS::FillResourceRecord(&rr,&header.payload[i]);
i += 10;
if (rr.type != this->type)
{