X-Git-Url: https://git.syn-net.org/debian/?p=anytun.git;a=blobdiff_plain;f=src%2Foptions.cpp;h=5d70751ae26ab1e4aa47237c9444ee2525d2e003;hp=236acb1b350886da9a37c9e864d2affd4b2de161;hb=ece844834d2cecc028ce81ca283f5d441088580e;hpb=bb834fe0ed7a38b724f49b944adb801634eb6194 diff --git a/src/options.cpp b/src/options.cpp index 236acb1..5d70751 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -37,6 +37,8 @@ #include #include "datatypes.h" +#include "version.h" + #include "options.h" #include "log.h" #include "authAlgoFactory.h" @@ -172,6 +174,8 @@ Options::Options() : key_(u_int32_t(0)), salt_(u_int32_t(0)) chroot_dir_ = ""; pid_file_ = ""; + debug_ = false; + file_name_ = ""; bind_to_.addr = "127.0.0.1"; bind_to_.port = "2323"; @@ -369,12 +373,18 @@ bool Options::parse(int argc, char* argv[]) std::string str(argv[i]); argc--; - if(str == "-h" || str == "--help") + if(str == "-h" || str == "--help") { + printUsage(); return false; + } + else if(str == "-v" || str == "--version") { + printVersion(); + return false; + } #if defined(ANYTUN_OPTIONS) || defined(ANYCTR_OPTIONS) - #ifndef NO_DAEMON + #ifndef _MSC_VER PARSE_INVERSE_BOOL_PARAM("-D","--nodaemonize", daemonize_, NOTHING) PARSE_SCALAR_PARAM("-u","--username", username_, NOTHING) PARSE_SCALAR_PARAM("-g","--groupname", groupname_, NOTHING) @@ -385,6 +395,7 @@ bool Options::parse(int argc, char* argv[]) #endif PARSE_STRING_LIST("-L","--log", log_targets_, NOTHING) + PARSE_BOOL_PARAM("-U","--debug", debug_, NOTHING) #if defined(ANYCTR_OPTIONS) @@ -417,9 +428,7 @@ bool Options::parse(int argc, char* argv[]) PARSE_SCALAR_PARAM("-d","--dev", dev_name_, NOTHING) PARSE_SCALAR_PARAM("-t","--type", dev_type_, NOTHING) PARSE_SCALAR_PARAM("-n","--ifconfig", ifconfig_param_, NOTHING) - #ifndef NO_EXEC PARSE_SCALAR_PARAM("-x","--post-up-script", post_up_script_, NOTHING) - #endif #endif #if defined(ANYTUN_OPTIONS) || defined(ANYCONF_OPTIONS) @@ -470,6 +479,27 @@ bool Options::parse(int argc, char* argv[]) throw syntax_error("unknown role name: " + role, -1); } + if(debug_) { + log_targets_.push_back("stdout:5"); + daemonize_ = false; + } + + if(log_targets_.empty()) { +#ifndef _MSC_VER + #if !defined(ANYCONF_OPTIONS) + log_targets_.push_back(std::string("syslog:3,").append(progname_).append(",daemon")); + #else + log_targets_.push_back("stderr:2"); + #endif +#else + #ifdef WIN_SERVICE + log_targets_.push_back(std::string("eventlog:3,").append(progname_)); + #else + log_targets_.push_back("stdout:3"); + #endif +#endif + } + return true; } @@ -496,6 +526,19 @@ void Options::parse_post() dev_type_ = "tun"; } +void Options::printVersion() +{ +#if defined(ANYCTR_OPTIONS) + std::cout << "anytun-controld"; +#elif defined(ANYCONF_OPTIONS) + std::cout << "anytun-config"; +#else + std::cout << "anytun"; +#endif + std::cout << VERSION_STRING_0 << std::endl; + std::cout << VERSION_STRING_1 << std::endl; +} + void Options::printUsage() { std::cout << "USAGE:" << std::endl; @@ -509,10 +552,11 @@ void Options::printUsage() #endif std::cout << " [-h|--help] prints this..." << std::endl; + std::cout << " [-v|--version] print version info and exit" << std::endl; #if defined(ANYTUN_OPTIONS) || defined(ANYCTR_OPTIONS) - #ifndef NO_DAEMON + #ifndef _MSC_VER std::cout << " [-D|--nodaemonize] don't run in background" << std::endl; std::cout << " [-u|--username] change to this user" << std::endl; std::cout << " [-g|--groupname] change to this group" << std::endl; @@ -524,6 +568,8 @@ void Options::printUsage() std::cout << " [-L|--log] :[,[,..]]" << std::endl; std::cout << " add a log target, can be invoked several times" << std::endl; + std::cout << " i.e.: stdout:5" << std::endl; + std::cout << " [-U|--debug] don't daemonize and log to stdout with maximum log level" << std::endl; #if defined(ANYCTR_OPTIONS) @@ -559,9 +605,7 @@ void Options::printUsage() std::cout << " [-d|--dev] device name" << std::endl; std::cout << " [-t|--type] device type" << std::endl; std::cout << " [-n|--ifconfig] / the local address for the tun/tap device and the used prefix length" << std::endl; - #ifndef NO_EXEC std::cout << " [-x|--post-up-script]