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-2009 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 as published by
21 * the Free Software Foundation, either version 3 of the License, or
24 * Anytun is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
29 * You should have received a copy of the GNU General Public License
30 * along with anytun. If not, see <http://www.gnu.org/licenses/>.
33 #ifndef ANYTUN_networkAddress_h_INCLUDED
34 #define ANYTUN_networkAddress_h_INCLUDED
36 // TODO not required here
37 #include <boost/archive/text_oarchive.hpp>
38 #include <boost/archive/text_iarchive.hpp>
40 #include "threadUtils.hpp"
41 #include "datatypes.h"
44 #include <boost/asio.hpp>
45 #include <boost/array.hpp>
47 typedef boost::array<unsigned char,6> ethernet_bytes_type;
48 typedef boost::asio::ip::address_v4::bytes_type ipv4_bytes_type;
49 typedef boost::asio::ip::address_v6::bytes_type ipv6_bytes_type;
51 enum network_address_type_t
62 NetworkAddress(const NetworkAddress &);
63 NetworkAddress(const std::string &);
64 NetworkAddress(boost::asio::ip::address_v6);
65 NetworkAddress(boost::asio::ip::address_v4);
66 NetworkAddress(u_int64_t);
67 NetworkAddress(const network_address_type_t type, const std::string & address );
69 void setNetworkAddress(const network_address_type_t type, const std::string & address );
70 void setNetworkAddress(boost::asio::ip::address_v4);
71 void setNetworkAddress(boost::asio::ip::address_v6);
72 void setNetworkAddress(u_int64_t);
73 network_address_type_t getNetworkAddressType() const;
74 std::string toString() const;
75 bool operator<(const NetworkAddress &s) const;
76 ipv4_bytes_type to_bytes_v4() const;
77 ipv6_bytes_type to_bytes_v6() const;
78 ethernet_bytes_type to_bytes_ethernet() const;
79 const boost::asio::ip::address_v4& getNetworkAddressV4() const;
80 const boost::asio::ip::address_v6& getNetworkAddressV6() const;
81 const u_int64_t getNetworkAdrressEther() const;
84 boost::asio::ip::address_v4 ipv4_address_;
85 boost::asio::ip::address_v6 ipv6_address_;
86 u_int64_t ethernet_address_;
87 network_address_type_t network_address_type_;
89 NetworkAddress operator=(const NetworkAddress &s);
90 friend class boost::serialization::access;
91 template<class Archive>
92 void serialize(Archive & ar, const unsigned int version)
94 ar & network_address_type_;
95 if (network_address_type_==ipv4)
97 std::string ip(ipv4_address_.to_string());
99 ipv4_address_=boost::asio::ip::address_v4::from_string(ip);
101 if (network_address_type_==ipv6)
103 std::string ip(ipv6_address_.to_string());
105 ipv6_address_=boost::asio::ip::address_v6::from_string(ip);
107 if (network_address_type_==ethernet)
108 ar & ethernet_address_;
112 // for(int i=0;i<4;i++)
113 //#if defined(__GNUC__) && defined(__linux__)
114 // ar & ipv6_address_.s6_addr32;
115 //#elif defined(__GNUC__) && defined(__OpenBSD__)
116 // ar & ipv6_address_.__u6_addr.__u6_addr32;
118 // #error Target not supported