From 44a97ff1f599f4bf882a801ead7aa495ea9ba936 Mon Sep 17 00:00:00 2001 From: Arlin Davis Date: Mon, 12 Jun 2006 14:51:14 +0000 Subject: [PATCH] r7928: Socket CM fix to guard against using a loopback address as the local device address. Signed-off-by: Arlin Davis Signed-off-by: James Lentini --- dapl/openib_scm/dapl_ib_util.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/dapl/openib_scm/dapl_ib_util.c b/dapl/openib_scm/dapl_ib_util.c index 85d2060..7d581f4 100644 --- a/dapl/openib_scm/dapl_ib_util.c +++ b/dapl/openib_scm/dapl_ib_util.c @@ -56,6 +56,8 @@ static const char rcsid[] = "$Id: $"; #include #include #include +#include +#include #include #include @@ -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; -- 2.46.0