title: How to Monitor for Input Device Addition and Removal with a Linux Netlink Socket
body: <p>I want to be able to monitor for device removal and addition of input devices using linux netlink sockets. Scouring the web, I have found source code that reads a netlink socket message but does no parsing on its type or content and just prints a <em>&quot;message recieved&quot;</em> string.</p>
  <p>If I have <code>int fd = open(&quot;/dev/input/event0&quot;, O_RDONLY)</code>, how do I:</p>
  <ol>
  <li>Determine that the received <code>uevent</code> is related to this device. Or in case of a new addition, what the new device's path is.</li>
  <li>Determine that the type of the received <code>uevent</code> is indicating either an addition or deletion.</li>
  </ol>