7 #include <libmnl/libmnl.h>
8 #include <linux/genetlink.h>
12 static int data_cb(
const struct nlmsghdr *nlh,
void *data)
14 printf(
"received event type=%d from genetlink group %d\n",
15 nlh->nlmsg_type, group);
19 int main(
int argc,
char *argv[])
22 char buf[MNL_SOCKET_BUFFER_SIZE];
26 printf(
"%s [group]\n", argv[0]);
29 group = atoi(argv[1]);
31 nl = mnl_socket_open(NETLINK_GENERIC);
33 perror(
"mnl_socket_open");
37 if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0) {
38 perror(
"mnl_socket_bind");
42 if (mnl_socket_setsockopt(nl, NETLINK_ADD_MEMBERSHIP, &group,
44 perror(
"mnl_socket_setsockopt");
48 ret = mnl_socket_recvfrom(nl, buf,
sizeof(buf));
50 ret = mnl_cb_run(buf, ret, 0, 0, data_cb, NULL);
53 ret = mnl_socket_recvfrom(nl, buf,
sizeof(buf));