https://github.com/troglobit/nlmon
Simple example of how to use libnl and libev to monitor kernel netlink events
https://github.com/troglobit/nlmon
libev libnl linux netlink networking
Last synced: about 2 months ago
JSON representation
Simple example of how to use libnl and libev to monitor kernel netlink events
- Host: GitHub
- URL: https://github.com/troglobit/nlmon
- Owner: troglobit
- License: mit
- Created: 2021-05-26T15:25:41.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2022-06-07T11:18:50.000Z (almost 4 years ago)
- Last Synced: 2025-03-17T00:34:08.558Z (about 1 year ago)
- Topics: libev, libnl, linux, netlink, networking
- Language: C
- Homepage:
- Size: 5.86 KB
- Stars: 9
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
nlmon
=====
Simple example of how to use libnl and libev to monitor kernel netlink
events. Beware, there's a lot of boiler plate code you might not need.
Building
--------
To build and use nlmon, you need the libnl and libev libraries. On
Debian/Ubuntu and Linux Mint, the following command installs the
required development libraries and their runtime equivalents:
sudo apt install libnl-route-3-dev libnl-3-dev libev-dev
Provided the code of this project is cloned to `~/nlmon`, do:
cd ~/nlmon
gcc -o nlmon nlmon.c -I/usr/include/libnl3 -lnl-3 -lnl-route-3 -lev
or type `make` to let it call GCC for you.
Testing
-------
In one terminal window, run nlmon:
./nlmon -v
In another terminal window, create and delete a VETH pair:
sudo ip link add veth1 type veth peer name veth1-peer
sudo ip link del veth1
There should be output from nlmon in the first window:
./nlmon -v
nlmon: veth iface veth1 deleted
nlmon: veth iface veth1-peer deleted
nlmon: veth iface veth1-peer added
nlmon: veth iface veth1 added
Origin & References
-------------------
This project is based on a deprecated external netlink plugin for the
[finit][] init system. It was developed by various people at Westermo
over the years. It has since been replaced by a native plugin.
Brought back to life by [Joachim Wiberg][] for use as an example of how
to utilize libnl and libev.
[finit]: https://github.com/troglobit/finit
[Joachim Wiberg]: http://troglobit.com