How can I access Ethernet statistics from C/C++ code like netstat -e?
Interface Statistics
Received Sent
Bytes 21010071 15425579
Unicast packets 95512 94166
Non-unicast packets 12510 7
Discards 0 0
Errors 0 3
Unknown protocols 0
Let me answer to myself, as I asked the same on another forum.
WMI is good, but it's easier to use IpHlpApi instead:
You might find a feasable WMI performance counter, e.g. Win32_PerfRawData_Tcpip_NetworkInterface.
The WMI will provide those readings:
These classes are available on Windows XP or newer. You may have to resign to the matching "Win32_PerfRawData" classes on Windows 2000, and do a little bit more of math before you can display the output.
Find documentation on all of them in the MSDN.
See Google Groups, original netstats source code has been posted many times (win32 api)
A good place to start for network statistics would be the GetIpStatistics call in the Windows IPHelper functions.
There are a couple of other approaches that are possibly more portable:-
Szia,
from http://en.wikipedia.org/wiki/Netstat
MFC sample at CodeProject: http://www.codeproject.com/KB/applications/wnetstat.aspx