Add a comparison function for hostapd_ip_addr

Signed-off-by: Jouni Malinen <quic_jouni@quicinc.com>
This commit is contained in:
Jouni Malinen 2022-07-23 17:10:24 +03:00 committed by Jouni Malinen
parent f7763880bd
commit 808834b18b
2 changed files with 21 additions and 0 deletions

View 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;
}

View 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 */