#include <stdlib.h>
#include <netinet/tcp.h>
#include <sys/utsname.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
#include <unistd.h>
#include <fcntl.h>
return DAT_INTERNAL_ERROR;
if ( h_ptr->h_addrtype == AF_INET ) {
- ipv4_addr = (struct sockaddr_in*) addr;
+ int i;
+ struct in_addr **alist =
+ (struct in_addr **)h_ptr->h_addr_list;
+
+ *(uint32_t*)&ipv4_addr->sin_addr = 0;
ipv4_addr->sin_family = AF_INET;
- dapl_os_memcpy( &ipv4_addr->sin_addr, h_ptr->h_addr_list[0], 4 );
+
+ /* Walk the list of addresses for host */
+ for (i=0; alist[i] != NULL; i++) {
+
+ /* first non-loopback address */
+ if ( *(uint32_t*)alist[i] != htonl(0x7f000001) ) {
+ dapl_os_memcpy( &ipv4_addr->sin_addr,
+ h_ptr->h_addr_list[i],
+ 4 );
+ break;
+ }
+ }
+ /* if no acceptable address found */
+ if (*(uint32_t*)&ipv4_addr->sin_addr == 0)
+ return DAT_INVALID_ADDRESS;
} else
return DAT_INVALID_ADDRESS;