randy newfield
randy newfield

Reputation: 1221

how to monitor bytes in/out network trafic in c (linux)

I wonder if there are functions for monitoring the number of bytes of network traffic that are going in/out on a linux machine.

I know that on windows you can use the PDH query data but I am not sure how to go about this on linux.

Any simple solutions or documents to work from would be appreciated.

Upvotes: 0

Views: 3927

Answers (2)

Rob Marrowstone
Rob Marrowstone

Reputation: 1264

netstat -s will give you a nice little summary of the packets in and out. You can change the formatting to suit your needs, or if you're looking for something where you can fine tune a little better, try tcpdump like most linux utils, you can get more info from their man pages, e.g. man netstat

Upvotes: 1

jørgensen
jørgensen

Reputation: 10549

Monitor the output of ip -s link. (Or, if you want to work with Netlink on a low-level fashion, you will have to send RTM_GETLINK messages and will find the result in the IFLA_STATS64 attribute.)

Upvotes: 1

Related Questions