]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/resolver.hh
Initial revision
[thirdparty/pdns.git] / pdns / resolver.hh
1 /*
2 PowerDNS Versatile Database Driven Nameserver
3 Copyright (C) 2002 PowerDNS.COM BV
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20 #include <string>
21 #include <vector>
22 #include <sys/types.h>
23
24 #ifndef WIN32
25
26 # include <arpa/nameser.h>
27 # include <resolv.h>
28 # include <netdb.h>
29 # include <unistd.h>
30 # include <sys/time.h>
31 # include <sys/uio.h>
32 # include <fcntl.h>
33 # include <sys/socket.h>
34 # include <netinet/in.h>
35 # include <arpa/inet.h>
36 # undef res_mkquery
37 #endif // WIN32
38
39 #include "ahuexception.hh"
40 #include "dns.hh"
41 using namespace std;
42
43 class ResolverException : public AhuException
44 {
45 public:
46 ResolverException(const string &reason) : AhuException(reason){}
47 };
48
49 //! Resolver class
50 class Resolver
51 {
52 public:
53 Resolver();
54 ~Resolver();
55 string i;
56
57 typedef vector<DNSResourceRecord> res_t;
58 void makeSocket(int type);
59 void makeUDPSocket();
60 void makeTCPSocket(const string &ip, u_int16_t port=53);
61 int notify(int sock, const string &domain, const string &ip, u_int16_t id);
62 int resolve(const string &ip, const char *domain, int type);
63 char* sendReceive(const string &ip, u_int16_t remotePort, const char *packet, int length, unsigned int *replylen);
64 int getSoaSerial(const string &, const string &, u_int32_t *);
65 int axfrChunk(Resolver::res_t &res);
66 vector<DNSResourceRecord> result();
67
68 void setRemote(const string &remote);
69 int axfr(const string &ip, const char *domain);
70
71 private:
72 void timeoutReadn(char *buffer, int bytes);
73 int d_sock;
74 unsigned char *d_buf;
75 int getLength();
76 int d_len;
77 int d_soacount;
78 string d_domain;
79 int d_type;
80 int d_timeout;
81 u_int32_t d_ip;
82 bool d_inaxfr;
83 };
84