summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile34
-rw-r--r--src/anytun.cpp12
-rw-r--r--src/networkAddress.cpp29
-rw-r--r--src/networkAddress.h7
-rw-r--r--src/networkPrefix.cpp7
-rw-r--r--src/plainPacket.cpp7
6 files changed, 81 insertions, 15 deletions
diff --git a/src/Makefile b/src/Makefile
index 902d2a0..a1f102e 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,5 +1,6 @@
+TARGET=$(shell uname -s)
C = gcc
-CFLAGS = -g -Wall
+CFLAGS = -g
CFLAGS += -DSOCKETS_NAMESPACE=sockets
CFLAGS += -DSOCKETS_NAMESPACE_STR='"sockets"'
C++ = g++
@@ -7,7 +8,16 @@ CCFLAGS = -g -Wall
CCFLAGS += -DSOCKETS_NAMESPACE=sockets
CCFLAGS += -DSOCKETS_NAMESPACE_STR='"sockets"'
LD = g++
-LDFLAGS = -g -Wall -O2 -ldl -lpthread -lgcrypt -lboost_serialization
+LDFLAGS = -g -Wall -O2 -lpthread -lgcrypt -lgpg-error -lboost_serialization
+
+ifeq ($(TARGET),Linux)
+ LDFLAGS += -ldl
+endif
+ifeq ($(TARGET),OpenBSD)
+ CCFLAGS += -I/usr/local/include
+ LDFLAGS += -L/usr/local/lib
+endif
+
OPENVPNDEPS = openvpn/tun.o \
openvpn/error.o \
@@ -141,7 +151,7 @@ tunDevice.o: tunDevice.cpp tunDevice.h
$(C++) $(CCFLAGS) $< -c
Sockets/libSockets.a:
- make --directory=./Sockets
+ $(MAKE) --directory=./Sockets
packetSource.o: packetSource.cpp packetSource.h
$(C++) $(CCFLAGS) $< -c
@@ -255,7 +265,7 @@ anytun.o: anytun.cpp
$(C++) $(CCFLAGS) $< -c
anytun-nosync.o: anytun.cpp
- $(C++) -g -Wall -DANYTUN_NOSYNC $< -c -o anytun-nosync.o
+ $(C++) $(CCFLAGS) -DANYTUN_NOSYNC $< -c -o anytun-nosync.o
anytun-showtables.o: anytun-showtables.cpp
$(C++) $(CCFLAGS) $< -c
@@ -274,17 +284,17 @@ libAnysync.a: $(OBJS)
ranlib $@
anyrtpproxy: anytun
- @cd anyrtpproxy ; make
+ @cd anyrtpproxy ; $(MAKE)
distclean: cleanall
- make --directory=$(CURDIR)/openvpn distclean
- find -name *.o -exec rm -f {}\;
+ $(MAKE) --directory=$(CURDIR)/openvpn distclean
+ find . -name *.o -exec rm -f {} \;
rm -f config.sub config.guess
cleanall: clean
- make --directory=$(CURDIR)/man clean
- make --directory=$(CURDIR)/Sockets clean
- make --directory=$(CURDIR)/openvpn clean
+ $(MAKE) --directory=$(CURDIR)/man clean
+ $(MAKE) --directory=$(CURDIR)/Sockets clean
+ $(MAKE) --directory=$(CURDIR)/openvpn clean
rm -f Sockets/libSockets.a Sockets/Sockets-config
clean:
@@ -294,10 +304,10 @@ clean:
rm -f -r doc/html/*
rm -f -r doc/latex/*
rm -f libAnysync.a
- make --directory=$(CURDIR)/anyrtpproxy clean
+ $(MAKE) --directory=$(CURDIR)/anyrtpproxy clean
manpage:
- @cd man ; make
+ @cd man ; $(MAKE)
doxygen:
doxygen Doxyfile
diff --git a/src/anytun.cpp b/src/anytun.cpp
index 37e21e6..e8bfb13 100644
--- a/src/anytun.cpp
+++ b/src/anytun.cpp
@@ -35,7 +35,10 @@
#include <pwd.h>
#include <grp.h>
#include <sys/wait.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <pthread.h>
#include <gcrypt.h>
#include <cerrno> // for ENOMEM
@@ -312,16 +315,20 @@ void* receiver(void* p)
}
#define MIN_GCRYPT_VERSION "1.2.0"
+#if defined(__GNUC__) && !defined(__OpenBSD__) // TODO: thread-safety on OpenBSD
// make libgcrypt thread safe
extern "C" {
GCRY_THREAD_OPTION_PTHREAD_IMPL;
}
+#endif
bool initLibGCrypt()
{
// make libgcrypt thread safe
// this must be called before any other libgcrypt call
+#if defined(__GNUC__) && !defined(__OpenBSD__) // TODO: thread-safety on OpenBSD
gcry_control( GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread );
+#endif
// this must be called right after the GCRYCTL_SET_THREAD_CBS command
// no other function must be called till now
@@ -425,7 +432,7 @@ int main(int argc, char* argv[])
gOpt.printUsage();
exit(-1);
}
-
+
cLog.msg(Log::PRIO_NOTICE) << "anytun started...";
std::ofstream pidFile;
@@ -467,7 +474,7 @@ int main(int argc, char* argv[])
src = new UDPPacketSource(gOpt.getLocalPort());
else
src = new UDPPacketSource(gOpt.getLocalAddr(), gOpt.getLocalPort());
-
+
ConnectionList cl;
ConnectToList connect_to = gOpt.getConnectTo();
SyncQueue queue;
@@ -497,6 +504,7 @@ int main(int argc, char* argv[])
pthread_create(& connectThreads.back(), NULL, syncConnector, point);
}
#endif
+
int ret = sig.run();
pthread_cancel(senderThread);
diff --git a/src/networkAddress.cpp b/src/networkAddress.cpp
index cd93576..dce8054 100644
--- a/src/networkAddress.cpp
+++ b/src/networkAddress.cpp
@@ -125,7 +125,13 @@ bool NetworkAddress::operator<(const NetworkAddress &right) const
return (ipv4_address_.s_addr < right.ipv4_address_.s_addr);
} else if (network_address_type_==ipv6) {
for(int i=0;i<4;i++)
+#if defined(__GNUC__) && defined(__linux__)
if (ipv6_address_.s6_addr32[i]<right.ipv6_address_.s6_addr32[i])
+#elif defined(__GNUC__) && defined(__OpenBSD__)
+ if (ipv6_address_.__u6_addr.__u6_addr32[i]<right.ipv6_address_.__u6_addr.__u6_addr32[i])
+#else
+ #error Target not supported
+#endif
return true;
return false;
} else if (network_address_type_==ethernet) {
@@ -148,9 +154,18 @@ NetworkAddress NetworkAddress::operator<<(uint8_t shift) const
in6_addr new_v6_addr;
for(int i=0;i<4;i++)
{
+#if defined(__GNUC__) && defined(__linux__)
new_v6_addr.s6_addr32[i]=ipv6_address_.s6_addr32[i]<<1;
if (i<3 && ipv6_address_.s6_addr32[i+1] || uint32_t (0x80000000))
new_v6_addr.s6_addr32[i] &=1;
+#elif defined(__GNUC__) && defined(__OpenBSD__)
+ new_v6_addr.__u6_addr.__u6_addr32[i]=ipv6_address_.__u6_addr.__u6_addr32[i]<<1;
+ if (i<3 && ipv6_address_.__u6_addr.__u6_addr32[i+1] || uint32_t (0x80000000))
+ new_v6_addr.__u6_addr.__u6_addr32[i] &=1;
+#else
+ #error Target not supported
+#endif
+
}
return NetworkAddress(new_v6_addr);
} else if (network_address_type_==ethernet) {
@@ -173,7 +188,14 @@ NetworkAddress NetworkAddress::operator&(const NetworkAddress &right) const
} else if (network_address_type_==ipv6) {
in6_addr new_v6_addr;
for(int i=0;i<4;i++)
+#if defined(__GNUC__) && defined(__linux__)
new_v6_addr.s6_addr32[i]=ipv6_address_.s6_addr32[i]&right.ipv6_address_.s6_addr32[i];
+#elif defined(__GNUC__) && defined(__OpenBSD__)
+ new_v6_addr.__u6_addr.__u6_addr32[i]=ipv6_address_.__u6_addr.__u6_addr32[i]&right.ipv6_address_.__u6_addr.__u6_addr32[i];
+#else
+ #error Target not supported
+#endif
+
return NetworkAddress(new_v6_addr);
} else if (network_address_type_==ethernet) {
//TODO
@@ -193,7 +215,14 @@ NetworkAddress NetworkAddress::operator&=(const NetworkAddress &right)
return *this;
} else if (network_address_type_==ipv6) {
for(int i=0;i<4;i++)
+#if defined(__GNUC__) && defined(__linux__)
ipv6_address_.s6_addr32[i]&=right.ipv6_address_.s6_addr32[i];
+#elif defined(__GNUC__) && defined(__OpenBSD__)
+ ipv6_address_.__u6_addr.__u6_addr32[i]&=right.ipv6_address_.__u6_addr.__u6_addr32[i];
+#else
+ #error Target not supported
+#endif
+
return *this;
} else if (network_address_type_==ethernet) {
//TODO
diff --git a/src/networkAddress.h b/src/networkAddress.h
index 33cc4b5..7465fc7 100644
--- a/src/networkAddress.h
+++ b/src/networkAddress.h
@@ -84,7 +84,14 @@ private:
ar & ipv4_address_.s_addr;
if (network_address_type_==ipv6)
for(int i=0;i<4;i++)
+#if defined(__GNUC__) && defined(__linux__)
ar & ipv6_address_.s6_addr32;
+#elif defined(__GNUC__) && defined(__OpenBSD__)
+ ar & ipv6_address_.__u6_addr.__u6_addr32;
+#else
+ #error Target not supported
+#endif
+
if (network_address_type_==ethernet)
ar & ethernet_address_;
}
diff --git a/src/networkPrefix.cpp b/src/networkPrefix.cpp
index 4ab8f6d..0d5f6ee 100644
--- a/src/networkPrefix.cpp
+++ b/src/networkPrefix.cpp
@@ -57,7 +57,14 @@ void NetworkPrefix::setNetworkPrefixLength(uint8_t length )
} else if (network_address_type_==ipv6) {
in6_addr v6addr;
for(int i=0;i<4;i++)
+#if defined(__GNUC__) && defined(__linux__)
ipv6_address_.s6_addr32[i]=0xFFFFFFFF;
+#elif defined(__GNUC__) && defined(__OpenBSD__)
+ ipv6_address_.__u6_addr.__u6_addr32[i]=0xFFFFFFFF;
+#else
+ #error Target not supported
+#endif
+
*this &= (NetworkAddress(v6addr)<<(128-length));
} else if (network_address_type_==ethernet) {
//TODO
diff --git a/src/plainPacket.cpp b/src/plainPacket.cpp
index c4717c3..f84aefd 100644
--- a/src/plainPacket.cpp
+++ b/src/plainPacket.cpp
@@ -31,9 +31,14 @@
#include <stdexcept>
#include <iostream>
#include <arpa/inet.h>
-#include <netinet/if_ether.h>
+#include <sys/socket.h>
+#include <netinet/in_systm.h>
+#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/ip6.h>
+#include <net/if.h>
+#include <net/if_arp.h>
+#include <netinet/if_ether.h>
#include "datatypes.h"
#include "plainPacket.h"