rtnl_link_get_kernel()

Thomas Graf tgraf at suug.ch
Mon Jul 9 16:49:31 EDT 2012


On Mon, Jul 09, 2012 at 10:14:43AM -0600, Wouter Verhelst wrote:
> Yes, if I do use the cache it's easy. But since I want to do my own
> cache management, I had preferred not doing it that way.
> 
> Do you mean to say that's not possible with libnl?

You don't have to use caches at all. You are free to implement
the collection data type yourself.

The following is typed from memory and may or may not compile or
work. You will get the idea.

   static int handle_object(struct nl_object *obj, void *arg)
   {
      /* you should see an address object here */
   }

   static int my_parser(struct nl_msg *msg, void *arg)
   {
      /* automatically parse message according to message type */
      nl_msg_parse(msg, handle_object, NULL);
   }

   /* request a address dump */
   nl_rtgen_request(sock, RTM_GETADDR, AF_UNSPEC, NLM_F_DUMP);

   /* pass incomming messages to my_parser */
   nl_socket_modify_cb(sock, NL_CB_VALID, NL_CB_CUSTOM, &my_parser, NULL);

   /* receive messages */
   nl_recvmsgs_default(sock);

~Thomas



More information about the libnl mailing list