continue implementation; first tests with recursion returned IPs but then added cance...
[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>
31#include <boost/date_time/posix_time/posix_time.hpp>
9c55ecd3 32
101be5ce
GMF
33#include "dns/timetolive.h"
34
e5567551
GMF
35//-----------------------------------------------------------------------------
36// HostAddress
37//-----------------------------------------------------------------------------
38
39class HostAddress
40{
41public:
42 HostAddress();
101be5ce 43 HostAddress(
496d74d7 44 const boost::asio::ip::address &ip,
b0a693a0 45 uint32_t ttl
101be5ce 46 );
a86e8ddc 47 ~HostAddress();
e5567551 48
496d74d7
GMF
49 boost::asio::ip::address get_ip() const;
50 void set_ip( const boost::asio::ip::address &ip );
e5567551 51
101be5ce
GMF
52 TimeToLive get_ttl() const;
53 void set_ttl( const TimeToLive &ttl );
e5567551
GMF
54
55private:
d3e8a9f9 56 /// IP address of the host
496d74d7 57 boost::asio::ip::address Ip;
d3e8a9f9 58 /// time-to-live of the host IP
101be5ce 59 TimeToLive Ttl;
e5567551 60
c5b4902d
CH
61 /// serialization: needs to be implemented here or will not compile
62 // since there is no serialize in ip::address nor ptime,
63 // need to save in other formats here
946356e1
CH
64 friend class boost::serialization::access;
65 template<class Archive>
c5b4902d
CH
66 void save(Archive & ar, const unsigned int version) const
67 {
68 std::string ip = Ip.to_string();
e18c1337
CH
69 std::string ttl_creation_time = boost::posix_time::to_iso_string(
70 Ttl.TtlSetTime);
c5b4902d 71 ar & BOOST_SERIALIZATION_NVP(ip);
e18c1337
CH
72 ar & BOOST_SERIALIZATION_NVP(Ttl.Ttl);
73 ar & BOOST_SERIALIZATION_NVP(ttl_creation_time);
c5b4902d
CH
74 }
75
76 template<class Archive>
77 void load(Archive & ar, const unsigned int version)
78 {
79 std::string ip;
e18c1337
CH
80 uint32_t ttl_seconds;
81 std::string ttl_creation_time;
c5b4902d 82 ar & BOOST_SERIALIZATION_NVP(ip);
e18c1337
CH
83 ar & BOOST_SERIALIZATION_NVP(ttl_seconds);
84 ar & BOOST_SERIALIZATION_NVP(ttl_creation_time);
c5b4902d
CH
85
86 // now convert to Ip and Ttl
87 Ip = boost::asio::ip::address::from_string(ip);
e18c1337
CH
88 Ttl = TimeToLive();
89 Ttl.Ttl = ttl_seconds;
90 Ttl.TtlSetTime = boost::posix_time::from_iso_string(ttl_creation_time);
c5b4902d
CH
91 }
92
93 BOOST_SERIALIZATION_SPLIT_MEMBER()
e5567551
GMF
94};
95
3bb5b5c0
GMF
96//-----------------------------------------------------------------------------
97// HostAddressList
98//-----------------------------------------------------------------------------
99
100typedef std::list<HostAddress> HostAddressList;
101
a9c88e1c 102#endif // HOST_ADDRESS_H