summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/options.c30
-rw-r--r--src/options.h4
-rw-r--r--src/uanytun.c5
3 files changed, 37 insertions, 2 deletions
diff --git a/src/options.c b/src/options.c
index 01c6528..cad58ff 100644
--- a/src/options.c
+++ b/src/options.c
@@ -219,7 +219,7 @@ int options_parse(options_t* opt, int argc, char* argv[])
argc--;
- int i;
+ int i, ipv4_only = 0, ipv6_only = 0;
for(i=1; argc > 0; ++i)
{
char* str = argv[i];
@@ -238,6 +238,8 @@ int options_parse(options_t* opt, int argc, char* argv[])
PARSE_STRING_LIST("-L","--log", opt->log_targets_)
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)
+ PARSE_BOOL_PARAM("-6","--ipv6-only", ipv6_only)
PARSE_STRING_PARAM("-d","--dev", opt->dev_name_)
PARSE_STRING_PARAM("-t","--type", opt->dev_type_)
PARSE_IFCONFIG_PARAM("-n","--ifconfig", opt->ifconfig_param_)
@@ -259,12 +261,28 @@ int options_parse(options_t* opt, int argc, char* argv[])
else
return i;
}
+ if(ipv4_only && ipv6_only)
+ return -3;
+ if(ipv4_only)
+ opt->resolv_addr_type_ = IPV4_ONLY;
+ if(ipv6_only)
+ opt->resolv_addr_type_ = IPV6_ONLY;
return 0;
}
void options_parse_post(options_t* opt)
{
+ if(!opt)
+ return;
+
+#ifdef NO_V4MAPPED
+ if(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")) {
@@ -299,6 +317,7 @@ void options_default(options_t* opt)
opt->sender_id_ = 0;
opt->remote_addr_ = NULL;
opt->remote_port_ = strdup("4444");
+ opt->resolv_addr_type_ = ANY;
opt->dev_name_ = NULL;
opt->dev_type_ = NULL;
opt->ifconfig_param_.net_addr_ = NULL;
@@ -387,6 +406,8 @@ void options_print_usage()
printf(" [-r|--remote-host] <hostname|ip> remote host\n");
printf(" [-o|--remote-port] <port> remote port\n");
+ printf(" [-4|--ipv4-only] always resolv IPv4 addresses\n");
+ printf(" [-6|--ipv6-only] always resolv IPv6 addresses\n");
printf(" [-d|--dev] <name> device name\n");
printf(" [-t|--type] <tun|tap> device type\n");
@@ -426,6 +447,13 @@ void options_print(options_t* opt)
printf("sender_id: %d\n", opt->sender_id_);
printf("remote_addr: '%s'\n", opt->remote_addr_);
printf("remote_port: '%s'\n", opt->remote_port_);
+ printf("resolv_addr_type: ");
+ switch(opt->resolv_addr_type_) {
+ case ANY: printf("any\n"); break;
+ case IPV4_ONLY: printf("ipv4-only\n"); break;
+ case IPV6_ONLY: printf("ipv6-only\n"); break;
+ default: printf("??\n"); break;
+ }
printf("dev_name: '%s'\n", opt->dev_name_);
printf("dev_type: '%s'\n", opt->dev_type_);
printf("ifconfig_net_addr: '%s'\n", opt->ifconfig_param_.net_addr_);
diff --git a/src/options.h b/src/options.h
index 609521f..688a50d 100644
--- a/src/options.h
+++ b/src/options.h
@@ -43,6 +43,9 @@ struct ifconfig_param_struct {
};
typedef struct ifconfig_param_struct ifconfig_param_t;
+enum resolv_addr_type_enum { ANY, IPV4_ONLY, IPV6_ONLY };
+typedef enum resolv_addr_type_enum resolv_addr_type_t;
+
struct options_struct {
char* progname_;
int daemonize_;
@@ -56,6 +59,7 @@ struct options_struct {
sender_id_t sender_id_;
char* remote_addr_;
char* remote_port_;
+ resolv_addr_type_t resolv_addr_type_;
char* dev_name_;
char* dev_type_;
ifconfig_param_t ifconfig_param_;
diff --git a/src/uanytun.c b/src/uanytun.c
index d7873d8..6e276bf 100644
--- a/src/uanytun.c
+++ b/src/uanytun.c
@@ -338,8 +338,11 @@ int main(int argc, char* argv[])
if(ret == -2) {
fprintf(stderr, "memory error on options_parse, exitting\n");
}
+ if(ret == -3) {
+ fprintf(stderr, "syntax error: -4 and -6 are mutual exclusive\n\n");
+ }
- if(ret == -1 || ret > 0)
+ if(ret != -2)
options_print_usage();
options_clear(&opt);