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
38 Options
* Options::inst
= NULL
;
39 Mutex
Options::instMutex
;
40 Options
& gOpt
= Options::instance();
42 Options
& Options::instance()
45 static instanceCleaner c
;
52 Options::Options() : control_interface_("0.0.0.0", 22220)
55 progname_
= "anyrtpproxy";
58 chroot_dir_
= "/var/run";
61 remote_hosts_
.push_back(Host("127.0.0.1", 22222));
68 #define PARSE_BOOL_PARAM(SHORT, LONG, VALUE) \
69 else if(str == SHORT || str == LONG) \
72 #define PARSE_INVERSE_BOOL_PARAM(SHORT, LONG, VALUE) \
73 else if(str == SHORT || str == LONG) \
76 #define PARSE_SCALAR_PARAM(SHORT, LONG, VALUE) \
77 else if(str == SHORT || str == LONG) \
79 if(argc < 1 || argv[i+1][0] == '-') \
81 std::stringstream tmp; \
88 #define PARSE_SCALAR_PARAM2(SHORT, LONG, VALUE1, VALUE2) \
89 else if(str == SHORT || str == LONG) \
92 argv[i+1][0] == '-' || argv[i+2][0] == '-') \
94 std::stringstream tmp; \
95 tmp << argv[i+1] << " " << argv[i+2]; \
102 #define PARSE_STRING_PARAM(SHORT, LONG, VALUE) \
103 else if(str == SHORT || str == LONG) \
105 if(argc < 1 || argv[i+1][0] == '-') \
107 VALUE = std::string(argv[i+1]); \
112 #define PARSE_HEXSTRING_PARAM(SHORT, LONG, VALUE) \
113 else if(str == SHORT || str == LONG) \
115 if(argc < 1 || argv[i+1][0] == '-') \
117 VALUE = Buffer(std::string(argv[i+1])); \
123 #define PARSE_CSLIST_PARAM(SHORT, LONG, LIST) \
124 else if(str == SHORT || str == LONG) \
126 if(argc < 1 || argv[i+1][0] == '-') \
128 std::stringstream tmp(argv[i+1]); \
132 std::string tmp_line; \
133 getline(tmp,tmp_line,','); \
134 LIST.push_back(tmp_line); \
140 bool Options::parse(int argc
, char* argv
[])
146 for(int i
=1; argc
> 0; ++i
)
148 std::string
str(argv
[i
]);
151 if(str
== "-h" || str
== "--help")
153 PARSE_BOOL_PARAM("-t","--chroot", chroot_
)
154 PARSE_SCALAR_PARAM("-u","--user", username_
)
155 PARSE_SCALAR_PARAM("-c","--chroot-dir", chroot_dir_
)
156 PARSE_INVERSE_BOOL_PARAM("-d","--nodaemonize", daemonize_
)
157 PARSE_STRING_PARAM("-s","--control", control_interface_
)
158 PARSE_SCALAR_PARAM("-p","--port", send_port_
)
159 PARSE_CSLIST_PARAM("-r","--remote-hosts", remote_hosts_
)
164 return sanityCheck();
167 bool Options::sanityCheck()
169 if(control_interface_
.port_
) control_interface_
.port_
= 22220;
171 HostList::iterator it
=remote_hosts_
.begin();
172 for(u_int32_t i
=0; it
!= remote_hosts_
.end(); ++it
, ++i
)
173 if(!it
->port_
) it
->port_
= 22222;
178 void Options::printUsage()
180 std::cout
<< "USAGE:" << std::endl
;
181 std::cout
<< "anyrtpproxy [-h|--help] prints this..." << std::endl
;
182 std::cout
<< " [-t|--chroot] chroot and drop priviledges" << std::endl
;
183 std::cout
<< " [-u|--username] <username> in case of chroot run as this user" << std::endl
;
184 std::cout
<< " [-c|--chroot-dir] <directory> directory to make a chroot to" << std::endl
;
185 std::cout
<< " [-d|--nodaemonize] don't run in background" << std::endl
;
186 std::cout
<< " [-s|--control] <addr[:port]> the address/port to listen on for control commands" << std::endl
;
187 std::cout
<< " [-p|--port] <port> use this port to send out packets to remote hosts" << std::endl
;
188 std::cout
<< " [-r|--remote-hosts] <addr[:port]>[,<addr[:<port]> .. ] a list of remote hosts to send duplicates to" << std::endl
;
191 void Options::printOptions()
194 std::cout
<< "Options:" << std::endl
;
195 std::cout
<< "chroot='" << chroot_
<< "'" << std::endl
;
196 std::cout
<< "username='" << username_
<< "'" << std::endl
;
197 std::cout
<< "chroot-dir='" << chroot_dir_
<< "'" << std::endl
;
198 std::cout
<< "daemonize='" << daemonize_
<< "'" << std::endl
;
199 std::cout
<< "control-interface='" << control_interface_
.toString() << "'" << std::endl
;
200 std::cout
<< "send-port='" << send_port_
<< "'" << std::endl
;
201 std::cout
<< "remote hosts='";
202 HostList::const_iterator it
=remote_hosts_
.begin();
203 for(u_int32_t i
=0; it
!= remote_hosts_
.end(); ++it
, ++i
)
205 if(i
) std::cout
<< "','";
206 std::cout
<< it
->toString();
208 std::cout
<< "'" << std::endl
;
211 std::string
Options::getProgname()
217 bool Options::getChroot()
223 std::string
Options::getUsername()
229 std::string
Options::getChrootDir()
235 bool Options::getDaemonize()
241 u_int16_t
Options::getSendPort()
247 Host
Options::getControlInterface()
250 return control_interface_
;
253 HostList
Options::getRemoteHosts()
256 return remote_hosts_
;