9 #ifndef __libutilxx__sella__net__DNS_H__
10 #define __libutilxx__sella__net__DNS_H__
12 #include "../../common.h"
13 #include "DNSException.h"
14 #include "IPAddress.h"
15 #include "../util/Task.h"
16 #include "../variant/Variant.h"
18 #include <sys/socket.h>
42 typedef std::shared_ptr<DNS> shared;
46 static const uint64_t DefaultInterval = 5000;
48 static const int AnyProtocol = 0x00;
49 static const int IPv4Preferred = 0x01;
50 static const int IPv4Required = 0x03;
52 static const int IPv6Preferred = 0x04;
53 static const int IPv6Required = 0x12;
55 static const int A = 0x20;
56 static const int PTR = 0x21;
58 static const int MX = 0x22;
59 static const int TXT = 0x23;
60 static const int SRV = 0x24;
63 static const std::vector<std::string> empty;
66 DNS(
const std::vector<std::string> &nameservers = empty,
const std::vector<std::string> &searches = empty)
throw (DNSException);
67 DNS(
sella::util::ThreadPool *pool,
const std::vector<std::string> &nameservers = empty,
const std::vector<std::string> &searches = empty)
throw (DNSException);
68 virtual ~
DNS()
throw ();
72 std::vector<std::string> resolve(
const std::string &name,
int record = A,
int protocol = AnyProtocol)
throw (DNSException);
73 sella::variant::Variant resolve(
const std::vector<std::string> &names,
int record = A,
int protocol = AnyProtocol)
throw (DNSException);
74 std::vector<std::string> bulkResolve(
const std::vector<std::string> &names,
int record = A,
int protocol = AnyProtocol)
throw (DNSException);
77 static std::vector<std::string> sresolve(
const std::string &name,
int protocol = AnyProtocol)
throw (DNSException);
78 static std::vector<IPAddress> sresolve_ip(
const std::string &name,
int protocol = AnyProtocol)
throw (DNSException);
81 DNSCallback* resolve(
DNSCallback *callback,
const std::string &name,
int record = A,
int protocol = AnyProtocol)
throw (DNSException);
82 bool receive(uint64_t usec = 0, time_t now = 0)
throw ();
84 void setInterval(uint64_t usec)
throw ();
85 void setNoSearch(
bool on =
true)
throw ();
86 void setNoRecursion(
bool on =
true)
throw ();
87 void setAuthoritativeOnly(
bool on =
true)
throw ();
88 void setTimeout(
int seconds = 5)
throw ();
89 void setRetries(
int retries = 2)
throw ();
90 void setDots(
int ndots = 1)
throw ();
91 void setUDPSize(
int bytes = 4096)
throw ();
92 void setUDPPort(
short port = 53)
throw ();
94 int getActive()
throw ();
97 static const DNS::shared shared_ptr(
const std::vector<std::string> &nameservers = empty,
const std::vector<std::string> &searches = empty)
throw (DNSException);
98 static const DNS::shared shared_ptr(
sella::util::ThreadPool *pool,
const std::vector<std::string> &nameservers = empty,
const std::vector<std::string> &searches = empty)
throw (DNSException);
100 static const IPAddress convertArpa(
const std::string &qname)
throw (DNSException);
103 static void callback_a(
struct dns_ctx *context,
void *result,
void *argument);
104 static void callback_aaaa(
struct dns_ctx *context,
void *result,
void *argument);
105 static void callback_ptr(
struct dns_ctx *context, dns_rr_ptr *result,
void *argument);
109 sella::util::Task::shared task;
111 struct dns_ctx *context;
115 void init(
const std::vector<std::string> &nameservers,
const std::vector<std::string> &searches);