anyrtpproxy: commandhanlder uses now boost::asio and boost::thread
[anytun.git] / src / anytun-showtables.cpp
blob6e197b198ef2eec8b008693377639caa7f5247e6
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-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 #include "datatypes.h"
34 #include "log.h"
35 #include "buffer.h"
36 #include "keyDerivation.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_end_==PacketSourceEndpoint())
61 std::cout<< "not registered";
62 } else {
63 std::cout<< conn.remote_end_;
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;
84 ConnectionList cl;
85 std::stringstream iss_;
86 int32_t missing_chars=-1;
87 int32_t buffer_size_=0;
88 while( std::cin.good() )
90 char c;
91 std::cin.get(c);
92 iss_ << c;
93 buffer_size_++;
94 while (1)
96 if(missing_chars==-1 && buffer_size_>5)
98 char * buffer = new char [6+1];
99 iss_.read(buffer,6);
100 std::stringstream tmp;
101 tmp.write(buffer,6);
102 tmp>>missing_chars;
103 delete[] buffer;
104 buffer_size_-=6;
106 else if( missing_chars>0 && missing_chars<=buffer_size_ )
108 char * buffer = new char [missing_chars+1];
109 iss_.read(buffer,missing_chars);
110 std::stringstream tmp;
111 tmp.write(buffer,missing_chars);
112 boost::archive::text_iarchive ia(tmp);
113 SyncCommand scom(cl);
114 ia >> scom;
115 buffer_size_-=missing_chars;
116 missing_chars=-1;
117 output(cl);
118 delete[] buffer;
120 else
121 break;
124 return ret;