working example server and client
[anytun.git] / anytun-showtables.cpp
blobd9ae0962da49f257f5ef3a9b9be7218033d1d8bc
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 #include "datatypes.h"
33 #include "log.h"
34 #include "buffer.h"
35 #include "keyDerivation.h"
36 #include "options.h"
37 #include "seqWindow.h"
38 #include "connectionList.h"
39 #include "routingTable.h"
40 #include "networkAddress.h"
41 #include "syncCommand.h"
43 #include <sstream>
44 #include <iostream>
45 #include <string>
47 #include <boost/archive/text_oarchive.hpp>
48 #include <boost/archive/text_iarchive.hpp>
51 void output(ConnectionList &cl)
53 if( !cl.empty() )
55 ConnectionMap::iterator it = cl.getBeginUnlocked();
56 mux_t mux = it->first;
57 ConnectionParam &conn( it->second );
58 std::cout << "Client " << mux << ": " ;
59 if( conn.remote_host_=="")
61 std::cout<< "not registered";
62 } else {
63 std::cout<< conn.remote_host_ << ':'<<conn.remote_port_;
65 std::cout << std::endl;
66 //std::cout << "Connection: Keyderivation-Type: " << conn.kd_.printType() << std::endl;
67 cl.clear();
69 else if( !gRoutingTable.empty() )
71 RoutingMap::iterator it = gRoutingTable.getBeginUnlocked();
72 NetworkPrefix pref( it->first );
73 std::cout << "Route: " << pref.toString() << "/" << pref.getNetworkPrefixLength() << " -> ";
74 mux_t mux = it->second;
75 std::cout << mux << std::endl;
76 gRoutingTable.clear();
80 int main(int argc, char* argv[])
82 int ret = 0;
83 if(!gOpt.parse(argc, argv))
85 gOpt.printUsage();
86 exit(-1);
89 ConnectionList cl;
90 std::stringstream iss_;
91 int32_t missing_chars=-1;
92 int32_t buffer_size_=0;
93 while( std::cin.good() )
95 char c;
96 std::cin.get(c);
97 iss_ << c;
98 buffer_size_++;
99 while (1)
101 if(missing_chars==-1 && buffer_size_>5)
103 char * buffer = new char [6+1];
104 iss_.read(buffer,6);
105 std::stringstream tmp;
106 tmp.write(buffer,6);
107 tmp>>missing_chars;
108 delete[] buffer;
109 buffer_size_-=6;
111 else if( missing_chars>0 && missing_chars<=buffer_size_ )
113 char * buffer = new char [missing_chars+1];
114 iss_.read(buffer,missing_chars);
115 std::stringstream tmp;
116 tmp.write(buffer,missing_chars);
117 boost::archive::text_iarchive ia(tmp);
118 SyncCommand scom(cl);
119 ia >> scom;
120 buffer_size_-=missing_chars;
121 missing_chars=-1;
122 output(cl);
123 delete[] buffer;
125 else
126 break;
129 return ret;