merged PingRotate into PingScheduler; fixed save/load of cache to/from file; started...
[pingcheck] / src / dns / hostaddress.h
CommitLineData
91fcc471
TJ
1/*
2The software in this package is distributed under the GNU General
3Public License version 2 (with a special exception described below).
4
5A copy of GNU General Public License (GPL) is included in this distribution,
6in the file COPYING.GPL.
7
8As a special exception, if other files instantiate templates or use macros
9or inline functions from this file, or you compile this file and link it
10with other works to produce a work based on this file, this file
11does not by itself cause the resulting work to be covered
12by the GNU General Public License.
13
14However the source code for this file must still be made available
15in accordance with section (3) of the GNU General Public License.
16
17This exception does not invalidate any other reasons why a work based
18on this file might be covered by the GNU General Public License.
19*/
a9c88e1c
GMF
20#ifndef HOST_ADDRESS_H
21#define HOST_ADDRESS_H
e5567551 22
b0a693a0
GMF
23#include <stdint.h>
24
3bb5b5c0 25#include <list>
496d74d7
GMF
26
27#include <boost/asio.hpp>
946356e1 28#include <boost/serialization/access.hpp>
c5b4902d
CH
29#include <boost/serialization/nvp.hpp>
30#include <boost/serialization/split_member.hpp>
9c55ecd3 31
101be5ce
GMF
32#include "dns/timetolive.h"
33
e5567551
GMF
34//-----------------------------------------------------------------------------
35// HostAddress
36//-----------------------------------------------------------------------------
37
38class HostAddress
39{
40public:
41 HostAddress();
101be5ce 42 HostAddress(
496d74d7 43 const boost::asio::ip::address &ip,
b0a693a0 44 uint32_t ttl
101be5ce 45 );
a86e8ddc 46 ~HostAddress();
e5567551 47
496d74d7
GMF
48 boost::asio::ip::address get_ip() const;
49 void set_ip( const boost::asio::ip::address &ip );
e5567551 50
101be5ce
GMF
51 TimeToLive get_ttl() const;
52 void set_ttl( const TimeToLive &ttl );
e5567551 53
26b0f687
CH
54 // return false if this HostAddress was default-constructed, so does not
55 // actually point to an ip (ip is probably 0.0.0.0)
56 bool is_valid() const;
57
e5567551 58private:
d3e8a9f9 59 /// IP address of the host
496d74d7 60 boost::asio::ip::address Ip;
d3e8a9f9 61 /// time-to-live of the host IP
101be5ce 62 TimeToLive Ttl;
e5567551 63
c5b4902d
CH
64 /// serialization: needs to be implemented here or will not compile
65 // since there is no serialize in ip::address nor ptime,
66 // need to save in other formats here
946356e1
CH
67 friend class boost::serialization::access;
68 template<class Archive>
c5b4902d
CH
69 void save(Archive & ar, const unsigned int version) const
70 {
26b0f687
CH
71 std::string ip_str = Ip.to_string();
72 ar & BOOST_SERIALIZATION_NVP(ip_str);
dbe986b9 73 ar & BOOST_SERIALIZATION_NVP(Ttl);
c5b4902d
CH
74 }
75
76 template<class Archive>
77 void load(Archive & ar, const unsigned int version)
78 {
26b0f687
CH
79 std::string ip_str;
80 ar & BOOST_SERIALIZATION_NVP(ip_str);
dbe986b9 81 ar & BOOST_SERIALIZATION_NVP(Ttl);
26b0f687 82 Ip = boost::asio::ip::address::from_string(ip_str);
dbe986b9 83
c5b4902d
CH
84 }
85
86 BOOST_SERIALIZATION_SPLIT_MEMBER()
e5567551
GMF
87};
88
3bb5b5c0
GMF
89//-----------------------------------------------------------------------------
90// HostAddressList
91//-----------------------------------------------------------------------------
92
93typedef std::list<HostAddress> HostAddressList;
94
a9c88e1c 95#endif // HOST_ADDRESS_H