Discussion:
LSP AcceptEx and getting the local and remote addresses
(too old to reply)
m***@gmail.com
2007-09-13 17:08:30 UTC
Permalink
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.

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;
}
Arkady Frenkel
2007-09-14 04:29:19 UTC
Permalink
Just additional question : do you see any problems with connection when
your LSP work ? If you succeed to send/receive data, that IP/ports should be
seen in LSP, OTOH
you can just use GetTcpTable() for that
Arkady
Post by m***@gmail.com
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.
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;
}
m***@gmail.com
2007-09-16 05:32:50 UTC
Permalink
I got the answer from someone at Microsoft. GetAcceptSockaddrs needs
to be called after the base lpnfAcceptEx is called. Plus it needs to
be called from the base provider.

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?
Arkady Frenkel
2007-09-17 08:20:38 UTC
Permalink
You can close socket after acception too, even without
LSP but in app itself
Arkady
Post by m***@gmail.com
I got the answer from someone at Microsoft. GetAcceptSockaddrs needs
to be called after the base lpnfAcceptEx is called. Plus it needs to
be called from the base provider.
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?
Loading...