summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anytun.org>2009-02-26 14:37:58 +0000
committerChristian Pointner <equinox@anytun.org>2009-02-26 14:37:58 +0000
commit3916b75f1ef7858101a1020f821115d83f285284 (patch)
treee01fb0d58403aa08ed9a241de2242ae48696914a /src
parentadded -4 and -6 command line arguments (diff)
added -4 and -6 switches to udp socket
Diffstat (limited to 'src')
-rwxr-xr-xsrc/configure8
-rw-r--r--src/options.c2
-rw-r--r--src/uanytun.c4
-rw-r--r--src/udp.c34
-rw-r--r--src/udp.h11
5 files changed, 31 insertions, 28 deletions
diff --git a/src/configure b/src/configure
index 3d630e9..d112494 100755
--- a/src/configure
+++ b/src/configure
@@ -51,8 +51,8 @@ print_usage() {
echo " --use-ssl-crypto use ssl crypto library instead of libgcrypt"
echo " --disable-crypto disable crypto at all (only NULL cipher)"
echo " --disable-passphrase disable master key and salt passphrase"
- echo " --disable-v4-mapped disable V4-Mapped addresses (until now this means"
- echo " to disable IPv6 as outer protocol)"
+ echo " --disable-v4-mapped disable V4-Mapped addresses (this means to disable"
+ echo " simultanious use of IPv4 and IPv6)"
}
for arg
@@ -136,8 +136,8 @@ if [ $PASSPHRASE -eq 0 ]; then
fi
if [ $V4_MAPPED -eq 0 ]; then
- CFLAGS=$CFLAGS' -DNO_UDPV6'
- echo "WARNING: disabling V4 mapped addresses, this prevents uanytun from using IPv6 as outer Protocol"
+ CFLAGS=$CFLAGS' -DNO_V4MAPPED'
+ echo "WARNING: disabling V4 mapped addresses, this prevents uanytun from using IPv6 and IPv4 Sockets at the same time"
fi
if [ "x$PREFIX" = "x/usr" ]; then
diff --git a/src/options.c b/src/options.c
index cad58ff..d8327db 100644
--- a/src/options.c
+++ b/src/options.c
@@ -277,7 +277,7 @@ void options_parse_post(options_t* opt)
return;
#ifdef NO_V4MAPPED
- if(resolv_addr_type_ == any) {
+ 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");
}
diff --git a/src/uanytun.c b/src/uanytun.c
index 6e276bf..380dca5 100644
--- a/src/uanytun.c
+++ b/src/uanytun.c
@@ -412,7 +412,7 @@ int main(int argc, char* argv[])
udp_socket_t sock;
- ret = udp_init(&sock, opt.local_addr_, opt.local_port_);
+ ret = udp_init(&sock, opt.local_addr_, opt.local_port_, opt.resolv_addr_type_);
if(ret) {
log_printf(ERROR, "error on udp_init, exitting");
tun_close(&dev);
@@ -428,7 +428,7 @@ int main(int argc, char* argv[])
if(opt.remote_addr_) {
- if(!udp_set_remote(&sock, opt.remote_addr_, opt.remote_port_)) {
+ if(!udp_set_remote(&sock, opt.remote_addr_, opt.remote_port_, opt.resolv_addr_type_)) {
char* remote_string = udp_get_remote_end_string(&sock);
if(remote_string) {
log_printf(NOTICE, "set remote end to: %s", remote_string);
diff --git a/src/udp.c b/src/udp.c
index d17ffef..e75e1ef 100644
--- a/src/udp.c
+++ b/src/udp.c
@@ -47,7 +47,7 @@
#include <arpa/inet.h>
#include <netinet/in.h>
-int udp_init(udp_socket_t* sock, const char* local_addr, const char* port)
+int udp_init(udp_socket_t* sock, const char* local_addr, const char* port, resolv_addr_type_t resolv_type)
{
if(!sock || !port)
return -1;
@@ -64,11 +64,11 @@ int udp_init(udp_socket_t* sock, const char* local_addr, const char* port)
hints.ai_socktype = SOCK_DGRAM;
hints.ai_flags |= AI_PASSIVE;
-#ifdef NO_UDPV6
- hints.ai_family = PF_INET;
-#else
- hints.ai_family = PF_UNSPEC;
-#endif
+ switch(resolv_type) {
+ case IPV4_ONLY: hints.ai_family = PF_INET; break;
+ case IPV6_ONLY: hints.ai_family = PF_INET6; break;
+ default: hints.ai_family = PF_UNSPEC; break;
+ }
int errcode = getaddrinfo(local_addr, port, &hints, &res);
if (errcode != 0) {
@@ -101,12 +101,20 @@ int udp_init(udp_socket_t* sock, const char* local_addr, const char* port)
return -1;
}
+#ifdef NO_V4MAPPED
+ if(res->ai_family == AF_INET6) {
+ log_printf(NOTICE, "disabling V4-Mapped addresses");
+ int on = 1;
+ if(setsockopt(sock->fd_, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)))
+ log_printf(ERROR, "Error on setting IPV6_V6ONLY socket option: %m");
+ }
+#endif
freeaddrinfo(res);
return 0;
}
-int udp_set_remote(udp_socket_t* sock, const char* remote_addr, const char* port)
+int udp_set_remote(udp_socket_t* sock, const char* remote_addr, const char* port, resolv_addr_type_t resolv_type)
{
if(!sock || !remote_addr || !port)
return -1;
@@ -117,11 +125,11 @@ int udp_set_remote(udp_socket_t* sock, const char* remote_addr, const char* port
memset (&hints, 0, sizeof (hints));
hints.ai_socktype = SOCK_DGRAM;
-#ifdef NO_UDPV6
- hints.ai_family = PF_INET;
-#else
- hints.ai_family = PF_UNSPEC;
-#endif
+ switch(resolv_type) {
+ case IPV4_ONLY: hints.ai_family = PF_INET; break;
+ case IPV6_ONLY: hints.ai_family = PF_INET6; break;
+ default: hints.ai_family = PF_UNSPEC; break;
+ }
int errcode = getaddrinfo(remote_addr, port, &hints, &res);
if (errcode != 0) {
@@ -164,14 +172,12 @@ char* udp_endpoint_to_string(udp_endpoint_t e)
addrstr_len = INET_ADDRSTRLEN + 1;
addrport_sep = ':';
break;
-#ifndef NO_UDPV6
case AF_INET6:
ptr = &((struct sockaddr_in6 *)&e)->sin6_addr;
port = ntohs(((struct sockaddr_in6 *)&e)->sin6_port);
addrstr_len = INET6_ADDRSTRLEN + 1;
addrport_sep = '.';
break;
-#endif
default:
asprintf(&ret, "unknown address type");
return ;
diff --git a/src/udp.h b/src/udp.h
index d7ff5fd..aacdae8 100644
--- a/src/udp.h
+++ b/src/udp.h
@@ -35,15 +35,12 @@
#ifndef _UDP_H_
#define _UDP_H_
+#include "options.h"
+
#include <sys/types.h>
#include <sys/socket.h>
-#ifdef NO_UDPV6
-#include <netinet/in.h>
-typedef struct sockaddr_in udp_endpoint_t;
-#else
typedef struct sockaddr_storage udp_endpoint_t;
-#endif
struct udp_socket_struct {
int fd_;
@@ -53,8 +50,8 @@ struct udp_socket_struct {
};
typedef struct udp_socket_struct udp_socket_t;
-int udp_init(udp_socket_t* sock, const char* local_addr, const char* port);
-int udp_set_remote(udp_socket_t* sock, const char* remote_addr, const char* port);
+int udp_init(udp_socket_t* sock, const char* local_addr, const char* port, resolv_addr_type_t resolv_type);
+int udp_set_remote(udp_socket_t* sock, const char* remote_addr, const char* port, resolv_addr_type_t resolv_type);
void udp_close(udp_socket_t* sock);
char* udp_endpoint_to_string(udp_endpoint_t e);