]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
Add a comparison function for hostapd_ip_addr
authorJouni Malinen <quic_jouni@quicinc.com>
Sat, 23 Jul 2022 14:10:24 +0000 (17:10 +0300)
committerJouni Malinen <j@w1.fi>
Sun, 24 Jul 2022 21:23:31 +0000 (00:23 +0300)
Signed-off-by: Jouni Malinen <quic_jouni@quicinc.com>
src/utils/ip_addr.c
src/utils/ip_addr.h

index 92a3590390331c8ef16b9df75e97f764e73874fa..a971f72e26afb52e111e04ae21b36f567752dcb8 100644 (file)
@@ -51,3 +51,22 @@ int hostapd_parse_ip_addr(const char *txt, struct hostapd_ip_addr *addr)
 
        return -1;
 }
+
+
+bool hostapd_ip_equal(const struct hostapd_ip_addr *a,
+                     const struct hostapd_ip_addr *b)
+{
+       if (a->af != b->af)
+               return false;
+
+       if (a->af == AF_INET && a->u.v4.s_addr == b->u.v4.s_addr)
+               return true;
+
+#ifdef CONFIG_IPV6
+       if (a->af == AF_INET6 &&
+           os_memcmp(&a->u.v6, &b->u.v6, sizeof(a->u.v6)) == 0)
+               return true;
+#endif /* CONFIG_IPV6 */
+
+       return false;
+}
index 0670411ccde43fb7e3de9ac15d89cdd5f3f9b73d..1d35e0b1e90798f39732708046bdd67c692daf0e 100644 (file)
@@ -23,5 +23,7 @@ struct hostapd_ip_addr {
 const char * hostapd_ip_txt(const struct hostapd_ip_addr *addr, char *buf,
                            size_t buflen);
 int hostapd_parse_ip_addr(const char *txt, struct hostapd_ip_addr *addr);
+bool hostapd_ip_equal(const struct hostapd_ip_addr *a,
+                     const struct hostapd_ip_addr *b);
 
 #endif /* IP_ADDR_H */