net: if: Add function to obtain IPv4 netmask
Add a helper function to obtain IPv4 netmask configured on an interface. Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This commit is contained in:
parent
1d14f13d75
commit
db80ed3e8d
|
@ -2279,6 +2279,15 @@ struct in_addr *net_if_ipv4_get_ll(struct net_if *iface,
|
||||||
struct in_addr *net_if_ipv4_get_global_addr(struct net_if *iface,
|
struct in_addr *net_if_ipv4_get_global_addr(struct net_if *iface,
|
||||||
enum net_addr_state addr_state);
|
enum net_addr_state addr_state);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get IPv4 netmask of an interface.
|
||||||
|
*
|
||||||
|
* @param iface Interface to use.
|
||||||
|
*
|
||||||
|
* @return The netmask set on the interface, unspecified address if not found.
|
||||||
|
*/
|
||||||
|
struct in_addr net_if_ipv4_get_netmask(struct net_if *iface);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set IPv4 netmask for an interface.
|
* @brief Set IPv4 netmask for an interface.
|
||||||
*
|
*
|
||||||
|
|
|
@ -3619,6 +3619,27 @@ static inline int z_vrfy_net_if_ipv4_addr_lookup_by_index(
|
||||||
#include <syscalls/net_if_ipv4_addr_lookup_by_index_mrsh.c>
|
#include <syscalls/net_if_ipv4_addr_lookup_by_index_mrsh.c>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
struct in_addr net_if_ipv4_get_netmask(struct net_if *iface)
|
||||||
|
{
|
||||||
|
struct in_addr netmask = { 0 };
|
||||||
|
|
||||||
|
net_if_lock(iface);
|
||||||
|
|
||||||
|
if (net_if_config_ipv4_get(iface, NULL) < 0) {
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!iface->config.ip.ipv4) {
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
netmask = iface->config.ip.ipv4->netmask;
|
||||||
|
out:
|
||||||
|
net_if_unlock(iface);
|
||||||
|
|
||||||
|
return netmask;
|
||||||
|
}
|
||||||
|
|
||||||
void net_if_ipv4_set_netmask(struct net_if *iface,
|
void net_if_ipv4_set_netmask(struct net_if *iface,
|
||||||
const struct in_addr *netmask)
|
const struct in_addr *netmask)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue