Skip to content

Commit

Permalink
sa: add utility function to check if address is multicast (#1168)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmfitch1 authored Jul 30, 2024
1 parent 80baf46 commit 460b5ae
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
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
24 changes: 24 additions & 0 deletions src/sa/sa.c
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,30 @@ 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));

case AF_INET6:
return IN6_IS_ADDR_MULTICAST(&sa->u.in6.sin6_addr);

default:
return false;
}
}

/**
* Check if socket address is any/unspecified address
Expand Down

0 comments on commit 460b5ae

Please sign in to comment.