Jump to content
Sign in to follow this  
daslick

SocketToIP problem? tried int*

Recommended Posts

daslick

This is what I have for the function's code:

Func SocketToIP($SHOCKET)
    Local $sockaddr = DLLStructCreate("short;ushort;uint;char[8]")
    Local $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

in context, this is the simple program I am TRYING to start...

#include <GuiConstants.au3>
#include <Array.au3>

TCPStartup()
$listen = TCPListen(@IPAddress1,1029,10)
$socket = _ArrayCreate(0,0,0,0,0,0,0,0,0,0)

$gui = GUICreate("",200,400,400,300)
Opt("GUIOnEventMode", 1)
GUISetState(@SW_SHOW)
$list = GUICtrlCreateList("",5,5,190,100)
;GUICtrlSetOnEvent($okbutton, "OKButton")
GUICtrlSetLimit(-1,200)
GUISetOnEvent($GUI_EVENT_CLOSE, "close")

While 1
    ToolTip($listen & " | " & $socket[0]&','&$socket[1]&','&$socket[2])
    For $i in $socket
    if $i < 1 then
        $i = TCPAccept($listen)
        if $i > 0 Then
            local $ip = SocketToIP($socket)
            GUICtrlSetData($list, $ip)
        EndIf
        ExitLoop
    EndIf
    Next
WEnd

Func SocketToIP($SHOCKET)
    Local $sockaddr = DLLStructCreate("short;ushort;uint;char[8]")
    Local $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

Func close()
    Exit
EndFunc

It is still not working. Can someone test this code and see if it works for them?

Edited by daslick

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.