The following commit has been merged in the master branch: commit b33c13c55cfc9ab07b0d0f1239f61c43e302d019 Author: Stefan Sperling stsp@stsp.in-berlin.de Date: Wed Sep 27 18:27:21 2006 +0200
Add support for OpenBSD.
Undefine LIST_HEAD, if set, at the top of list.h instead of undefining it before including list.h in freebsd.c. This should do no harm and may be needed on any system that has <sys/queue.h> anyway.
diff --git a/Makefile b/Makefile index b2ef3a8..939ef1e 100755 --- a/Makefile +++ b/Makefile @@ -35,6 +35,10 @@ ifeq ($(UNAME),FreeBSD) OS_OBJ= posix.o freebsd.o endif
+ifeq ($(UNAME),OpenBSD) +OS_OBJ= posix.o freebsd.o +endif + batman: batman.o $(OS_OBJ) $(CC) -o $@ batman.o $(OS_OBJ) $(LDFLAGS)
diff --git a/freebsd.c b/freebsd.c index e799aee..6251ca4 100644 --- a/freebsd.c +++ b/freebsd.c @@ -18,6 +18,7 @@ */
#include <sys/types.h> +#include <sys/param.h> #include <sys/sysctl.h> #include <sys/socket.h> #include <netinet/in.h> @@ -29,11 +30,6 @@ #include <stdlib.h> #include <err.h>
-/* Resolve namespace pollution from sys/queue.h */ -#ifdef LIST_HEAD -#undef LIST_HEAD -#endif - #include "os.h" #include "batman.h"
@@ -41,6 +37,8 @@
void set_forwarding(int state) { + int mib[4]; + /* FreeBSD allows us to set the boolean IP forwarding * sysctl to anything. Check the value for sanity. */ if (state < 0 || state > 1) @@ -49,7 +47,12 @@ void set_forwarding(int state) err(1, "set_forwarding: %i", state); }
- if (sysctlbyname(SYSCTL_FORWARDING, NULL, NULL, &state, sizeof(state)) == -1) + mib[0] = CTL_NET; + mib[1] = PF_INET; + mib[2] = IPPROTO_IP; + mib[3] = IPCTL_FORWARDING; + + if (sysctl(mib, 4, NULL, 0, (void*)&state, sizeof(state)) == -1) { err(1, "Cannot enable packet forwarding"); } @@ -59,9 +62,15 @@ int get_forwarding(void) { int state; size_t len; - - len = sizeof(state); - if (sysctlbyname(SYSCTL_FORWARDING, &state, &len, NULL, 0) == -1) + int mib[4]; + + mib[0] = CTL_NET; + mib[1] = PF_INET; + mib[2] = IPPROTO_IP; + mib[3] = IPCTL_FORWARDING; + len = sizeof(int); + + if (sysctl(mib, 4, &state, &len, NULL, 0) == -1) { err(1, "Cannot tell if packet forwarding is enabled"); } diff --git a/list.h b/list.h index c74478d..a0d785b 100755 --- a/list.h +++ b/list.h @@ -1,6 +1,13 @@ #ifndef _LINUX_LIST_H #define _LINUX_LIST_H
+/* + * XXX: Resolve conflict between this file and <sys/queue.h> on BSD systems. + */ +#ifdef LIST_HEAD +#undef LIST_HEAD +#endif + /* * Simple doubly linked list implementation. *