about summary refs log tree commit diff
path: root/src/nm-core-utils.c
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2016-04-12 17:33:05 +0200
committerMichael Biebl <biebl@debian.org>2016-04-12 17:33:05 +0200
commit288a08a3672a89a9bfdb8354b6863cc039759fc2 (patch)
tree351ac159de25507ba7eeab003153dabb1c6652a2 /src/nm-core-utils.c
parent2bfb3eb7d0323e69affca154395f51d8b577414d (diff)
Imported Upstream version 1.1.94 upstream/1.1.94
Diffstat (limited to 'src/nm-core-utils.c')
-rw-r--r--src/nm-core-utils.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/nm-core-utils.c b/src/nm-core-utils.c
index 6cdd00e0..714aaa92 100644
--- a/src/nm-core-utils.c
+++ b/src/nm-core-utils.c
@@ -233,7 +233,6 @@ nm_ethernet_address_is_valid (gconstpointer addr, gssize len)
 	return TRUE;
 }
 
-
 /* nm_utils_ip4_address_clear_host_address:
  * @addr: source ip6 address
  * @plen: prefix length of network
@@ -279,6 +278,32 @@ nm_utils_ip6_address_clear_host_address (struct in6_addr *dst, const struct in6_
 	return dst;
 }
 
+gboolean
+nm_utils_ip6_address_same_prefix (const struct in6_addr *addr_a, const struct in6_addr *addr_b, guint8 plen)
+{
+	int nbytes;
+	guint8 t, m;
+
+	if (plen >= 128)
+		return memcmp (addr_a, addr_b, sizeof (struct in6_addr)) == 0;
+
+	nbytes = plen / 8;
+	if (nbytes) {
+		if (memcmp (addr_a, addr_b, nbytes) != 0)
+			return FALSE;
+	}
+
+	plen = plen % 8;
+	if (plen == 0)
+		return TRUE;
+
+	m = ~((1 << (8 - plen)) - 1);
+	t = ((((const guint8 *) addr_a))[nbytes]) ^ ((((const guint8 *) addr_b))[nbytes]);
+	return (t & m) == 0;
+}
+
+/*****************************************************************************/
+
 void
 nm_utils_array_remove_at_indexes (GArray *array, const guint *indexes_to_delete, gsize len)
 {