Browse Source

patch from Jari Korva <jpkorva@iki.fi>:

- 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!
Eric Andersen 22 years ago
parent
commit
41b035e634
2 changed files with 12 additions and 7 deletions
  1. 1 1
      libc/inet/Makefile
  2. 11 6
      libc/inet/resolv.c

+ 1 - 1
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 \

+ 11 - 6
libc/inet/resolv.c

@@ -59,6 +59,8 @@
 #include <netdb.h>
 #include <ctype.h>
 #include <arpa/nameser.h>
+#include <sys/utsname.h>
+#include <sys/un.h>
 
 #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] = &in;
 
-		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.  */