Skip to content

Instantly share code, notes, and snippets.

@utky
Created September 1, 2019 12:03
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save utky/de8b37756f8664d0045f829292657ae5 to your computer and use it in GitHub Desktop.
Save utky/de8b37756f8664d0045f829292657ae5 to your computer and use it in GitHub Desktop.
Example which communicates with Linux Netlink subsystem to fetch interface information
@cmcqueen
Copy link

cmcqueen commented Sep 1, 2021

Testing with Ubuntu 20.04 running Linux 5.11.0...

I get "Operation not permitted" if I don't run this as root/sudo. But if I comment out line 35 sa.nl_pid = pid; I can run it fine as a non-root/sudo.

I get information for all interfaces, not just the one named on the command line. If I remove NLM_F_DUMP on line 58, then it gives information for just the named interface.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment