Info Posted August 19, 2011 Posted August 19, 2011 (edited) Func _SocketGetIP($Data) Local $Struct, $Return $Struct = DllStructCreate('short;ushort;uint;char[8]') $Return = DllCall('Ws2_32.dll', 'int', 'getpeername', 'int', $Data, 'ptr', DllStructGetPtr($Struct), 'int*', DllStructGetSize($Struct)) If @error Or $Return[0] <> 0 Then Return 0 $Return = DllCall('Ws2_32.dll', 'str', 'inet_ntoa', 'int', DllStructGetData($Struct, 3)) If @error Then Return 0 $Struct = 0 Return $Return[0] EndFunc ;==>_SocketGetIP Here's my attempt bool GetSocketIP(const SOCKET &socket, char *sBuffer) { sockaddr sa; ZeroMemory(&sa, sizeof sa); int iLen = sizeof sa; if( getpeername(socket, &sa, &iLen) != 0 ) return false; strcpy(sBuffer, inet_ntoa(reinterpret_cast<sockaddr_in*>(&sa)->sin_addr)); return true; } Thanks Edit: Forgot to say, the C++ functions isn't really like the AutoIt one because of the return values and the parameters and stuff, but you get the idea. Edited August 19, 2011 by Info
jaberwacky Posted August 19, 2011 Posted August 19, 2011 Info, we would need more info. Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum?
Info Posted August 19, 2011 Author Posted August 19, 2011 Hehe nvm, got it to work. bool tcp_server::GetSocketIP(const SOCKET &socket, char *sBuffer)//might only work for ipv4, don't know why { sockaddr sa; ZeroMemory(&sa, sizeof sa); int iLen = sizeof sa; if( getpeername(socket, &sa, &iLen) != 0 ) return false; strcpy(sBuffer, inet_ntoa(reinterpret_cast<sockaddr_in*>(&sa)->sin_addr)); return true; }
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now