Socket is invalid while hooking WSASend/WSARecv on the server
<p>I am hooking WSASend, and WSARecv in C++ using the same method I've used to hook the client's WSASend and WSARecv functions. In the client I am able to get the IP, Port, and Socket from the SOCKET structure passed by WSASend/WSARecv; however, for the server when I try to use getpeername or getsockname() they both return the error 10057 (Socket not connected)...</p>

<p>I'm fairly sure that the hook is correct on the server, since it prints the bytes successfully, and I'm also sure the socket SHOULD be valid seeing how client and server establish a successful connection.</p>

<p>Is there a way to resolve this problem by any other alternative methods? I've been looking around the internet to find a solution, but I haven't seen anyone with the same problem.</p>

<p>I've tried this:</p>

<pre><code>            sockaddr *address = new sockaddr;
            int peer_len;
            getpeername(s, address, &amp;peer_len);
            int err = WSAGetLastError();
            if(err==0)
            {
                char *Str = inet_ntoa(((sockaddr_in*)address)-&gt;sin_addr);
                printf("[%s", Str);
                printf(":%d]",ntohs(((sockaddr_in*)address)-&gt;sin_port));
            }
            else
            {
                printf("Error %i\n",err);
            }
</code></pre>

<p>(Using both getpeername and getsockname)Both result in the same socket not connected error.</p>

<p>I'm planning on using the packets the C++ dll gets and forward the information to the C# dll since it'll be easier to manage on that (for me anyways), but I'd need to distinguish each packet with it's socket id.</p>
