diff options
author | Christian Pointner <equinox@anytun.org> | 2008-11-25 04:13:55 +0000 |
---|---|---|
committer | Christian Pointner <equinox@anytun.org> | 2008-11-25 04:13:55 +0000 |
commit | ea607fcc37694c55e10d0180bdaf8a676bbdf7c8 (patch) | |
tree | 9310e0c444ce30049c8b8ab0a223f7e7c2d003e0 /src/options.cpp | |
parent | small type cleanup (diff) |
options parser support ipv6 now
fixed anytun-controld
- fixed log issues
- added better error output
- some cleanups
Diffstat (limited to 'src/options.cpp')
-rw-r--r-- | src/options.cpp | 64 |
1 files changed, 56 insertions, 8 deletions
diff --git a/src/options.cpp b/src/options.cpp index 806c7c8..1a40f59 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -201,18 +201,60 @@ bool Options::parse(int argc, char* argv[]) while(!host_port_queue.empty()) { - std::stringstream tmp_stream(host_port_queue.front()); - OptionConnectTo oct; - getline(tmp_stream,oct.host,':'); - if(!tmp_stream.good()) - return false; - tmp_stream >> oct.port; - host_port_queue.pop(); - connect_to_.push_back(oct); + bool ret = splitAndAddHostPort(host_port_queue.front(), connect_to_); + if(!ret) return false; + host_port_queue.pop(); } return true; } +bool Options::splitAndAddHostPort(std::string hostPort, ConnectToList& list) +{ + OptionConnectTo oct; + size_t pos = hostPort.find_first_of("["); + + if(pos != std::string::npos && pos != 0) + return false; // an [ was found but not at the beginning + + bool hasPort = false; + if(pos != std::string::npos) { + hostPort.erase(pos, 1); + pos = hostPort.find_first_of("]"); + + if(pos == std::string::npos) + return false; // no trailing ] although an leading [ was found + + if(pos < hostPort.length()-2) { + + if(hostPort[pos+1] != ':') + return false; // wrong port delimieter + + hostPort[pos+1] = '/'; + hasPort = true; + } + else if(pos != hostPort.length()-1) + return false; // to few characters left + + hostPort.erase(pos, 1); + } + + if(hasPort) { + std::stringstream tmp_stream(hostPort); + getline(tmp_stream,oct.host,'/'); + if(!tmp_stream.good()) + return false; + + tmp_stream >> oct.port; + } + else { + oct.host = hostPort; + oct.port = "2323"; // default sync port + } + + list.push_back(oct); + return true; +} + void Options::printUsage() { std::cout << "USAGE:" << std::endl; @@ -276,6 +318,12 @@ void Options::printOptions() std::cout << "salt=" << salt_.getHexDumpOneLine() << std::endl; std::cout << "kd_prf='" << kd_prf_ << "'" << std::endl; std::cout << "auth_algo='" << auth_algo_ << "'" << std::endl; + + std::cout << "connect_to="; + ConnectToList::const_iterator it = connect_to_.begin(); + for(; it != connect_to_.end(); ++it) + std::cout << "'" << it->host << "','" << it->port << "';"; + std::cout << std::endl; } std::string Options::getProgname() |