I assume you've read the docs? and called setsockopt() on the socket
after the accept completes? and you're still having problems?
If not:
See:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/acceptex_2.asp
The key part of that page is "On Windows XP or later, once the AcceptEx
function completes and the SO_UPDATE_ACCEPT_CONTEXT option is set on the
accepted socket, the local address associated with the accepted socket
can also be retrieved using the getsockname function. Likewise, the
remote address associated with the accepted socket can be retrieved
using the getpeername function."
The code required is something like this:
if (SOCKET_ERROR == ::setsockopt(
acceptedSocket,
SOL_SOCKET,
SO_UPDATE_ACCEPT_CONTEXT,
(char *)&m_listeningSocket,
sizeof(m_listeningSocket)))
{
// handle error
}
and this should be done in the code that deals with the acceptex
completion packet, before you do much else with the socket...
--
Len Holgate - http://www.lenholgate.com
JetByte Limited - http://www.jetbyte.com
The right code, right now.
Contract Programming and Consulting Services.
Try to use the following API's to get the IP address:
AcceptEx()
GetAcceptExSockaddrs()
OR,
gethostname()
gethostbyname()
getpeername()
getsockname()
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/acceptex_2.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/gethostname_2.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/gethostbyname_2.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/getpeername_2.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/getsockname_2.asp
Hope these information helps,
Kellie.
"Len Holgate" <Len.H...@jetbyte.com> wrote in message
news:43201905$0$12920$cc9e...@news.dial.pipex.com...
I assume you're using AcceptEx in 'accept and read' rather than just in
'overlapped accept' mode and the client is not sending data when it
should...
I don't think there IS a documented way to determine the peer address
before the connection completes. However you could try using setsockopt
(SO_UPDATE_ACCEPT_CONTEXT) as detailed in the previous reply on the
socket after you have determined that it has accepted using getsockopt
(SO_CONNECT_TIME) but before the acceptex has completed... It's not
documented and I've never tried it and I don't expect it to work but you
could give it a go...
Why do you need to do this?
Have you used the API GetTcpTable() ?
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iphlp/iphlp/gettcptable.asp
Kellie.