Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use tcp_diag with C++?

Tags:

c++

linux

tcp

I've googled this all over the place, and I'm still at a loss. tcp_diag is supposed to replace /proc/net/tcp, but I can't find a shred of documentation on how to use it. Please tell me how to #include it, and what methods, classes and functions it has. Thanks!

like image 803
Thoughtful Dragon Avatar asked Oct 27 '25 21:10

Thoughtful Dragon


1 Answers

You create a DGRAM socket with domain AF_NETLINK and protocol NETLINK_INET_DIAG. Then you use the netlink protocol to communicate with the kernel and get the information you need.

Further reading:

  • http://kristrev.github.io/2013/07/26/passive-monitoring-of-sockets-on-linux
  • http://www.linuxjournal.com/article/7356
  • https://git.kernel.org/cgit/linux/kernel/git/shemminger/iproute2.git/tree/misc/ss.c
like image 196
Arnout Engelen Avatar answered Oct 30 '25 13:10

Arnout Engelen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!