J'utilise netlink
pour obtenir des interfaces, ses noms, types, etc., mais je ne peux pas obtenir l'adresse L2 (ugly_data
est nlmsghdr*
):Comment obtenir l'adresse L2 du lien réseau via netlink?
struct ifinfomsg *iface;
struct rtattr *attribute;
int len;
iface = (struct ifinfomsg *) NLMSG_DATA(ugly_data);
len = ugly_data->nlmsg_len - NLMSG_LENGTH(sizeof(*iface));
for (attribute = IFLA_RTA(iface);
RTA_OK(attribute, len);
attribute = RTA_NEXT(attribute, len))
{
id_ = iface->ifi_index;
// get type
switch (iface->ifi_type)
{
case ARPHRD_ETHER:
type_ = "Ethernet";
break;
case ...
}
// get attributes
switch (attribute->rta_type)
{
case IFLA_IFNAME:
name_ = (char *) RTA_DATA(attribute);
break;
case IFLA_ADDRESS:
address_ = (char *) RTA_DATA(attribute);
break;
...
}
}
type_
, id_
et name_
contiennent des valeurs de droite, même que je obtenu à partir de ifconfig
, mais address_
est toujours vide. Qu'est-ce que je fais de mal et comment obtenir des adresses?