title: Netlink implementation for the Android NDK
body: <p>I have a requirement for similar task as mentioned in <a href="https://kristrev.github.io/2013/07/26/passive-monitoring-of-sockets-on-linux/" rel="nofollow">this link.</a>. Passive monitoring of sockets in Android. One way is parsing the /proc/net/{tcp,udp,...} tables. But we have to keep on reading continuously for keep on monitoring; which is not efficient way. As it will be a mobile device app, it will eat up the battery as it requires CPU Time for keep on monitoring for time interval (say 1 sec).</p>
  
  <p>But, I am looking for an event based approach. As I googled about the same, I ended with NETLINK for monitoring the sockets. But I observe that Android NDK doesn't have support for the </p>
  
  <pre><code>#include &lt;linux/sock_diag.h&gt;
  #include &lt;linux/inet_diag.h&gt;
  #include &lt;linux/unix_diag.h&gt;
  #include &lt;linux/packet_diag.h&gt;
  #include &lt;linux/netlink_diag.h&gt;
  </code></pre>
  
  <p>Does anyone tried using NETLINK in Android for monitoring the INET sockets? If so please share the information.</p>
  
  <p>Thanks.</p>
  
  <hr>
  
  <p>UPDATE:
  I tried copy pasting the above mentioned files in the "jni" folder and built using ndk-build. Building was successful and also no crashes at the runtime. But, socket creation of type </p>
  
  <pre><code>socket(AF_NETLINK, SOCK_DGRAM, NETLINK_INET_DIAG)
  </code></pre>
  
  <p>is failing with error EACCES(13) - Permission to create a socket of the specified type and/or protocol is denied.</p>
  
  <p>Any suggestions how to proceed further?</p>