Search code examples
cwindowsnetworkingethernetnetwork-monitoring

How can I access netstat-like Ethernet statistics from a Windows program


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

Solution

  • 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:-

    • SNMP. Requires SNMP to be enabled on the computer, but can obviously be used to retrieve statistics for remote computers also.
    • Pipe the output of 'netstat' into your application, and unpick the values from the text.