[tor-commits] [torsocks/master] Fix: change TSOCKS_LOOPBACK bitness

dgoulet at torproject.org dgoulet at torproject.org
Fri Apr 4 22:40:28 UTC 2014


commit 8cedb97d013a4d78e81685c45339479e68354db5
Author: Lunar <lunar at torproject.org>
Date:   Mon Mar 24 19:31:50 2014 -0400

    Fix: change TSOCKS_LOOPBACK bitness
    
    This changes the loopback constant to be in host byte order and use
    htonl() when needed in network byte order.
    
    With this, tests pass on powerpc.
    
    Signed-off-by: David Goulet <dgoulet at ev0ke.net>
---
 src/common/compat.h     |    4 ++--
 src/common/utils.c      |    2 +-
 tests/unit/test_utils.c |    4 ++--
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/common/compat.h b/src/common/compat.h
index e977b41..2058a23 100644
--- a/src/common/compat.h
+++ b/src/common/compat.h
@@ -101,8 +101,8 @@ void tsocks_mutex_unlock(tsocks_mutex_t *m);
 #define TSOCKS_CLASSA_NET   0xff000000
 #define TSOCKS_LOOPBACK_NET 0x7f000000
 
-/* Loopback address in network byte order. */
-#define TSOCKS_LOOPBACK     0x0100007f
+/* Loopback addresses. */
+#define TSOCKS_LOOPBACK     0x7f000001
 #define TSOCKS_LOOPBACK6    { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 }
 #define TSOCKS_ANY          ((unsigned long int) 0x00000000)
 #define TSOCKS_ANY6         { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
diff --git a/src/common/utils.c b/src/common/utils.c
index 890bbde..377dcae 100644
--- a/src/common/utils.c
+++ b/src/common/utils.c
@@ -277,7 +277,7 @@ int utils_localhost_resolve(const char *name, int af, void *buf, size_t len)
 	assert(buf);
 
 	if (af == AF_INET) {
-		const in_addr_t addr = TSOCKS_LOOPBACK;
+		const in_addr_t addr = htonl(TSOCKS_LOOPBACK);
 
 		entry = match_name(name, localhost_names_v4);
 		if (entry) {
diff --git a/tests/unit/test_utils.c b/tests/unit/test_utils.c
index a115db1..dc5b0ca 100644
--- a/tests/unit/test_utils.c
+++ b/tests/unit/test_utils.c
@@ -64,7 +64,7 @@ static void test_is_address_ipv6(void)
 static void test_localhost_resolve(void)
 {
 	int ret = 0;
-	in_addr_t ipv4, loopback = TSOCKS_LOOPBACK;
+	in_addr_t ipv4, loopback = htonl(TSOCKS_LOOPBACK);
 	struct in6_addr ipv6;
 	const uint8_t loopback6[] = TSOCKS_LOOPBACK6;
 
@@ -117,7 +117,7 @@ static void test_sockaddr_is_localhost(void)
 	diag("Utils sockaddr is localhost");
 
 	sin.sin_family = AF_INET;
-	sin.sin_addr.s_addr = TSOCKS_LOOPBACK;
+	sin.sin_addr.s_addr = htonl(TSOCKS_LOOPBACK);
 	ret = utils_sockaddr_is_localhost((const struct sockaddr *) &sin);
 	ok(ret == 1, "Loopback matches localhost");
 





More information about the tor-commits mailing list