net: Add util to check if IPv4 address is part of a subnet
Change-Id: I6005861a4c4085b6c17ded03fda38a567a4e504a Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
parent
79fa53e17d
commit
702ea43621
3 changed files with 47 additions and 0 deletions
|
@ -227,6 +227,29 @@ const struct in_addr *net_if_ipv4_broadcast_addr(void)
|
|||
#endif
|
||||
}
|
||||
|
||||
bool net_if_ipv4_addr_mask_cmp(struct net_if *iface,
|
||||
struct in_addr *addr)
|
||||
{
|
||||
#if defined(CONFIG_NET_IPV4)
|
||||
uint32_t subnet = ntohl(addr->s_addr[0]) &
|
||||
ntohl(iface->ipv4.netmask.s_addr[0]);
|
||||
int i;
|
||||
|
||||
for (i = 0; i < NET_IF_MAX_IPV4_ADDR; i++) {
|
||||
if (!iface->ipv4.unicast[i].is_used ||
|
||||
iface->ipv4.unicast[i].address.family != AF_INET) {
|
||||
continue;
|
||||
}
|
||||
if ((ntohl(iface->ipv4.unicast[i].address.in_addr.s_addr[0]) &
|
||||
ntohl(iface->ipv4.netmask.s_addr[0])) == subnet) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
struct in6_addr *net_if_ipv6_get_ll(struct net_if *iface,
|
||||
enum net_addr_state addr_state)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue