Skip to content

Instantly share code, notes, and snippets.

@miniupnp
Created May 29, 2017 12:23
Show Gist options
  • Save miniupnp/ea587bb82ca933a616e7f9537d4f9d02 to your computer and use it in GitHub Desktop.
Save miniupnp/ea587bb82ca933a616e7f9537d4f9d02 to your computer and use it in GitHub Desktop.
patch for compiling torsocks under OS X 10.5.8
diff --git a/configure.ac b/configure.ac
index 7e442f7..80ad9a4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -55,6 +55,9 @@ AC_CHECK_FUNCS(strcspn strdup strerror strcasecmp strncasecmp mmap munmap \
[AC_MSG_ERROR("Required function not found")]
)
+dnl Check for strndup
+AC_CHECK_FUNC(strndup, AC_DEFINE([HAVE_STRNDUP],[],[Description]), [])
+
##############################################################################
# 3. Determine libraries we need to include when linking libtorsocks.
# OpenBSD and OSX have some special requirements here.
diff --git a/src/common/config-file.c b/src/common/config-file.c
index 2147068..6f87fe3 100644
--- a/src/common/config-file.c
+++ b/src/common/config-file.c
@@ -67,6 +67,9 @@ static int set_onion_info(const char *addr, struct configuration *config)
unsigned long bit_mask;
char *ip = NULL, *mask = NULL;
in_addr_t net;
+#ifndef HAVE_STRNDUP
+ size_t len;
+#endif
assert(addr);
assert(config);
@@ -79,7 +82,13 @@ static int set_onion_info(const char *addr, struct configuration *config)
}
mask = strdup(addr + (ip - addr) + 1);
+#ifdef HAVE_STRNDUP
ip = strndup(addr, ip - addr);
+#else
+ len = ip - addr;
+ ip = calloc(1, len + 1);
+ if (ip) memcpy(ip, addr, len);
+#endif
if (!ip || !mask) {
PERROR("[config] strdup onion addr");
ret = -ENOMEM;
diff --git a/tests/unit/test_socks5.c b/tests/unit/test_socks5.c
index 4ef92f7..69938c1 100644
--- a/tests/unit/test_socks5.c
+++ b/tests/unit/test_socks5.c
@@ -68,7 +68,7 @@ static struct connection *get_connection_domain_stub(void)
conn = connection_create(1, NULL);
conn->dest_addr.domain = CONNECTION_DOMAIN_NAME;
- conn->dest_addr.hostname.addr = strndup(addr_str, strlen(addr_str));
+ conn->dest_addr.hostname.addr = strdup(addr_str);
conn->dest_addr.hostname.port = htons(9050);
return conn;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment