Getting Socket Descriptor from recv/send hooked function

Oct 25, 2013 at 6:44 PM
I have my hooked recv funtion.
 int MyRecv(IntPtr socketHandle, IntPtr buf, int count, int socketFlags)
     {
         int bytesCount = recv(socketHandle, buf, count, socketFlags);
         //Interface.mensajes("Recv: " + str);
         if (bytesCount > 0)
         {
             byte[] newBuffer = new byte[bytesCount];
             Marshal.Copy(buf, newBuffer, 0, bytesCount);
             //string r = System.Text.UTF7Encoding.ASCII.GetString(newBuffer);
             string r = System.Text.ASCIIEncoding.ASCII.GetString(newBuffer);
             //Main This = (Main)HookRuntimeInfo.Callback;
             lock (recep)
             {
                 sockaddr address = new sockaddr();
                 int namelen = 0x10;
                 int num2 = getpeername(socketHandle, ref address, ref namelen);
                 string str = address.sin_addr.sin_addr[0].ToString() + "." + address.sin_addr.sin_addr[1].ToString() + "." + address.sin_addr.sin_addr[2].ToString() + "." + address.sin_addr.sin_addr[3].ToString() + ":" + address.sin_port.ToString();
                 string sarasa = Marshal.PtrToStringAnsi(socketHandle);
                 recep.Push("|" + str + "|" + r + "sarasa: " + sarasa);
             }
         }
         return bytesCount;
     }
What I want is to obtain the Socket Descriptor in order to bind to that socket. How can I do this, what I have is the Integer Pointer to that socket. How can I obtain that data?
I am trying to gather that information with this
                 string sarasa = Marshal.PtrToStringAnsi(socketHandle);
but it is useless.

Can anyone give me some advise?

Thanks