[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [torsocks/master] Implement gethostbyname2() GNU extension call



commit c9beeafef8afaae18e25ac13bea616d4f7513992
Author: David Goulet <dgoulet@xxxxxxxxx>
Date:   Sun Jun 23 21:04:31 2013 -0400

    Implement gethostbyname2() GNU extension call
    
    Signed-off-by: David Goulet <dgoulet@xxxxxxxxx>
---
 src/lib/gethostbyname.c |   29 +++++++++++++++++++++++++++++
 src/lib/torsocks.h      |   13 +++++++++++++
 2 files changed, 42 insertions(+)

diff --git a/src/lib/gethostbyname.c b/src/lib/gethostbyname.c
index 58a7290..d9afec9 100644
--- a/src/lib/gethostbyname.c
+++ b/src/lib/gethostbyname.c
@@ -19,6 +19,7 @@
 
 #include <arpa/inet.h>
 #include <assert.h>
+#include <stdlib.h>
 
 #include <common/log.h>
 
@@ -84,3 +85,31 @@ LIBC_GETHOSTBYNAME_DECL
 {
 	return tsocks_gethostbyname(LIBC_GETHOSTBYNAME_ARGS);
 }
+
+/*
+ * Torsocks call for gethostbyname2(3).
+ *
+ * This call, like gethostbyname(), returns pointer to static data thus is
+ * absolutely not reentrant.
+ */
+LIBC_GETHOSTBYNAME2_RET_TYPE tsocks_gethostbyname2(LIBC_GETHOSTBYNAME2_SIG)
+{
+	/*
+	 * For now, there is no way of resolving a domain name to IPv6 through Tor
+	 * so only accept INET request thus using the original gethostbyname().
+	 */
+	if (__af != AF_INET) {
+		h_errno = HOST_NOT_FOUND;
+		return NULL;
+	}
+
+	return tsocks_gethostbyname(__name);
+}
+
+/*
+ * Libc hijacked symbol gethostbyname2(3).
+ */
+LIBC_GETHOSTBYNAME2_DECL
+{
+	return tsocks_gethostbyname2(LIBC_GETHOSTBYNAME2_ARGS);
+}
diff --git a/src/lib/torsocks.h b/src/lib/torsocks.h
index de62c33..0121716 100644
--- a/src/lib/torsocks.h
+++ b/src/lib/torsocks.h
@@ -64,6 +64,13 @@ char tsocks_he_addr[INET_ADDRSTRLEN];
 #define LIBC_GETHOSTBYNAME_SIG const char *__name
 #define LIBC_GETHOSTBYNAME_ARGS __name
 
+/* gethostbyname2(3) - GNU extension to avoid static data. */
+#define LIBC_GETHOSTBYNAME2_NAME gethostbyname2
+#define LIBC_GETHOSTBYNAME2_NAME_STR XSTR(LIBC_GETHOSTBYNAME2_NAME)
+#define LIBC_GETHOSTBYNAME2_RET_TYPE struct hostent *
+#define LIBC_GETHOSTBYNAME2_SIG const char *__name, int __af
+#define LIBC_GETHOSTBYNAME2_ARGS __name, __af
+
 /* getaddrinfo(3) */
 #include <netdb.h>
 
@@ -95,6 +102,12 @@ TSOCKS_LIBC_DECL(gethostbyname, LIBC_GETHOSTBYNAME_RET_TYPE,
 #define LIBC_GETHOSTBYNAME_DECL LIBC_GETHOSTBYNAME_RET_TYPE \
 		LIBC_GETHOSTBYNAME_NAME(LIBC_GETHOSTBYNAME_SIG)
 
+/* gethostbyname2(3) */
+TSOCKS_LIBC_DECL(gethostbyname2, LIBC_GETHOSTBYNAME2_RET_TYPE,
+		LIBC_GETHOSTBYNAME2_SIG)
+#define LIBC_GETHOSTBYNAME2_DECL LIBC_GETHOSTBYNAME2_RET_TYPE \
+		LIBC_GETHOSTBYNAME2_NAME(LIBC_GETHOSTBYNAME2_SIG)
+
 /* getaddrinfo(3) */
 TSOCKS_LIBC_DECL(getaddrinfo, LIBC_GETADDRINFO_RET_TYPE,
 		LIBC_GETADDRINFO_SIG)



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits