fixed 2 bugs and made clearer that Long-term timer in DnsResolver is not affected...
[pingcheck] / src / dns / hostaddress.cpp
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 #include "dns/hostaddress.h"
21
22 #include <boost/version.hpp>
23
24 #include "boost_assert_handler.h"
25
26 using namespace std;
27 using boost::asio::ip::address;
28
29 //-----------------------------------------------------------------------------
30 // HostAddress
31 //-----------------------------------------------------------------------------
32
33 HostAddress::HostAddress() :
34     Ip(),
35     Ttl( 0 )
36 {
37 }
38
39 HostAddress::HostAddress(
40         const address &ip,
41         uint32_t ttl
42 ) :
43     Ip( ip ),
44     Ttl( ttl )
45 {
46 }
47
48 HostAddress::~HostAddress()
49 {
50 }
51
52 address HostAddress::get_ip() const
53 {
54     return Ip;
55 }
56
57 void HostAddress::set_ip( const address &ip )
58 {
59 #if BOOST_VERSION >= 104700
60     BOOST_ASSERT( ip.is_unspecified() );
61 #endif
62
63     Ip = ip;
64 }
65
66 TimeToLive HostAddress::get_ttl() const
67 {
68     return Ttl;
69 }
70
71 void HostAddress::set_ttl( const TimeToLive &ttl )
72 {
73     Ttl = ttl;
74 }
75
76 bool HostAddress::is_valid() const
77 {
78     return Ip != address() && Ip != boost::asio::ip::address_v4()
79                            && Ip != boost::asio::ip::address_v6();
80 }