LSP AcceptEx and getting the local and remote addresses

I am having a hard time trying to get the local and remote addresses in my LSP which intercepts AcceptEx. When I call GetAcceptExSockaddrs with the parameters passed to my AcceptEx function I get NULLs for all the addresses. Does anyone have any ideas?

This is the basic jist of the code.

Code Snippet

BOOL PASCAL FAR
ExtAcceptEx(
IN SOCKET sListenSocket,
IN SOCKET sAcceptSocket,
IN PVOID lpOutputBuffer,
IN DWORD dwReceiveDataLength,
IN DWORD dwLocalAddressLength,
IN DWORD dwRemoteAddressLength,
OUT LPDWORD lpdwBytesReceived,
IN LPOVERLAPPED lpOverlapped)
{
SOCKET_CONTEXT *ListenSocketContext = NULL;
SOCKET_CONTEXT *AcceptSocketContext = NULL;
sockaddr_in * localAddr = 0;
sockaddr_in * remoteAddr = 0;
int remote_addr_len = sizeof(sockaddr_in);
int local_addr_len = sizeof(sockaddr_in);
int rc = FALSE;

ListenSocketContext = FindSocketContext( sListenSocket );
...
AcceptSocketContext = FindSocketContext( sAcceptSocket );
...

GetAcceptExSockaddrs(lpOutputBuffer, dwReceiveDataLength, dwLocalAddressLength, dwRemoteAddressLength, (sockaddr **) &localAddr, &local_addr_len, (sockaddr **) &remoteAddr, &remote_addr_len);
//PROBLEM
//localAddr = 0
//remoteAddr = 0

....

rc = ListenSocketContext->Provider->NextProcTableExt.lpfnAcceptEx(
ListenSocketContext->Socket,
AcceptSocketContext->Socket,
lpOutputBuffer,
dwReceiveDataLength,
dwLocalAddressLength,
dwRemoteAddressLength,
lpdwBytesReceived,
lpOverlapped
);
...

return rc;
}

[1853 byte] By [MattyBoy4444] at [2008-1-9]
# 1

Hello,

You need to first retrieve the GetAcceptExSockaddrs extension function pointer (WSAID_GETACCEPTEXSOCKADDRS) from the lower provider, then use this function only "after the AcceptEx function from the lower provider has been successfully completed". In your code above, you' re calling GetAcceptExSockaddrs before calling the lower providers AcceptEx function, which is not the correct usage. I hope this helps.

OsmanErtugay-MSFT at 2007-10-3 > top of Msdn Tech,Windows Networking Development,Winsock Kernel (WSK)...
# 2

This DID work. But know I must not be understanding something correct.

I am writing an LSP which will deny access to certain remote IP's. When I am running MS FTP Server and I connect from another machine, the first time my ExtAcceptEx is called 5 times right when the FTP client tries to connect. I then disconnect the ftp client. If I connect again, ExtAcceptEx isn't called until AFTER the ftp client is disconnected. Note: I am running in debug mode and attaching to inetinfo.exe with stops in my ExtAcceptEx function to determine this.

How would I intercept every connection everytime when using a server that is using I/O completion ports, using an LSP?

Thanks, Matt

MattyBoy4444 at 2007-10-3 > top of Msdn Tech,Windows Networking Development,Winsock Kernel (WSK)...