From 233af1137359804dfc26daccc07ba2813f1a3b28 Mon Sep 17 00:00:00 2001 From: Chris Fitch Date: Mon, 29 Jul 2024 09:00:18 -0400 Subject: [PATCH 1/2] sa: add utility function to check if address is multicast --- include/re_sa.h | 1 + src/sa/sa.c | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/include/re_sa.h b/include/re_sa.h index 9670bfbcd..1d26a0e5f 100644 --- a/include/re_sa.h +++ b/include/re_sa.h @@ -68,6 +68,7 @@ bool sa_cmp(const struct sa *l, const struct sa *r, int flag); bool sa_is_linklocal(const struct sa *sa); bool sa_is_loopback(const struct sa *sa); +bool sa_is_multicast(const struct sa *sa); bool sa_is_any(const struct sa *sa); void sa_set_scopeid(struct sa *sa, uint32_t scopeid); diff --git a/src/sa/sa.c b/src/sa/sa.c index 4b5c6410f..71203584a 100644 --- a/src/sa/sa.c +++ b/src/sa/sa.c @@ -695,6 +695,32 @@ bool sa_is_loopback(const struct sa *sa) } } +/** + * Check if socket address is a multicast address + * + * @param sa Socket address + * + * @return true if multicast address, otherwise false + */ +bool sa_is_multicast(const struct sa *sa) +{ + if (!sa) + return false; + + switch (sa_af(sa)) { + + case AF_INET: + return IN_MULTICAST(ntohl(sa->u.in.sin_addr.s_addr)); + +#ifdef HAVE_INET6 + case AF_INET6: + return IN6_IS_ADDR_MULTICAST(&sa->u.in6.sin6_addr); +#endif + + default: + return false; + } +} /** * Check if socket address is any/unspecified address From 5c10bb205780afeb397c392f0b17d734ef111e1a Mon Sep 17 00:00:00 2001 From: Chris Fitch Date: Mon, 29 Jul 2024 09:35:24 -0400 Subject: [PATCH 2/2] Remove HAVE_INET6 ifdef --- src/sa/sa.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/sa/sa.c b/src/sa/sa.c index 5d0ad198c..8f6abb7f8 100644 --- a/src/sa/sa.c +++ b/src/sa/sa.c @@ -683,10 +683,8 @@ bool sa_is_multicast(const struct sa *sa) case AF_INET: return IN_MULTICAST(ntohl(sa->u.in.sin_addr.s_addr)); -#ifdef HAVE_INET6 case AF_INET6: return IN6_IS_ADDR_MULTICAST(&sa->u.in6.sin6_addr); -#endif default: return false;