changeset 57:4c083d81f5a8

Fixes for OpenBSD (thanks to Pi <pi-quicktun@mrtheplague.net> and SeekingFor)
author Ivo Smits <Ivo@UCIS.nl>
date Fri, 31 Jan 2014 23:58:53 +0100
parents 377e7d4fbc10
children 732d45ab94ab
files build.sh src/common.c
diffstat 2 files changed, 7 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/build.sh	Fri Jan 31 22:57:46 2014 +0100
+++ b/build.sh	Fri Jan 31 23:58:53 2014 +0100
@@ -7,6 +7,7 @@
 if [ "$(uname -s)" = "OpenBSD" -o "$(uname -s)" = "FreeBSD" -o "$(uname -s)" = "NetBSD" ]; then
 	echo "Detected *BSD"
 	tar="gtar"
+	export CPATH="/usr/local/include:${CPATH}"
 elif [ "$(uname -s)" = "SunOS" ]; then
 	echo "Detected SunOS"
 	tar="gtar"
--- a/src/common.c	Fri Jan 31 22:57:46 2014 +0100
+++ b/src/common.c	Fri Jan 31 23:58:53 2014 +0100
@@ -180,6 +180,9 @@
 		af = ai_remote->ai_family;
 	}
 	if (!af) af = AF_INET;
+	int sa_size = sizeof(sockaddr_any);
+	if (af == AF_INET) sa_size = sizeof(struct sockaddr_in);
+	else if (af == AF_INET6) sa_size = sizeof(struct sockaddr_in6);
 	int sfd = socket(af, SOCK_DGRAM, IPPROTO_UDP);
 	if (sfd < 0) return errorexitp("Could not create UDP socket");
 	sockaddr_any udpaddr;
@@ -189,7 +192,7 @@
 	int port = 2998;
 	if ((envval = getconf("LOCAL_PORT"))) port = atoi(envval);
 	if (sockaddr_set_port(&udpaddr, port)) return -1;
-	if (bind(sfd, (struct sockaddr*)&udpaddr, sizeof(udpaddr))) return errorexitp("Could not bind socket");
+	if (bind(sfd, &udpaddr.any, sa_size)) return errorexitp("Could not bind socket");
 	memset(&udpaddr, 0, sizeof(udpaddr));
 	udpaddr.any.sa_family = af;
 	if (ai_remote) memcpy(&udpaddr, ai_remote->ai_addr, ai_remote->ai_addrlen);
@@ -204,7 +207,7 @@
 		if (session->remote_float) {
 			session->remote_float = 2;
 		} else {
-			if (connect(sfd, (struct sockaddr*)&udpaddr, sizeof(udpaddr))) return errorexitp("Could not connect socket");
+			if (connect(sfd, &udpaddr.any, sa_size)) return errorexitp("Could not connect socket");
 		}
 	}
 	if (ai_local) freeaddrinfo(ai_local);
@@ -318,7 +321,7 @@
 
 	char protocol_data[p->protocol_data_size];
 	memset(protocol_data, 0, p->protocol_data_size);
-	session.protocol_data = &protocol_data;
+	session.protocol_data = protocol_data;
 	if (p->init && p->init(&session) < 0) return -1;
 
 	if (drop_privileges() < 0) return -1;