4

I'm looking forward to create a network monitor by looking into the contents of /proc/net folder. It's my specific requirement that I can't do any packet sniffing or anything like that. All my source is /proc/net.For example I can get all the active TCP connection details from /proc/net/tcp etc.

The contents of these files keep on changing, so I want to read these files continuously but also I need to read only when it's contents changes, that is if there is no network connected the file contents won't change and I don't' need to read them.

I looked into inotify but it does not detect the changes in /proc/net/ files.

inotifywatch /proc/net/

Continuous polling I guess will be ineffective. So looking for a suggestion.. Thanks in advance..

3lokh
  • 891
  • 4
  • 17
  • 39
  • Hi @Nikhil, Were you able to monitor /proc/net? I am working on Android and need to monitor the /proc/net. But not able to do that. Any information will be of great help. – Suman Jun 30 '15 at 11:36

1 Answers1

0

Did you check the gio libraries? You can add a watch to an open file, and specify on which events you get a callback.

https://developer.gnome.org/glib/stable/glib-IO-Channels.html

Also, this might be of interest to you (it seems newer versions would have this patch already included):

https://gitorious.org/gnome-essentials/glib/commit/68f9255ec6434b25339cfd6055013e898730d0e7

https://www.google.com.ar/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&cad=rja&uact=8&ved=0CCEQFjAB&url=https%3A%2F%2Fmail.gnome.org%2Farchives%2Fcommits-list%2F2011-September%2Fmsg13539.html&ei=02qMVJ7cHse1sQTm2oKwDg&usg=AFQjCNEJpurm10iskmcHVkc81oAv8_7MLQ&sig2=e48bXfZxW_BwvNCjdpsfSw&bvm=bv.81828268,d.cWc

jcoppens
  • 5,306
  • 6
  • 27
  • 47
  • None of this helps to monitor changes in `/proc/net`, since `/proc` does not support change notifications through inotify and GIO doesn't poll `/proc/net` (the patch you link to is for `/proc/mounts`). – Gilles 'SO- stop being evil' Dec 14 '17 at 16:09