From 1ec13d530c18b9e981d651ea516486107dbeaf33 Mon Sep 17 00:00:00 2001 From: Ralph Castain <rhc@open-mpi.org> Date: Tue, 14 May 2013 22:08:39 +0000 Subject: [PATCH] Allow simple way to request comparison to full address regardless of addr family This commit was SVN r28519. --- opal/util/net.c | 16 ++++++++++++++-- opal/util/net.h | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/opal/util/net.c b/opal/util/net.c index ee97a91925..2917f47198 100644 --- a/opal/util/net.c +++ b/opal/util/net.c @@ -255,8 +255,10 @@ opal_net_islocalhost(const struct sockaddr *addr) bool opal_net_samenetwork(const struct sockaddr *addr1, const struct sockaddr *addr2, - uint32_t prefixlen) + uint32_t plen) { + uint32_t prefixlen; + if(addr1->sa_family != addr2->sa_family) { return false; /* address families must be equal */ } @@ -264,6 +266,11 @@ opal_net_samenetwork(const struct sockaddr *addr1, switch (addr1->sa_family) { case AF_INET: { + if (0 == plen) { + prefixlen = 32; + } else { + prefixlen = plen; + } const struct sockaddr_in *inaddr1 = (struct sockaddr_in*) addr1; const struct sockaddr_in *inaddr2 = (struct sockaddr_in*) addr2; uint32_t netmask = opal_net_prefix2netmask (prefixlen); @@ -283,7 +290,12 @@ opal_net_samenetwork(const struct sockaddr *addr1, struct in6_addr *a6_1 = (struct in6_addr*) &inaddr1->sin6_addr; struct in6_addr *a6_2 = (struct in6_addr*) &inaddr2->sin6_addr; - if (64 == prefixlen) { + if (0 == plen) { + prefixlen = 64; + } else { + prefixlen = plen; + } + if (64 == prefixlen) { /* prefixlen is always /64, any other case would be routing. Compare the first eight bytes (64 bits) and hope that endianess is not an issue on any system as long as diff --git a/opal/util/net.h b/opal/util/net.h index 2355cdf2bb..a1680003c1 100644 --- a/opal/util/net.h +++ b/opal/util/net.h @@ -94,7 +94,7 @@ OPAL_DECLSPEC bool opal_net_islocalhost(const struct sockaddr *addr); * * @param addr1 struct sockaddr of address * @param addr2 struct sockaddr of address - * @param prefixlen netmask (either CIDR oder IPv6 prefixlen) + * @param prefixlen netmask (either CIDR or IPv6 prefixlen) * @return true if \c addr1 and \c addr2 are on the * same net, false otherwise. */