commit 94421ba8e0cc59003ecdb0317c346d7783723b5e Author: Robert Hogan robert@roberthogan.net Date: Sun Feb 20 19:28:36 2011 +0000
Make tests compile and run on OSX --- configure.in | 17 ++++++++++++++++- test/test_torsocks.c | 15 +++++++++------ 2 files changed, 25 insertions(+), 7 deletions(-)
diff --git a/configure.in b/configure.in index 3366420..69d2efb 100644 --- a/configure.in +++ b/configure.in @@ -521,6 +521,8 @@ LIBS=${SIMPLELIBS} AC_SEARCH_LIBS(dlopen, [dl]) AC_SEARCH_LIBS(res_query, [resolv])
+TESTLDFLAGS="$LDFLAGS" + dnl Linker checks for Mac OSX, which uses DYLD_INSERT_LIBRARIES dnl instead of LD_PRELOAD case "$host_os" in @@ -575,6 +577,16 @@ case $host in *-*-freebsd*) AC_DEFINE(FREEBSD, 1, "Define to handle FreeBSD") ;; +*-*-darwin*) + dnl Needed to compile tests. + dnl See https://bugs.g10code.com/gnupg/issue1292: + dnl "On OS X (at least in 10.6 and I believe starting at 10.3) the DNS resolution + dnl services fail to compile. This is a result of the addition of BIND9 compatible + dnl resolution libraries on OS X that are being picked up by the configure script + dnl instead of -lresolv causing the tests for useable resolution services to fail + dnl thus disabling features like pka auto lookup." + LIBS="-lresolv $LIBS" + ;; esac
AC_SUBST(SHLIB_EXT) @@ -615,5 +627,8 @@ AC_ENABLE_STATIC
AC_CONFIG_FILES([src/usewithtor src/torsocks src/torsocks.conf.5 src/torsocks.8 src/usewithtor.1 src/torsocks.1])
-AC_OUTPUT(Makefile src/Makefile test/Makefile) +AC_OUTPUT(Makefile src/Makefile)
+dnl Dump any LDFLAGS that were only required for linking libtorsocks, such as -dynamiclib on OSX. +LDFLAGS="$TESTLDFLAGS" +AC_OUTPUT(test/Makefile) diff --git a/test/test_torsocks.c b/test/test_torsocks.c index 6e8933b..60d78c8 100644 --- a/test/test_torsocks.c +++ b/test/test_torsocks.c @@ -37,6 +37,9 @@ #include <arpa/inet.h> #endif #include <arpa/nameser.h> +#if defined(__APPLE__) || defined(__darwin__) +#include <arpa/nameser_compat.h> +#endif #include <netinet/ip.h> #include <netinet/ip_icmp.h> #include <pthread.h> @@ -80,7 +83,7 @@ static int icmp_test() char datagram[400]; struct sockaddr_in dest; struct ip *iphdr=(struct ip *) datagram; -#if defined(OPENBSD) || defined(FREEBSD) +#if defined(OPENBSD) || defined(FREEBSD) ||defined(__APPLE__) || defined(__darwin__) struct icmp *icmphdr=(struct icmp *)(iphdr +1); #else struct icmphdr *icmphdr=(struct icmphdr *)(iphdr +1); @@ -112,7 +115,7 @@ static int icmp_test() iphdr->ip_dst.s_addr=dest.sin_addr.s_addr; iphdr->ip_sum=csum((unsigned short *)datagram,iphdr->ip_len >> 1);
-#if defined(OPENBSD) || defined(FREEBSD) +#if defined(OPENBSD) || defined(FREEBSD) ||defined(__APPLE__) || defined(__darwin__) icmphdr->icmp_type=130; icmphdr->icmp_code=0; icmphdr->icmp_cksum=htons(0xc3b0); @@ -264,7 +267,7 @@ static int res_tests(char *ip, char *test) { See: http://sourceware.org/ml/libc-help/2009-11/msg00013.html */ printf("\n---------------------- %s res_query() TEST----------------------\n\n", test); snprintf((char *)host, 127, "www.google.com"); -#ifndef OPENBSD +#if !defined(OPENBSD) && !defined(__APPLE__) && !defined(__darwin__) ret = res_nquery(&_res, (char *) host, C_IN, T_TXT, dnsreply, sizeof( dnsreply )); #else ret = res_query((char *) host, C_IN, T_TXT, dnsreply, sizeof( dnsreply )); @@ -273,7 +276,7 @@ static int res_tests(char *ip, char *test) {
printf("\n---------------------- %s res_search() TEST----------------------\n\n", test); memset( dnsreply, '\0', sizeof( dnsreply )); -#ifndef OPENBSD +#if !defined(OPENBSD) && !defined(__APPLE__) && !defined(__darwin__) ret = res_nsearch(&_res, (char *) host, C_IN, T_TXT, dnsreply, sizeof( dnsreply )); #else ret = res_search((char *) host, C_IN, T_TXT, dnsreply, sizeof( dnsreply )); @@ -282,7 +285,7 @@ static int res_tests(char *ip, char *test) {
printf("\n--------------- %s res_querydomain() TEST----------------------\n\n", test); memset( dnsreply, '\0', sizeof( dnsreply )); -#ifndef OPENBSD +#if !defined(OPENBSD) && !defined(__APPLE__) && !defined(__darwin__) ret = res_nquerydomain(&_res, "www.google.com", "google.com", C_IN, T_TXT, dnsreply, sizeof( dnsreply )); #else ret = res_querydomain("www.google.com", "google.com", C_IN, T_TXT, dnsreply, sizeof( dnsreply )); @@ -291,7 +294,7 @@ static int res_tests(char *ip, char *test) {
printf("\n---------------------- %s res_send() TEST----------------------\n\n", test); memset( dnsreply, '\0', sizeof( dnsreply )); -#ifndef OPENBSD +#if !defined(OPENBSD) && !defined(__APPLE__) && !defined(__darwin__) ret = res_nsend(&_res, host, 32, dnsreply, sizeof( dnsreply )); #else ret = res_send(host, 32, dnsreply, sizeof( dnsreply ));