working version with crypto
[anytun.git] / networkAddress.h
blob33cc4b5d1d3b29df45ab4f4821f5ba6a43eb47be
1 /*
2 * anytun
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 anytun.org <satp@wirdorange.org>
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License version 2
18 * as published by the Free Software Foundation.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program (see the file COPYING included with this
27 * distribution); if not, write to the Free Software Foundation, Inc.,
28 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #ifndef _NETWORK_ADDRESS_H
32 #define _NETWORK_ADDRESS_H
33 #include <boost/archive/text_oarchive.hpp>
34 #include <boost/archive/text_iarchive.hpp>
36 #include "threadUtils.hpp"
37 #include "datatypes.h"
39 #include <sys/socket.h>
40 #include <netinet/in.h>
41 #include <arpa/inet.h>
42 #include <string>
44 enum network_address_type_t
46 ipv4,
47 ipv6,
48 ethernet
51 class NetworkAddress
53 public:
54 NetworkAddress();
55 NetworkAddress(const NetworkAddress &);
56 NetworkAddress(in6_addr);
57 NetworkAddress(in_addr);
58 NetworkAddress(uint64_t);
59 NetworkAddress(const network_address_type_t type, const char * address );
60 ~NetworkAddress();
61 void setNetworkAddress(const network_address_type_t type, const char * address );
62 void getNetworkAddress(const char *);
63 network_address_type_t getNetworkAddressType();
64 std::string toString() const;
65 bool operator<(const NetworkAddress &s) const;
66 NetworkAddress operator&(const NetworkAddress &s) const;
67 NetworkAddress operator&=(const NetworkAddress &s);
68 NetworkAddress operator<<(uint8_t shift) const;
70 protected:
71 Mutex mutex_;
72 in_addr ipv4_address_;
73 in6_addr ipv6_address_;
74 uint64_t ethernet_address_;
75 network_address_type_t network_address_type_;
76 private:
77 NetworkAddress operator=(const NetworkAddress &s);
78 friend class boost::serialization::access;
79 template<class Archive>
80 void serialize(Archive & ar, const unsigned int version)
82 ar & network_address_type_;
83 if (network_address_type_==ipv4)
84 ar & ipv4_address_.s_addr;
85 if (network_address_type_==ipv6)
86 for(int i=0;i<4;i++)
87 ar & ipv6_address_.s6_addr32;
88 if (network_address_type_==ethernet)
89 ar & ethernet_address_;
93 #endif