From 41b035e634135310bca3381877120981d7b248a4 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Fri, 7 Dec 2001 18:19:09 +0000 Subject: patch from Jari Korva : - fixes endianness bug in gethostbyaddr() (i386 worked fine, while m68k didn't: 192.168.160.162 was queried with 192.168.160.162.in-addr.arpa while it should have been 162.160.168.192.ip-addr.arpa) - contains missing pieces from my previous getnameinfo() patch: now it actually compiles! --- libc/inet/Makefile | 2 +- libc/inet/resolv.c | 17 +++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) (limited to 'libc/inet') diff --git a/libc/inet/Makefile b/libc/inet/Makefile index 6fd75010d..62ae92847 100644 --- a/libc/inet/Makefile +++ b/libc/inet/Makefile @@ -40,7 +40,7 @@ MOBJ2=encodeh.o decodeh.o encoded.o decoded.o lengthd.o encodeq.o \ opennameservers.o closenameservers.o resolvename.o gethostbyname.o\ res_init.o res_query.o gethostbyaddr.o \ get_hosts_byname.o get_hosts_byaddr.o read_etc_hosts.o \ - gethostbyname2.o + gethostbyname2.o getnameinfo.o MSRC3=socketcalls.c MOBJ3= accept.o bind.o connect.o getpeername.o getsockname.o getsockopt.o \ diff --git a/libc/inet/resolv.c b/libc/inet/resolv.c index 710b35937..69fa1c148 100644 --- a/libc/inet/resolv.c +++ b/libc/inet/resolv.c @@ -59,6 +59,8 @@ #include #include #include +#include +#include #define MAX_RECURSE 5 #define REPLY_TIMEOUT 10 @@ -1238,15 +1240,14 @@ struct hostent *gethostbyaddr (const void *addr, socklen_t len, int type) memset(&h, 0, sizeof(h)); if(type == AF_INET) { + unsigned char *tmp_addr = (unsigned char *)addr; + memcpy(&in.s_addr, addr, len); addr_list[0] = ∈ - sprintf(namebuf, "%d.%d.%d.%d.in-addr.arpa", - (in.s_addr >> 24) & 0xff, - (in.s_addr >> 16) & 0xff, - (in.s_addr >> 8) & 0xff, - (in.s_addr >> 0) & 0xff); + sprintf(namebuf, "%u.%u.%u.%u.in-addr.arpa", + tmp_addr[3], tmp_addr[2], tmp_addr[1], tmp_addr[0]); #ifdef __UCLIBC_HAS_IPV6__ } else { memcpy(&in6.s6_addr, addr, len); @@ -1436,6 +1437,10 @@ struct hostent * get_hosts_byaddr(const char * addr, int len, int type) #ifdef L_getnameinfo +#ifndef min +# define min(x,y) (((x) > (y)) ? (y) : (x)) +#endif /* min */ + int getnameinfo (const struct sockaddr *sa, socklen_t addrlen, char *host, socklen_t hostlen, char *serv, socklen_t servlen, unsigned int flags) @@ -1510,7 +1515,6 @@ int getnameinfo (const struct sockaddr *sa, socklen_t addrlen, char *host, #ifdef __UCLIBC_HAS_IPV6__ if (sa->sa_family == AF_INET6) { const struct sockaddr_in6 *sin6p; - uint32_t scopeid; sin6p = (const struct sockaddr_in6 *) sa; @@ -1518,6 +1522,7 @@ int getnameinfo (const struct sockaddr *sa, socklen_t addrlen, char *host, (const void *) &sin6p->sin6_addr, host, hostlen); #if 0 /* Does scope id need to be supported? */ + uint32_t scopeid; scopeid = sin6p->sin6_scope_id; if (scopeid != 0) { /* Buffer is >= IFNAMSIZ+1. */ -- cgit v1.2.3