completed partial IPv6 compatibility in DNS; does retrieve and Cache IPv6 IPs
[pingcheck] / src / dns / ippseudoresolver.h
CommitLineData
36ad976b
CH
1/*
2 The software in this package is distributed under the GNU General
3 Public License version 2 (with a special exception described below).
4
5 A copy of GNU General Public License (GPL) is included in this distribution,
6 in the file COPYING.GPL.
7
8 As a special exception, if other files instantiate templates or use macros
9 or inline functions from this file, or you compile this file and link it
10 with other works to produce a work based on this file, this file
11 does not by itself cause the resulting work to be covered
12 by the GNU General Public License.
13
14 However the source code for this file must still be made available
15 in accordance with section (3) of the GNU General Public License.
16
17 This exception does not invalidate any other reasons why a work based
18 on this file might be covered by the GNU General Public License.
19
20 Christian Herdtweck, Intra2net AG 2015
21 */
22
23#ifndef IP_PSEUDO_RESOLVER_H
24#define IP_PSEUDO_RESOLVER_H
25
4e7b6ff9
CH
26#include <boost/asio/ip/address.hpp>
27#include "dns/hostaddress.h"
c5b4902d
CH
28#include "dns/resolverbase.h"
29#include "dns/dnsmaster.h"
36ad976b 30
96779587
CH
31namespace Config
32{
33 uint32_t DefaultTtl = 60*60*24*356; // 1 year in seconds (approx)
34}
35
36ad976b
CH
36/** @brief Degenerate case of a resolver: hostname is already an IP
37 *
38 * created by DnsMaster if given an IP address as hostname
39 *
40 * Will do nothing, just remember that IP and return it for every call to
41 * get_next_ip
42 *
43 * Since this is so boring, I did not create an own .cpp for it
44 */
45class IpPseudoResolver : public ResolverBase
46{
47// constructor accessible from friend DnsMaster
48public:
96779587 49 friend ResolverItem& DnsMaster::get_resolver_for(
923626c0
CH
50 const std::string &hostname,
51 const DnsIpProtocol &protocol);
36ad976b 52private:
4e7b6ff9
CH
53 IpPseudoResolver(const IoServiceItem io_serv,
54 const std::string &ip_string,
8f00b3df 55 const DnsIpProtocol &protocol,
96779587 56 const DnsCacheItem &cache )
8f00b3df 57 : ResolverBase( io_serv, ip_string, protocol, cache )
4e7b6ff9
CH
58 , IpAddress( boost::asio::ip::address::from_string(ip_string),
59 Config::DefaultTtl )
96779587 60 {}
36ad976b
CH
61
62private:
4e7b6ff9 63 HostAddress IpAddress;
36ad976b 64
4e7b6ff9 65// only real public function
36ad976b 66public:
26b0f687 67 HostAddress get_next_ip(const bool check_up_to_date=true)
72be9e7d
CH
68 { return IpAddress; }
69 bool have_up_to_date_ip() { return true; }
fd62d09f
CH
70 int get_resolved_ip_count(const bool check_up_to_date=true)
71 { return 1; }
72be9e7d
CH
72 bool is_resolving() const { return false; }
73 bool is_waiting_to_resolve() const { return false; }
e18c1337 74 void cancel_resolve() {}
4e7b6ff9
CH
75
76// implementation of ResolverBase::async_resolve
77protected:
cd71d095 78 void do_resolve(const int recursion_count)
923626c0 79 { ResolverBase::schedule_callbacks(true, 0); }
36ad976b
CH
80};
81#endif
82