Iam trying to drop an established tcp connection and I am using SetTcpEntry
function. But its returning with 317 value which says “The function is unable to set the TCP entry since the application is running non-elevated.” But my application is running with admin previlage. What could be the reason.
MIB_TCPROW_LH sKillConn;
sKillConn.dwLocalAddr = ulLocIP;
sKillConn.dwLocalPort = usLocalPort;
sKillConn.dwRemoteAddr = ulRemIP;
sKillConn.dwRemotePort = usRemPort;
sKillConn.dwState = MIB_TCP_STATE_DELETE_TCB;
// Load iphlpapi.dll and get the SetTcpEntry function
HMODULE iphlpapi = LoadLibrary("iphlpapi.dll");
if (!iphlpapi) {
printf("Failed to load iphlpapi.dlln");
return;
}
FARPROC setTcpEntry = GetProcAddress(iphlpapi, "SetTcpEntry");
if (!setTcpEntry) {
printf("Failed to get SetTcpEntry addressn");
FreeLibrary(iphlpapi);
return;
}
// Call SetTcpEntry
DWORD ret = ((DWORD(WINAPI*)(PMIB_TCPROW_LH))setTcpEntry)(&sKillConn);
if (ret == NO_ERROR) {
printf("TCP connection killed successfully.n");
} else {
printf("Failed to kill TCP connection. Error: %ldn", ret);
}
2