commit 8dd3fbc015eb671651dcb829a6761d9e0758bcf1 Author: George Kadianakis desnacked@gmail.com Date: Mon Jun 20 03:41:13 2011 +0200
obfsproxy now compiles and runs on the Microsoft Windows computing platform. --- Makefile.am | 4 ++-- configure.ac | 9 +++++++++ src/main.c | 14 ++++++++++++++ src/network.c | 4 ++++ src/socks.c | 40 +++++++++++++++++++++++++++++++++++++++- src/socks.h | 4 ++++ src/test/tinytest.c | 8 ++++---- src/util.c | 4 ++++ 8 files changed, 80 insertions(+), 7 deletions(-)
diff --git a/Makefile.am b/Makefile.am index bd3a2b2..614748f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -18,7 +18,7 @@ libobfsproxy_a_SOURCES = \
obfsproxy_SOURCES = \ src/main.c -obfsproxy_LDADD = @libevent_LIBS@ @openssl_LIBS@ libobfsproxy.a +obfsproxy_LDADD = libobfsproxy.a @libevent_LIBS@ @openssl_LIBS@ @LIB_WS32@
unittests_SOURCES = \ src/test/tinytest.c \ @@ -26,7 +26,7 @@ unittests_SOURCES = \ src/test/unittest_obfs2.c \ src/test/unittest_crypt.c \ src/test/unittest_socks.c -unittests_LDADD = @libevent_LIBS@ @openssl_LIBS@ libobfsproxy.a +unittests_LDADD = libobfsproxy.a @libevent_LIBS@ @openssl_LIBS@ @LIB_WS32@
noinst_HEADERS = \ src/network.h \ diff --git a/configure.ac b/configure.ac index da838db..c799d61 100644 --- a/configure.ac +++ b/configure.ac @@ -17,6 +17,15 @@ PKG_CHECK_MODULES([openssl], [openssl >= 0.9.7]) # We don't need -lssl, only -lcrypto openssl_LIBS=`echo "$openssl_LIBS" | $SED -e 's/-lssl//'`
+AC_CHECK_HEADERS([winsock2.h], HAVE_WINSOCK2_H=yes) +AM_CONDITIONAL(HAVE_WINSOCK2_H, test "x$HAVE_WINSOCK2_H" = "xyes") +if test "x$HAVE_WINSOCK2_H" = "xyes"; then + LIB_WS32=-lws2_32 +else + LIB_WS32= +fi +AC_SUBST(LIB_WS32) + AC_CHECK_SIZEOF(size_t)
AC_CONFIG_FILES([Makefile]) diff --git a/src/main.c b/src/main.c index 5ca365f..e469b7b 100644 --- a/src/main.c +++ b/src/main.c @@ -13,6 +13,10 @@ #include "util.h" #include "protocol.h"
+#ifdef _WIN32 +#include <Ws2tcpip.h> +#endif + #ifndef __GNUC__ #define __attribute__(x) #endif @@ -278,6 +282,13 @@ main(int argc, const char **argv) /* Excellent. Now we should have protocol_options populated with all the protocol options we got from the user. */
+ /* Ugly method to fix a Windows problem: + http://archives.seul.org/libevent/users/Oct-2010/msg00049.html */ +#ifdef _WIN32 + WSADATA wsaData; + WSAStartup(0x101, &wsaData); +#endif + /* Initialize libevent */ base = event_base_new(); if (!base) { @@ -292,6 +303,9 @@ main(int argc, const char **argv) }
/* Handle signals */ +#ifdef SIGPIPE + signal(SIGPIPE, SIG_IGN); +#endif signal(SIGPIPE, SIG_IGN); sigevent = evsignal_new(base, SIGINT, handle_signal_cb, (void*) base); diff --git a/src/network.c b/src/network.c index e3c2fa0..ed78104 100644 --- a/src/network.c +++ b/src/network.c @@ -16,6 +16,10 @@ #include <errno.h> #include <event2/util.h>
+#ifdef _WIN32 +#include <WS2tcpip.h> +#endif + struct listener_t { struct evconnlistener *listener; protocol_params_t *proto_params; diff --git a/src/socks.c b/src/socks.c index 7cf179b..13d5375 100644 --- a/src/socks.c +++ b/src/socks.c @@ -3,8 +3,14 @@ */
#include <sys/types.h> -#include <sys/socket.h> +#ifdef _WIN32 +#include <Winsock2.h> +#else #include <arpa/inet.h> +#include <sys/socket.h> +#endif + + #include <assert.h>
#include <string.h> @@ -48,6 +54,38 @@ static enum socks_ret socks5_do_negotiation(struct evbuffer *dest,
typedef unsigned char uchar;
+/* + Necessary definitions for platforms that don't support + sockaddr_in6 and u_int16_t +*/ +#ifdef _WIN32 +typedef uint16_t sa_family_t; + +struct in6_addr +{ + union { + uint8_t u6_addr8[16]; + uint16_t u6_addr16[8]; + uint32_t u6_addr32[4]; + } in6_u; +#define s6_addr in6_u.u6_addr8 +#define s6_addr16 in6_u.u6_addr16 +#define s6_addr32 in6_u.u6_addr32 +}; + +/* Define struct sockaddr_in6 on platforms that do not have it. See notes + * on struct in6_addr. */ +struct sockaddr_in6 { + sa_family_t sin6_family; + uint16_t sin6_port; + // uint32_t sin6_flowinfo; + struct in6_addr sin6_addr; + // uint32_t sin6_scope_id; +}; + +typedef unsigned short u_int16_t; +#endif + socks_state_t * socks_state_new(void) { diff --git a/src/socks.h b/src/socks.h index caa7ec0..2f1e44b 100644 --- a/src/socks.h +++ b/src/socks.h @@ -5,7 +5,11 @@ #ifndef SOCKS_H #define SOCKS_H
+#ifdef _WIN32 +#include <Winsock2.h> +#else #include <netdb.h> +#endif
typedef struct socks_state_t socks_state_t; struct evbuffer; diff --git a/src/test/tinytest.c b/src/test/tinytest.c index ab43694..32410fd 100644 --- a/src/test/tinytest.c +++ b/src/test/tinytest.c @@ -28,7 +28,7 @@ #include <string.h> #include <assert.h>
-#ifdef WIN32 +#ifdef _WIN32 #include <windows.h> #else #include <sys/types.h> @@ -61,7 +61,7 @@ const char *cur_test_prefix = NULL; /**< prefix of the current test group */ /** Name of the current test, if we haven't logged is yet. Used for --quiet */ const char *cur_test_name = NULL;
-#ifdef WIN32 +#ifdef _WIN32 /** Pointer to argv[0] for win32. */ static const char *commandname = NULL; #endif @@ -100,7 +100,7 @@ static enum outcome _testcase_run_forked(const struct testgroup_t *group, const struct testcase_t *testcase) { -#ifdef WIN32 +#ifdef _WIN32 /* Fork? On Win32? How primitive! We'll do what the smart kids do: we'll invoke our own exe (whose name we recall from the command line) with a command line that tells it to run just the test we @@ -283,7 +283,7 @@ tinytest_main(int c, const char **v, struct testgroup_t *groups) { int i, j, n=0;
-#ifdef WIN32 +#ifdef _WIN32 commandname = v[0]; #endif for (i=1; i<c; ++i) { diff --git a/src/util.c b/src/util.c index d4eddb6..7e3e747 100644 --- a/src/util.c +++ b/src/util.c @@ -14,6 +14,10 @@
#include "util.h"
+#ifdef _WIN32 +#include <Ws2tcpip.h> +#endif + #include <event2/util.h> #include <event2/dns.h>
tor-commits@lists.torproject.org