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
35 #include "datatypes.h"
39 #define PARSE_BOOL_PARAM(SHORT, LONG, VALUE) \
40 else if(str == SHORT || str == LONG) \
43 #define PARSE_INVERSE_BOOL_PARAM(SHORT, LONG, VALUE) \
44 else if(str == SHORT || str == LONG) \
47 #define PARSE_SCALAR_PARAM(SHORT, LONG, VALUE) \
48 else if(str == SHORT || str == LONG) \
50 if(argc < 1 || argv[i+1][0] == '-') \
52 std::stringstream tmp; \
59 #define PARSE_SCALAR_PARAM2(SHORT, LONG, VALUE1, VALUE2) \
60 else if(str == SHORT || str == LONG) \
63 argv[i+1][0] == '-' || argv[i+2][0] == '-') \
65 std::stringstream tmp; \
66 tmp << argv[i+1] << " " << argv[i+2]; \
83 ifconfig_param_local_
= "192.168.200.1";
84 ifconfig_param_remote_netmask_
= "255.255.255.0";
85 seq_window_size_
= 100;
90 bool Options::parse(int argc
, char* argv
[])
97 for(int i
=1; argc
> 0; ++i
)
99 std::string
str(argv
[i
]);
102 if(str
== "-h" || str
== "--help")
104 PARSE_SCALAR_PARAM("-s","--sender-id", sender_id_
)
105 PARSE_SCALAR_PARAM("-i","--interface", local_addr_
)
106 PARSE_SCALAR_PARAM("-p","--port", local_port_
)
107 PARSE_SCALAR_PARAM("-r","--remote-host", remote_addr_
)
108 PARSE_SCALAR_PARAM("-o","--remote-port", remote_port_
)
109 PARSE_SCALAR_PARAM("-d","--dev", dev_name_
)
110 PARSE_SCALAR_PARAM2("-n","--ifconfig", ifconfig_param_local_
, ifconfig_param_remote_netmask_
)
111 PARSE_SCALAR_PARAM("-w","--window-size", seq_window_size_
)
112 PARSE_SCALAR_PARAM("-c","--cypher", cypher_
)
113 PARSE_SCALAR_PARAM("-a","--auth-algo", auth_algo_
)
120 void Options::printUsage()
122 std::cout
<< "USAGE:" << std::endl
;
123 std::cout
<< "anytun [-h|--help] prints this..." << std::endl
;
124 // std::cout << " [-f|--config] <file> the config file" << std::endl;
125 std::cout
<< " [-s|--sender-id ] <sender id> the sender id to use" << std::endl
;
126 std::cout
<< " [-i|--interface] <interface> local interface to bind to" << std::endl
;
127 std::cout
<< " [-p|--port] <port> local port to bind to" << std::endl
;
128 std::cout
<< " [-r|--remote-host] <hostname/ip> remote host" << std::endl
;
129 std::cout
<< " [-o|--remote-port] <port> remote port" << std::endl
;
130 std::cout
<< " [-d|--dev] <name> device name/type" << std::endl
;
131 std::cout
<< " [-n|--ifconfig] <local> the local address for the tun/tap device" << std::endl
132 << " <remote/netmask> the remote address(tun) or netmask(tap)" << std::endl
;
133 std::cout
<< " [-w|--window-size] <window size> seqence number window size" << std::endl
;
134 std::cout
<< " [-c|--cypher] <cypher type> type of cypher" << std::endl
;
135 std::cout
<< " [-a|--auth-algo] <algo type> authentication algoritm" << std::endl
;
138 void Options::printOptions()
141 std::cout
<< "Options:" << std::endl
;
142 std::cout
<< "sender_id='" << sender_id_
<< "'" << std::endl
;
143 std::cout
<< "local_addr='" << local_addr_
<< "'" << std::endl
;
144 std::cout
<< "local_port='" << local_port_
<< "'" << std::endl
;
145 std::cout
<< "remote_addr='" << remote_addr_
<< "'" << std::endl
;
146 std::cout
<< "remote_port='" << remote_port_
<< "'" << std::endl
;
147 std::cout
<< "dev_name='" << dev_name_
<< "'" << std::endl
;
148 std::cout
<< "ifconfig_param_local='" << ifconfig_param_local_
<< "'" << std::endl
;
149 std::cout
<< "ifconfig_param_remote_netmask='" << ifconfig_param_remote_netmask_
<< "'" << std::endl
;
150 std::cout
<< "seq_window_size='" << seq_window_size_
<< "'" << std::endl
;
151 std::cout
<< "cypher='" << cypher_
<< "'" << std::endl
;
152 std::cout
<< "auth_algo='" << auth_algo_
<< "'" << std::endl
;
155 std::string
Options::getProgname()
161 Options
& Options::setProgname(std::string p
)
168 sender_id_t
Options::getSenderId()
173 Options
& Options::setSenderId(sender_id_t s
)
179 std::string
Options::getLocalAddr()
185 Options
& Options::setLocalAddr(std::string l
)
192 u_int16_t
Options::getLocalPort()
197 Options
& Options::setLocalPort(u_int16_t l
)
203 std::string
Options::getRemoteAddr()
209 Options
& Options::setRemoteAddr(std::string r
)
216 u_int16_t
Options::getRemotePort()
221 Options
& Options::setRemotePort(u_int16_t r
)
227 Options
& Options::setRemoteAddrPort(std::string addr
, u_int16_t port
)
235 std::string
Options::getDevName()
241 Options
& Options::setDevName(std::string d
)
248 std::string
Options::getIfconfigParamLocal()
251 return ifconfig_param_local_
;
254 Options
& Options::setIfconfigParamLocal(std::string i
)
257 ifconfig_param_local_
= i
;
261 std::string
Options::getIfconfigParamRemoteNetmask()
264 return ifconfig_param_remote_netmask_
;
267 Options
& Options::setIfconfigParamRemoteNetmask(std::string i
)
270 ifconfig_param_remote_netmask_
= i
;
274 window_size_t
Options::getSeqWindowSize()
276 return seq_window_size_
;
279 Options
& Options::setSeqWindowSize(window_size_t s
)
281 seq_window_size_
= s
;
285 std::string
Options::getCypher()
291 Options
& Options::setCypher(std::string c
)
298 std::string
Options::getAuthAlgo()
304 Options
& Options::setAuthAlgo(std::string a
)