7 #include <libmnl/libmnl.h>
9 #include <linux/if_link.h>
10 #include <linux/rtnetlink.h>
12 static int data_attr_cb(
const struct nlattr *attr,
void *data)
14 const struct nlattr **tb = data;
24 perror(
"mnl_attr_validate");
30 perror(
"mnl_attr_validate2");
39 static int data_cb(
const struct nlmsghdr *nlh,
void *data)
41 struct nlattr *tb[IFLA_MAX+1] = {};
44 printf(
"index=%d type=%d flags=%d family=%d ",
45 ifm->ifi_index, ifm->ifi_type,
46 ifm->ifi_flags, ifm->ifi_family);
48 if (ifm->ifi_flags & IFF_RUNNING)
51 printf(
"[NOT RUNNING] ");
57 if (tb[IFLA_IFNAME]) {
67 char buf[MNL_SOCKET_BUFFER_SIZE];
71 unsigned int seq, portid;
74 nlh->nlmsg_type = RTM_GETLINK;
75 nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP;
76 nlh->nlmsg_seq = seq = time(NULL);
78 rt->rtgen_family = AF_PACKET;
82 perror(
"mnl_socket_open");
87 perror(
"mnl_socket_bind");
93 perror(
"mnl_socket_send");
99 ret =
mnl_cb_run(buf, ret, seq, portid, data_cb, NULL);
100 if (ret <= MNL_CB_STOP)