From 808834b18b648eecc7e877f470071a98cbdee6b5 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Sat, 23 Jul 2022 17:10:24 +0300 Subject: [PATCH] Add a comparison function for hostapd_ip_addr Signed-off-by: Jouni Malinen --- src/utils/ip_addr.c | 19 +++++++++++++++++++ src/utils/ip_addr.h | 2 ++ 2 files changed, 21 insertions(+) diff --git a/src/utils/ip_addr.c b/src/utils/ip_addr.c index 92a359039..a971f72e2 100644 --- a/src/utils/ip_addr.c +++ b/src/utils/ip_addr.c @@ -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; +} diff --git a/src/utils/ip_addr.h b/src/utils/ip_addr.h index 0670411cc..1d35e0b1e 100644 --- a/src/utils/ip_addr.h +++ b/src/utils/ip_addr.h @@ -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 */