+/**
+ * Compare the address part of IPv4/6 addresses.
+ *
+ * \param sa1 First address.
+ * \param sa2 Second address.
+ *
+ * \return True iff the IP address of \a sa1 and \a sa2 match.
+ */
+bool sockaddr_equal(const struct sockaddr *sa1, const struct sockaddr *sa2)
+{
+ if (!sa1 || !sa2)
+ return false;
+ if (sa1->sa_family != sa2->sa_family)
+ return false;
+ if (sa1->sa_family == AF_INET) {
+ struct sockaddr_in *a1 = (typeof(a1))sa1,
+ *a2 = (typeof (a2))sa2;
+ return a1->sin_addr.s_addr == a2->sin_addr.s_addr;
+ } else if (sa1->sa_family == AF_INET6) {
+ struct sockaddr_in6 *a1 = (typeof(a1))sa1,
+ *a2 = (typeof (a2))sa2;
+ return !memcmp(a1, a2, sizeof(*a1));
+ } else
+ return false;
+}
+