summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anytun.org>2008-12-29 18:48:39 +0000
committerChristian Pointner <equinox@anytun.org>2008-12-29 18:48:39 +0000
commit7a3cf1eeed77e6918c04cc913cd6d7602eeb090a (patch)
tree309dd9d4a56771cfb27664d0f81253dda7ac1c3d /src
parentadded bsd tun device (diff)
works on OpenBSD now (but no support for UDPv6)
Diffstat (limited to 'src')
-rw-r--r--src/Makefile1
-rw-r--r--src/udp.c19
-rw-r--r--src/udp.h6
3 files changed, 24 insertions, 2 deletions
diff --git a/src/Makefile b/src/Makefile
index 6a5280f..740373c 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -42,6 +42,7 @@ ifeq ($(TARGET),Linux)
LDFLAGS += -ldl
endif
ifeq ($(TARGET),OpenBSD)
+ CCFLAGS += -DNO_UDPV6
LDFLAGS += -L/usr/local/lib
endif
diff --git a/src/udp.c b/src/udp.c
index 6ae7066..2ffeab6 100644
--- a/src/udp.c
+++ b/src/udp.c
@@ -58,10 +58,16 @@ void udp_init(udp_socket_t** sock, const char* local_addr, const char* port)
struct addrinfo hints, *res;
memset (&hints, 0, sizeof (hints));
- hints.ai_family = PF_UNSPEC;
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
+
+
int errcode = getaddrinfo(local_addr, port, &hints, &res);
if (errcode != 0) {
log_printf(ERR, "Error resolving local address: %s", gai_strerror(errcode));
@@ -71,6 +77,7 @@ void udp_init(udp_socket_t** sock, const char* local_addr, const char* port)
}
memcpy(&((*sock)->local_end_), res->ai_addr, sizeof(*(res->ai_addr)));
+
(*sock)->fd_ = socket(res->ai_family, SOCK_DGRAM, 0);
if((*sock)->fd_ < 0) {
log_printf(ERR, "Error on opening udp socket: %m");
@@ -98,9 +105,15 @@ void udp_set_remote(udp_socket_t* sock, const char* remote_addr, const char* por
struct addrinfo hints, *res;
memset (&hints, 0, sizeof (hints));
- hints.ai_family = PF_UNSPEC;
hints.ai_socktype = SOCK_DGRAM;
+#ifdef NO_UDPV6
+ hints.ai_family = PF_INET;
+#else
+ hints.ai_family = PF_UNSPEC;
+#endif
+
+
int errcode = getaddrinfo(remote_addr, port, &hints, &res);
if (errcode != 0) {
log_printf(ERR, "Error resolving remote address: %s", gai_strerror(errcode));
@@ -136,11 +149,13 @@ char* udp_endpoint_to_string(udp_endpoint_t e)
port = ntohs(((struct sockaddr_in *)&e)->sin_port);
addrstr_len = INET_ADDRSTRLEN + 1;
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;
break;
+#endif
default:
return "";
}
diff --git a/src/udp.h b/src/udp.h
index 4873483..7bddf15 100644
--- a/src/udp.h
+++ b/src/udp.h
@@ -38,7 +38,13 @@
#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_;
udp_endpoint_t local_end_;