sk_group_example.c

00001 #include <netlink/netlink.h>
00002 #include <netlink/socket.h>
00003 #include <netlink/msg.h>
00004 
00005 /*
00006  * This function will be called for each valid netlink message received
00007  * in nl_recvmsgs_default()
00008  */
00009 static int my_func(struct nl_msg *msg, void *arg)
00010 {
00011         return 0;
00012 }
00013 
00014 struct nl_sock *sk;
00015 
00016 /* Allocate a new socket */
00017 sk = nl_socket_alloc();
00018 
00019 /*
00020  * Notifications do not use sequence numbers, disable sequence number
00021  * checking.
00022  */
00023 nl_socket_disable_seq_check(sk);
00024 
00025 /*
00026  * Define a callback function, which will be called for each notification
00027  * received
00028  */
00029 nl_socket_modify_cb(sk, NL_CB_VALID, NL_CB_CUSTOM, my_func, NULL);
00030 
00031 /* Connect to routing netlink protocol */
00032 nl_connect(sk, NETLINK_ROUTE);
00033 
00034 /* Subscribe to link notifications group */
00035 nl_socket_add_memberships(sk, RTNLGRP_LINK);
00036 
00037 /*
00038  * Start receiving messages. The function nl_recvmsgs_default() will block
00039  * until one or more netlink messages (notification) are received which
00040  * will be passed on to my_func().
00041  */
00042 while (1)
00043         nl_recvmsgs_default(sock);