1

On Win10 I can run get-netinterface in powershell to display InterfaceMetric for each interface. Is there a C/C++ Win API that would let me retrieve it programmatically?

The metric can be set in adapter's TCP/IP settings:

enter image description here

bj chrome
  • 65
  • 6
  • _"Is there a C/C++ Win API"_ There's the C Winsock API, yes. Any particular question about that? Here's one question I found: https://stackoverflow.com/questions/9249886/how-to-link-winsock-lib – πάντα ῥεῖ May 27 '21 at 19:10
  • 1
    Which specific function in Winsock API will give me interface metric? – bj chrome May 27 '21 at 19:15
  • There is no WinSock function to get this information. There is, however, an [IP Helper function](https://learn.microsoft.com/en-us/windows/win32/api/iphlpapi/nf-iphlpapi-getadaptersaddresses) that can. – Remy Lebeau May 27 '21 at 19:16
  • I'm not quite sure why the question was so quickly downgraded. Should I have listed all the [useless] APIs/functions that I looked at to 'show research effort'? And what is not clear in the question? Could you please help me understand the reason for the downgrade so I could be better next time I post a question? – bj chrome May 27 '21 at 19:19
  • @RemyLebeau The helper function might be exactly what I was looking for. It returns Ipv4Metric and IpV6Metric. – bj chrome May 27 '21 at 19:29

1 Answers1

1

Is there a C/C++ Win API that would let me retrieve [InterfaceMetric] programmatically?

Use GetAdaptersAddresses(). See the Ipv4Metric and Ipv6Metric members of the IP_ADAPTER_ADDRESSES struct.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770