wfp redirector WSAIoctl(SIO_QUERY_WFP_CONNECTION_REDIRECT_CONTEXT) returns WSAEINVAL

I am implementing a WFP redirector based on https://github.com/microsoft/Windows-driver-samples/tree/master/network/trans/WFPSampler. Now driver redirects traffic successfully and i can recive redirected data in my proxy server, however i have problem with getting original desitnation address/port by WSAIoctl(SIO_QUERY_WFP_CONNECTION_REDIRECT_CONTEXT) which returns WSAEINVAL. I call WSAIoctl right after accept() returned successfully. Here is how i call it:

SOCKET s = accept(ListenSocket, NULL, NULL);
SOCKADDR_STORAGE *ss = (SOCKADDR_STORAGE *)new BYTE[sizeof(SOCKADDR_STORAGE)*2];
DWORD ret = 0;
int a = WSAIoctl(
s,
SIO_QUERY_WFP_CONNECTION_REDIRECT_CONTEXT,
NULL, 0, ss,
sizeof(SOCKADDR_STORAGE)*2, &ret,
NULL, NULL);

That looks fine, albeit SOCKADDR_STORAGE ss[2 * sizeof(SOCKADDR_STORAGE)]; would be better unless you specifically need heap.

  1. Have you read https://docs.microsoft.com/en-us/windows-hardware/drivers/network/using-bind-or-connect-redirection ?
  2. Are you setting the localRedirectTargetPid?
  3. Are you setting the localRedirectHandle?
  4. Are you on OS > Win7?