mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2025-01-22 19:44:14 +01:00
rtnlutil: Add parser for ifaddrmsg struct
Its purpose is to extract interface label, ip, and broadcast addresses out of ifaddrmsg rntl message.
This commit is contained in:
parent
4e3e1fbf60
commit
f3f343c04b
@ -26,6 +26,7 @@
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <linux/rtnetlink.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <ell/ell.h>
|
||||
|
||||
@ -74,3 +75,38 @@ uint32_t rtnl_set_linkmode_and_operstate(struct l_netlink *rtnl, int ifindex,
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
void rtnl_ifaddr_extract(const struct ifaddrmsg *ifa, int bytes,
|
||||
char **label, char **ip, char **broadcast)
|
||||
{
|
||||
struct in_addr in_addr;
|
||||
struct rtattr *attr;
|
||||
|
||||
for (attr = IFA_RTA(ifa); RTA_OK(attr, bytes);
|
||||
attr = RTA_NEXT(attr, bytes)) {
|
||||
switch (attr->rta_type) {
|
||||
case IFA_LOCAL:
|
||||
if (!ip)
|
||||
break;
|
||||
|
||||
in_addr = *((struct in_addr *) RTA_DATA(attr));
|
||||
*ip = l_strdup(inet_ntoa(in_addr));
|
||||
|
||||
break;
|
||||
case IFA_BROADCAST:
|
||||
if (!broadcast)
|
||||
break;
|
||||
|
||||
in_addr = *((struct in_addr *) RTA_DATA(attr));
|
||||
*broadcast = l_strdup(inet_ntoa(in_addr));
|
||||
|
||||
break;
|
||||
case IFA_LABEL:
|
||||
if (!label)
|
||||
break;
|
||||
|
||||
*label = l_strdup(RTA_DATA(attr));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,3 +25,6 @@ uint32_t rtnl_set_linkmode_and_operstate(struct l_netlink *rtnl, int ifindex,
|
||||
l_netlink_command_func_t cb,
|
||||
void *user_data,
|
||||
l_netlink_destroy_func_t destroy);
|
||||
|
||||
void rtnl_ifaddr_extract(const struct ifaddrmsg *ifa, int bytes,
|
||||
char **label, char **ip, char **broadcast);
|
||||
|
Loading…
Reference in New Issue
Block a user