[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [torsocks/master] Fix: gethostbyname IP address byte order
commit c623b9899b133ac9ee24988445c0767902511caa
Author: David Goulet <dgoulet@xxxxxxxxx>
Date: Fri Aug 23 11:48:26 2013 -0400
Fix: gethostbyname IP address byte order
The gethostbyname() call was not returning the IP address in network
byte order as stated in the man page.
Reported-by: Micah Anderson <micah@xxxxxxxxxx>
Signed-off-by: David Goulet <dgoulet@xxxxxxxxx>
---
src/lib/gethostbyname.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/src/lib/gethostbyname.c b/src/lib/gethostbyname.c
index 3e3588e..bab01b0 100644
--- a/src/lib/gethostbyname.c
+++ b/src/lib/gethostbyname.c
@@ -34,7 +34,6 @@ LIBC_GETHOSTBYNAME_RET_TYPE tsocks_gethostbyname(LIBC_GETHOSTBYNAME_SIG)
{
int ret;
uint32_t ip;
- const char *ret_str;
DBG("[gethostbyname] Requesting %s hostname", __name);
@@ -54,12 +53,8 @@ LIBC_GETHOSTBYNAME_RET_TYPE tsocks_gethostbyname(LIBC_GETHOSTBYNAME_SIG)
memset(tsocks_he_addr_list, 0, sizeof(tsocks_he_addr_list));
memset(tsocks_he_addr, 0, sizeof(tsocks_he_addr));
- ret_str = inet_ntop(AF_INET, &ip, tsocks_he_addr, sizeof(tsocks_he_addr));
- if (!ret_str) {
- PERROR("inet_ntop");
- h_errno = NO_ADDRESS;
- goto error;
- }
+ /* Copy resolved network byte order IP address. */
+ memcpy(tsocks_he_addr, &ip, sizeof(tsocks_he_addr));
tsocks_he_addr_list[0] = tsocks_he_addr;
tsocks_he_addr_list[1] = NULL;
@@ -70,7 +65,8 @@ LIBC_GETHOSTBYNAME_RET_TYPE tsocks_gethostbyname(LIBC_GETHOSTBYNAME_SIG)
tsocks_he.h_addrtype = AF_INET;
tsocks_he.h_addr_list = tsocks_he_addr_list;
- DBG("Hostname %s resolved to %s", __name, tsocks_he_addr);
+ DBG("Hostname %s resolved to %s", __name,
+ inet_ntoa(*((struct in_addr *) &ip)));
errno = 0;
return &tsocks_he;
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits