title: How to get notified about network interface changes with Netlist and RTMGRP_LINK signal?
body: <p>I write a program which needs to get notified if the network interfaces have changed, in particular new one appeared or existed one gone. My research brought to the <strong>netlink</strong> and its <code>RTMGRP_LINK</code> signal. This <a href="http://manpages.ubuntu.com/manpages/hardy/man7/netlink.7.html" rel="nofollow noreferrer">manpage</a> gives an example which is not clear for me yet. </p>
  
  <p>It has this code:</p>
  
  <pre><code>memset(&amp;sa, 0, sizeof(sa));
  snl.nl_family = AF_NETLINK;
  snl.nl_groups = RTMGRP_LINK | RTMGRP_IPV4_IFADDR;
  
  fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
  bind(fd, (struct sockaddr*)&amp;sa, sizeof(sa));
  </code></pre>
  
  <p>My understading is this is an initialization part to enable some signals. I guess there must be a handler subroutine which processes the event. </p>
  
  <p>My questions are: </p>
  
  <ul>
  <li><p>Is this a correct code snippet for enabling the event?</p></li>
  <li><p>How to process the event: do I need to have some handler?</p></li>
  <li><p>What are the data structures that contains a relevant information (about network interfaces and their changes)?</p></li>
  </ul>
  
  <p>Thanks for any help. </p>