Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sa: add utility function to check if address is multicast #1168

Merged
merged 3 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/re_sa.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
26 changes: 26 additions & 0 deletions src/sa/sa.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
sreimers marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down