Jump to content

TCPAccept get ip when the client connects?


Recommended Posts

Read the title! Also i cannot have the client send the ip i need to get it when they connect before the client sends anything.

[quote name='PsaltyDS' post='635433' date='Jan 27 2009, 07:04 AM']Larry is a mass murderer?! It's always the quiet, clean cut, bald guys... [/quote]

Link to comment
Share on other sites

Hello Lar i was unable to find that function in the help file or on the forums.

Well actually i found this where the person uses the function but he is not defining it... #113353

Edited by MerkurAlex

[quote name='PsaltyDS' post='635433' date='Jan 27 2009, 07:04 AM']Larry is a mass murderer?! It's always the quiet, clean cut, bald guys... [/quote]

Link to comment
Share on other sites

; Function to return IP Address from a connected socket.
;----------------------------------------------------------------------
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), "ptr", 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

Under TCPRecv in the helpfile.

Acutally the help file fails.

Edited by Glyph

tolle indicium

Link to comment
Share on other sites

... Brilliant lol thanks.

Actually not brilliant... it returns 0 everytime.

Edited by MerkurAlex

[quote name='PsaltyDS' post='635433' date='Jan 27 2009, 07:04 AM']Larry is a mass murderer?! It's always the quiet, clean cut, bald guys... [/quote]

Link to comment
Share on other sites

Func _TCP_Server_ClientIP($hSocket)
    
    Local $pSocketAddress, $aReturn
    
    $pSocketAddress = DllStructCreate("short;ushort;uint;char[8]")
    $aReturn = DllCall("Ws2_32.dll", "int", "getpeername", "int", $hSocket, "ptr", DllStructGetPtr($pSocketAddress), "int*", DllStructGetSize($pSocketAddress))
    If @error Or $aReturn[0] <> 0 Then Return 0
    
    $aReturn = DllCall("Ws2_32.dll", "str", "inet_ntoa", "int", DllStructGetData($pSocketAddress, 3))
    If @error Then Return 0
    
    $pSocketAddress = 0
    
    Return $aReturn[0]
    
EndFunc

Link to comment
Share on other sites

Func _TCP_Server_ClientIP($hSocket)
    
    Local $pSocketAddress, $aReturn
    
    $pSocketAddress = DllStructCreate("short;ushort;uint;char[8]")
    $aReturn = DllCall("Ws2_32.dll", "int", "getpeername", "int", $hSocket, "ptr", DllStructGetPtr($pSocketAddress), "int*", DllStructGetSize($pSocketAddress))
    If @error Or $aReturn[0] <> 0 Then Return 0
    
    $aReturn = DllCall("Ws2_32.dll", "str", "inet_ntoa", "int", DllStructGetData($pSocketAddress, 3))
    If @error Then Return 0
    
    $pSocketAddress = 0
    
    Return $aReturn[0]
    
EndFunc
Hah, The helpfile should be fixed. Thank-you for sharing that code with us!

I remember seeing that fix before, but it slipped my mind!

Edited by Glyph

tolle indicium

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...