Jump to content



Photo

How to convert SocketToIP to C++?


  • Please log in to reply
2 replies to this topic

#1 E1M1

E1M1

    Newbie

  • Active Members
  • PipPipPipPipPipPip
  • 1,073 posts

Posted 01 August 2012 - 01:01 PM

I am having trouble with converting autoit function to c++.

Func SocketToIP($SHOCKET)     Local $sockaddr, $aRet     $sockaddr = DllStructCreate("short;ushort;uint;char[8]")     $aRet = DllCall("Ws2_32.dll", "int", "getpeername", "int", $SHOCKET, _             "ptr", DllStructGetPtr($sockaddr), "int*", DllStructGetSize($sockaddr))     If Not @error And $aRet[0] = 0 Then         $aRet = DllCall("Ws2_32.dll", "str", "inet_ntoa", "int", DllStructGetData($sockaddr, 3))         If Not @error Then $aRet = $aRet[0]     Else         $aRet = 0     EndIf     $sockaddr = 0     Return $aRet EndFunc   ;==>SocketToIP



This is what I've managed to do so far.
    struct mystruct{         short a; unsigned short b; unsigned int c; char d[8];     };     int struct_size = sizeof(mystruct);     getpeername(s, &mystruct, &struct_size);


Error I get: type name is not allowed.
edited







#2 Manadar

Manadar

    Taking a REST.

  • MVPs
  • 10,714 posts

Posted 01 August 2012 - 01:13 PM

It sounds lame, but Google is your friend: http://www.wiredrevolution.com/c/find-ip-address-from-remote-end-of-a-tcp-socket

You think you're the first to ever need this in C++? : )

#3 E1M1

E1M1

    Newbie

  • Active Members
  • PipPipPipPipPipPip
  • 1,073 posts

Posted 01 August 2012 - 01:38 PM

Thanks
edited




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users