Hello,
You may try ***GetExtendedTcpTable ***function (iphlpapi.h) combined with GetPerTcpConnectionEStats or GetPerTcp6ConnectionEStats.
Detail information about the usage you may reference iphlpapi.h header:
https://learn.microsoft.com/en-us/windows/win32/api/iphlpapi/
Above are suggestions for your reference. More questions about the dev or code, we would recommend you post on specific dev forum.
Best Regards,
Karlie Weng
If the Answer is helpful, please click "Accept Answer" and upvote it.