インターフェイス、その名前、タイプなどを取得するために使用netlink
していますが、L2 アドレスを取得できません ( ugly_data
is nlmsghdr*
):
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_
とname_
同じように、正しい値が含まれていますが、ifconfig
常にaddress_
空です。何が間違っているのか、アドレスを取得する方法は?