4 * The secure anycast tunneling protocol (satp) defines a protocol used
5 * for communication between any combination of unicast and anycast
6 * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel
7 * mode and allows tunneling of every ETHER TYPE protocol (e.g.
8 * ethernet, ip, arp ...). satp directly includes cryptography and
9 * message authentication based on the methodes used by SRTP. It is
10 * intended to deliver a generic, scaleable and secure solution for
11 * tunneling and relaying of packets of any protocol.
14 * Copyright (C) 2007-2008 Othmar Gsenger, Erwin Nindl,
15 * Christian Pointner <satp@wirdorange.org>
17 * This file is part of Anytun.
19 * Anytun is free software: you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License version 3 as
21 * published by the Free Software Foundation.
23 * Anytun is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with anytun. If not, see <http://www.gnu.org/licenses/>.
32 #ifndef _NETWORK_ADDRESS_H
33 #define _NETWORK_ADDRESS_H
34 #include <boost/archive/text_oarchive.hpp>
35 #include <boost/archive/text_iarchive.hpp>
37 #include "threadUtils.hpp"
38 #include "datatypes.h"
41 #include <boost/asio.hpp>
42 #include <boost/array.hpp>
44 typedef boost::array<unsigned char,6> ethernet_bytes_type;
45 typedef boost::asio::ip::address_v4::bytes_type ipv4_bytes_type;
46 typedef boost::asio::ip::address_v6::bytes_type ipv6_bytes_type;
48 enum network_address_type_t
59 NetworkAddress(const NetworkAddress &);
60 NetworkAddress(const std::string &);
61 NetworkAddress(boost::asio::ip::address_v6);
62 NetworkAddress(boost::asio::ip::address_v4);
63 NetworkAddress(u_int64_t);
64 NetworkAddress(const network_address_type_t type, const std::string & address );
66 void setNetworkAddress(const network_address_type_t type, const std::string & address );
67 void setNetworkAddress(boost::asio::ip::address_v4);
68 void setNetworkAddress(boost::asio::ip::address_v6);
69 void setNetworkAddress(u_int64_t);
70 network_address_type_t getNetworkAddressType() const;
71 std::string toString() const;
72 bool operator<(const NetworkAddress &s) const;
73 ipv4_bytes_type to_bytes_v4() const;
74 ipv6_bytes_type to_bytes_v6() const;
75 ethernet_bytes_type to_bytes_ethernet() const;
76 const boost::asio::ip::address_v4& getNetworkAddressV4() const;
77 const boost::asio::ip::address_v6& getNetworkAddressV6() const;
78 const u_int64_t getNetworkAdrressEther() const;
81 boost::asio::ip::address_v4 ipv4_address_;
82 boost::asio::ip::address_v6 ipv6_address_;
83 u_int64_t ethernet_address_;
84 network_address_type_t network_address_type_;
86 NetworkAddress operator=(const NetworkAddress &s);
87 friend class boost::serialization::access;
88 template<class Archive>
89 void serialize(Archive & ar, const unsigned int version)
91 ar & network_address_type_;
92 if (network_address_type_==ipv4)
94 std::string ip(ipv4_address_.to_string());
96 ipv4_address_=boost::asio::ip::address_v4::from_string(ip);
98 if (network_address_type_==ipv6)
100 std::string ip(ipv6_address_.to_string());
102 ipv6_address_=boost::asio::ip::address_v6::from_string(ip);
104 if (network_address_type_==ethernet)
105 ar & ethernet_address_;
109 // for(int i=0;i<4;i++)
110 //#if defined(__GNUC__) && defined(__linux__)
111 // ar & ipv6_address_.s6_addr32;
112 //#elif defined(__GNUC__) && defined(__OpenBSD__)
113 // ar & ipv6_address_.__u6_addr.__u6_addr32;
115 // #error Target not supported