+class DNS : public Extensible
+{
+ private:
+
+ /**
+ * The maximum value of a dns request id,
+ * 16 bits wide, 0xFFFF.
+ */
+ static const int MAX_REQUEST_ID = 0xFFFF;
+
+ /**
+ * Requests that are currently 'in flight
+ */
+ requestlist requests;
+
+ /**
+ * Server address being used currently
+ */
+ insp_inaddr myserver;
+
+ /**
+ * File descriptor being used to perform queries
+ */
+ static int MasterSocket;
+
+ /**
+ * A counter used to form part of the pseudo-random id
+ */
+ int currid;
+
+ /**
+ * Currently active Resolver classes
+ */
+ Resolver* Classes[MAX_REQUEST_ID];
+
+ /**
+ * Build a dns packet payload
+ */
+ int MakePayload(const char* name, const QueryType rr, const unsigned short rr_class, unsigned char* payload);
+
+ public:
+
+ /**
+ * Fill an rr (resource record) with data from input
+ */
+ static void FillResourceRecord(ResourceRecord* rr, const unsigned char* input);
+ /**
+ * Fill a header with data from input limited by a length
+ */
+ static void FillHeader(DNSHeader *header, const unsigned char *input, const int length);
+ /**
+ * Empty out a header into a data stream ready for transmission "on the wire"
+ */
+ static void EmptyHeader(unsigned char *output, const DNSHeader *header, const int length);
+ /**
+ * Get the master socket fd, used internally
+ */
+ static int GetMasterSocket();
+
+ /**
+ * Start the lookup of an ip from a hostname
+ */
+ int GetIP(const char* name);
+
+ /**
+ * Start the lookup of a hostname from an ip
+ */
+ int GetName(const insp_inaddr* ip);
+
+ /**
+ * Fetch the result string (an ip or host)
+ * and/or an error message to go with it.
+ */
+ DNSResult GetResult();
+
+ /**
+ * Handle a SocketEngine read event
+ */
+ void MarshallReads(int fd);
+
+ /**
+ * Add a Resolver* to the list of active classes
+ */
+ bool AddResolverClass(Resolver* r);
+
+ /**
+ * Add a query to the list to be sent
+ */
+ DNSRequest* AddQuery(DNSHeader *header, int &id);
+
+ /**
+ * The constructor initialises the dns socket,
+ * and clears the request lists.
+ */
+ DNS();
+
+ /**
+ * 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();
+};