removed debug statements
[anytun.git] / anytun-showtables.cpp
bloba3fb5056a5a58c32fb8c2517b161aa304089e3e3
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 std::cout << "Connection: Mux-ID: " << mux << std::endl;
58 ConnectionParam &conn( it->second );
59 std::cout << "Connection: Keyderivation-Type: " << conn.kd_.printType() << std::endl;
60 cl.clear();
62 else if( !gRoutingTable.empty() )
64 RoutingMap::iterator it = gRoutingTable.getBeginUnlocked();
65 NetworkPrefix pref( it->first );
66 std::cout << "Route: " << pref.toString() << "/" << pref.getNetworkPrefixLength() << " -> ";
67 mux_t mux = it->second;
68 std::cout << mux << std::endl;
69 gRoutingTable.clear();
71 std::cout << std::endl;
74 int main(int argc, char* argv[])
76 int ret = 0;
77 if(!gOpt.parse(argc, argv))
79 gOpt.printUsage();
80 exit(-1);
83 ConnectionList cl;
84 std::stringstream iss_;
85 int32_t missing_chars=-1;
86 int32_t buffer_size_=0;
87 while( std::cin.good() )
89 char c;
90 std::cin.get(c);
91 iss_ << c;
92 buffer_size_++;
93 while (1)
95 if(missing_chars==-1 && buffer_size_>5)
97 char * buffer = new char [6+1];
98 iss_.read(buffer,6);
99 std::stringstream tmp;
100 tmp.write(buffer,6);
101 tmp>>missing_chars;
102 delete[] buffer;
103 buffer_size_-=6;
105 else if( missing_chars>0 && missing_chars<=buffer_size_ )
107 char * buffer = new char [missing_chars+1];
108 iss_.read(buffer,missing_chars);
109 std::stringstream tmp;
110 tmp.write(buffer,missing_chars);
111 boost::archive::text_iarchive ia(tmp);
112 SyncCommand scom(cl);
113 ia >> scom;
114 buffer_size_-=missing_chars;
115 missing_chars=-1;
116 output(cl);
117 delete[] buffer;
119 else
120 break;
123 return ret;