Imported Upstream version 0.3.3
[debian/uanytun.git] / src / options.c
index f5010bf..331a3c3 100644 (file)
@@ -15,7 +15,7 @@
  *  tunneling and relaying of packets of any protocol.
  *  
  *
- *  Copyright (C) 2007-2008 Christian Pointner <equinox@anytun.org>
+ *  Copyright (C) 2007-2010 Christian Pointner <equinox@anytun.org>
  *
  *  This file is part of uAnytun.
  *
@@ -34,6 +34,7 @@
  */
 
 #include "datatypes.h"
+#include "version.h"
 
 #include "options.h"
 
@@ -233,6 +234,8 @@ int options_parse(options_t* opt, int argc, char* argv[])
 
     if(!strcmp(str,"-h") || !strcmp(str,"--help"))
       return -1;
+    else if(!strcmp(str,"-v") || !strcmp(str,"--version"))
+      return -5;
     PARSE_INVERSE_BOOL_PARAM("-D","--nodaemonize", opt->daemonize_)
     PARSE_STRING_PARAM("-u","--username", opt->username_)
     PARSE_STRING_PARAM("-g","--groupname", opt->groupname_)
@@ -242,6 +245,7 @@ int options_parse(options_t* opt, int argc, char* argv[])
     PARSE_STRING_PARAM("-p","--port", opt->local_port_)
     PARSE_INT_PARAM("-s","--sender-id", opt->sender_id_)
     PARSE_STRING_LIST("-L","--log", opt->log_targets_)
+    PARSE_BOOL_PARAM("-U", "--debug", opt->debug_)
     PARSE_STRING_PARAM("-r","--remote-host", opt->remote_addr_)
     PARSE_STRING_PARAM("-o","--remote-port", opt->remote_port_)
     PARSE_BOOL_PARAM("-4","--ipv4-only", ipv4_only)
@@ -274,6 +278,14 @@ int options_parse(options_t* opt, int argc, char* argv[])
   if(ipv6_only)
     opt->resolv_addr_type_ = IPV6_ONLY;
 
+  if(opt->debug_) {
+    string_list_add(&opt->log_targets_, "stdout:5");
+    opt->daemonize_ = 0;
+  }
+
+  if(!opt->log_targets_.first_)
+    string_list_add(&opt->log_targets_, "syslog:3,uanytun,daemon");
+
 #ifndef NO_CRYPT
   if(role) {
     if(!strcmp(role, "alice") || !strcmp(role, "server") || !strcmp(role, "left"))
@@ -295,13 +307,6 @@ void options_parse_post(options_t* opt)
   if(!opt)
     return;
 
-#ifdef NO_V4MAPPED
-  if(opt->resolv_addr_type_ == ANY) {
-    opt->resolv_addr_type_ = IPV4_ONLY;
-    log_printf(WARNING, "No support for V4-mapped Adresses on this platform, defaulting to only use IPv4 addresses");
-  }
-#endif
-
 #ifndef NO_CRYPT
   if(!strcmp(opt->cipher_, "null") && !strcmp(opt->auth_algo_, "null") && 
      strcmp(opt->kd_prf_, "null")) {
@@ -338,6 +343,7 @@ void options_default(options_t* opt)
   opt->chroot_dir_ = NULL;
   opt->pid_file_ = NULL;
   string_list_init(&opt->log_targets_);
+  opt->debug_ = 0;
   opt->local_addr_ = NULL;
   opt->local_port_ = strdup("4444");
   opt->sender_id_ = 0;
@@ -420,6 +426,7 @@ void options_print_usage()
 {
   printf("USAGE:\n");
   printf("uanytun [-h|--help]                         prints this...\n");
+  printf("        [-v|--version]                      print version info and exit\n");
   printf("        [-D|--nodaemonize]                  don't run in background\n");
   printf("        [-u|--username] <username>          change to this user\n");
   printf("        [-g|--groupname] <groupname>        change to this group\n");
@@ -430,6 +437,7 @@ void options_print_usage()
   printf("        [-s|--sender-id ] <sender id>       the sender id to use\n");
   printf("        [-L|--log] <target>:<level>[,<param1>[,<param2>..]]\n");
   printf("                                            add a log target, can be invoked several times\n");
+  printf("        [-U|--debug]                        don't daemonize and log to stdout with maximum log level\n");
 
   printf("        [-r|--remote-host] <hostname|ip>    remote host\n");
   printf("        [-o|--remote-port] <port>           remote port\n");
@@ -456,6 +464,12 @@ void options_print_usage()
 #endif
 }
 
+void options_print_version()
+{
+  printf("%s\n", VERSION_STRING_0);
+  printf("%s\n", VERSION_STRING_1);
+}
+
 void options_print(options_t* opt)
 {
   if(!opt)
@@ -469,6 +483,7 @@ void options_print(options_t* opt)
   printf("pid_file: '%s'\n", opt->pid_file_);
   printf("log_targets: \n");
   string_list_print(&opt->log_targets_, "  '", "'\n");
+  printf("debug: %s\n", !opt->debug_ ? "false" : "true");
   printf("local_addr: '%s'\n", opt->local_addr_);
   printf("local_port: '%s'\n", opt->local_port_);
   printf("sender_id: %d\n", opt->sender_id_);