Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void f()
- {
- std::unique_ptr<MIB_TCPTABLE_OWNER_PID> buffer;
- DWORD ret = 0;
- DWORD dwSize = 0;
- do
- {
- buffer = std::unique_ptr<MIB_TCPTABLE_OWNER_PID>(new MIB_TCPTABLE_OWNER_PID[dwSize]());
- ret = GetExtendedTcpTable(buffer.get(), &dwSize, TRUE, AF_INET, TCP_TABLE_OWNER_PID_ALL, 0);
- } while (ret == ERROR_INSUFFICIENT_BUFFER);
- PMIB_TCPTABLE_OWNER_PID ptTable;
- if (ret == ERROR_SUCCESS)
- {
- ptTable = (PMIB_TCPTABLE_OWNER_PID)buffer.get();
- }
- else
- {
- return;
- }
- for (DWORD i = 0; i < ptTable->dwNumEntries; i++)
- {
- MIB_TCPROW row;
- row.dwLocalAddr = ptTable->table[i].dwLocalAddr;
- row.dwLocalPort = ptTable->table[i].dwLocalPort;
- row.dwRemoteAddr = ptTable->table[i].dwRemoteAddr;
- row.dwRemotePort = ptTable->table[i].dwRemotePort;
- row.dwState = ptTable->table[i].dwState;
- if (row.dwRemoteAddr != 0)
- {
- ULONG rosSize = 0, rodSize = 0;
- ULONG winStatus;
- PUCHAR ros = NULL;// , rod = NULL;
- std::shared_ptr<UCHAR> rod;
- rodSize = sizeof(TCP_ESTATS_DATA_ROD_v0);
- PTCP_ESTATS_DATA_ROD_v0 dataRod = { 0 };
- if (rosSize != 0)
- {
- ros = (PUCHAR)malloc(rosSize);
- if (ros == NULL)
- {
- wprintf(L"\nOut of memory");
- return;
- }
- else
- memset(ros, 0, rosSize); // zero the buffer
- }
- if (rodSize != 0)
- {
- rod = std::shared_ptr<UCHAR>(new UCHAR[rodSize]());
- if (rod == NULL)
- {
- free(ros);
- wprintf(L"\nOut of memory");
- return;
- }
- }
- winStatus = GetPerTcpConnectionEStats((PMIB_TCPROW)&row, TcpConnectionEstatsData, NULL, 0, 0, ros, 0, rosSize, rod.get(), 0, rodSize);
- dataRod = (PTCP_ESTATS_DATA_ROD_v0)rod.get();
- PTCP_ESTATS_BANDWIDTH_ROD_v0 bandwidthRod = { 0 };
- rodSize = sizeof(TCP_ESTATS_BANDWIDTH_ROD_v0);
- if (rodSize != 0)
- {
- rod = std::shared_ptr<UCHAR>(new UCHAR[rodSize]());
- }
- winStatus = GetPerTcpConnectionEStats((PMIB_TCPROW)&row, TcpConnectionEstatsBandwidth, NULL, 0, 0, ros, 0, rosSize, rod.get(), 0, rodSize);
- bandwidthRod = (PTCP_ESTATS_BANDWIDTH_ROD_v0)rod.get();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement