diff options
author | Christian Pointner <equinox@anytun.org> | 2009-02-25 18:26:44 +0000 |
---|---|---|
committer | Christian Pointner <equinox@anytun.org> | 2009-02-25 18:26:44 +0000 |
commit | fea1fcfad21b9b2cbcda26fd40933ccca2ebe214 (patch) | |
tree | fe4873ef5569d6e70b0ed6b1bdbc562b41cff56a | |
parent | fixed vtable errors for older gcc versions (diff) |
added -4 and -6 to command line parser (no affect until now)
-rw-r--r-- | cmd-option-letters | 3 | ||||
-rw-r--r-- | src/options.cpp | 41 | ||||
-rw-r--r-- | src/options.h | 9 |
3 files changed, 48 insertions, 5 deletions
diff --git a/cmd-option-letters b/cmd-option-letters index 934186e..87ccc0f 100644 --- a/cmd-option-letters +++ b/cmd-option-letters @@ -1,3 +1,6 @@ +4: resolv ipv4 only (payload socket) +6: resolv ipv6 only (payload socket) + a: auth algo b: c: cipher diff --git a/src/options.cpp b/src/options.cpp index 6aa795a..ce1a6fa 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -42,9 +42,12 @@ std::ostream& operator<<(std::ostream& stream, syntax_error const& error) { stream << "syntax error: " << error.what() << std::endl; - stream << " "; - for(u_int32_t i = 0; i < error.pos; ++i) stream << " "; - return stream << "^"; + if(error.pos >= 0) { + stream << " "; + for(int32_t i = 0; i < error.pos; ++i) stream << " "; + return stream << "^"; + } + return stream; } void OptionHost::init(std::string addrPort) @@ -158,6 +161,8 @@ Options::Options() : key_(u_int32_t(0)), salt_(u_int32_t(0)) bind_to_.addr = "127.0.0.1"; bind_to_.port = "2323"; + resolv_addr_type_ = ANY; + local_.addr = ""; local_.port = "4444"; remote_.addr = ""; @@ -321,6 +326,7 @@ bool Options::parse(int argc, char* argv[]) progname_ = argv[0]; argc--; + bool ipv4_only = false, ipv6_only = false; int32_t ld_kdr_tmp = ld_kdr_; for(int i=1; argc > 0; ++i) { @@ -361,6 +367,8 @@ bool Options::parse(int argc, char* argv[]) PARSE_SCALAR_PARAM("-r","--remote-host", remote_.addr) PARSE_SCALAR_PARAM("-o","--remote-port", remote_.port) + PARSE_BOOL_PARAM("-4","--ipv4-only", ipv4_only) + PARSE_BOOL_PARAM("-6","--ipv6-only", ipv6_only) #endif #if defined(ANYTUN_OPTIONS) @@ -410,6 +418,13 @@ bool Options::parse(int argc, char* argv[]) else throw syntax_error(str, 0); } + if(ipv4_only && ipv6_only) + throw syntax_error("-4 and -6 are mutual exclusive", -1); + if(ipv4_only) + resolv_addr_type_ = IPV4_ONLY; + if(ipv6_only) + resolv_addr_type_ = IPV6_ONLY; + ld_kdr_ = static_cast<int8_t>(ld_kdr_tmp); return true; @@ -544,6 +559,14 @@ void Options::printOptions() std::cout << "bind_to.addr = '" << bind_to_.addr << "'" << std::endl; std::cout << "bind_to.port = '" << bind_to_.port << "'" << std::endl; std::cout << std::endl; + std::cout << "resolv_addr_type = "; + switch(resolv_addr_type_) { + case ANY: std::cout << "any" << std::endl; break; + case IPV4_ONLY: std::cout << "ipv4-only" << std::endl; break; + case IPV6_ONLY: std::cout << "ipv6-only" << std::endl; break; + default: std::cout << "?" << std::endl; break; + } + std::cout << std::endl; std::cout << "local.addr = '" << local_.addr << "'" << std::endl; std::cout << "local.port = '" << local_.port << "'" << std::endl; std::cout << "remote.addr = '" << remote_.addr << "'" << std::endl; @@ -708,6 +731,18 @@ Options& Options::setBindToPort(std::string b) } +ResolvAddrType Options::getResolvAddrType() +{ + ReadersLock lock(mutex); + return resolv_addr_type_; +} + +Options& Options::setResolvAddrType(ResolvAddrType r) +{ + WritersLock lock(mutex); + resolv_addr_type_ = r; + return *this; +} std::string Options::getLocalAddr() { diff --git a/src/options.h b/src/options.h index 3e1b5ce..dce8eeb 100644 --- a/src/options.h +++ b/src/options.h @@ -40,8 +40,8 @@ class syntax_error : public std::runtime_error { public: - syntax_error(std::string t, u_int32_t p) : runtime_error(t), pos(p) {}; - u_int32_t pos; + syntax_error(std::string t, int32_t p) : runtime_error(t), pos(p) {}; + int32_t pos; }; std::ostream& operator<<(std::ostream& stream, syntax_error const& error); @@ -77,6 +77,8 @@ std::istream& operator>>(std::istream& stream, OptionNetwork& network); typedef std::list<std::string> StringList; +typedef enum { ANY, IPV4_ONLY, IPV6_ONLY } ResolvAddrType; + class Options { public: @@ -109,6 +111,8 @@ public: std::string getBindToPort(); Options& setBindToPort(std::string b); + ResolvAddrType getResolvAddrType(); + Options& setResolvAddrType(ResolvAddrType r); std::string getLocalAddr(); Options& setLocalAddr(std::string l); std::string getLocalPort(); @@ -189,6 +193,7 @@ private: std::string file_name_; OptionHost bind_to_; + ResolvAddrType resolv_addr_type_; OptionHost local_; OptionHost remote_; |