]> git.openfabrics.org - ~ardavis/dapl.git/commitdiff
r7928: Socket CM fix to guard against using a loopback address
authorArlin Davis <ardavis@ichips.intel.com>
Mon, 12 Jun 2006 14:51:14 +0000 (14:51 +0000)
committerJames Lentini <jlentini@netapp.com>
Mon, 12 Jun 2006 14:51:14 +0000 (14:51 +0000)
as the local device address.
Signed-off-by: Arlin Davis <ardavis@ichips.intel.com>
Signed-off-by: James Lentini <jlentini@netapp.com>
dapl/openib_scm/dapl_ib_util.c

index 85d20601c0d257de7b69a08c7d163d460769d1d9..7d581f461e507b188e6a065fc5d2580366995684 100644 (file)
@@ -56,6 +56,8 @@ static const char rcsid[] = "$Id:  $";
 #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>
 
@@ -76,9 +78,27 @@ DAT_RETURN getipaddr( char *addr, int addr_len)
                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;