Запутался с getaddrinfo на fasm

Applications development, KoOS API questions
  • "Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." Albert Einstein
  • Спасибо за ответ немного прояснилась ситуация,
    В дебагере прошелся по программе, тормозит на загруженной функции,точнее ее там нет, видимо в загрузке чтото сделал не так.Вот код загрузки функции

    Code: Select all

     stdcall dll.Load, @IMPORT
            test    eax, eax
            jnz     exit
    
    
    @IMPORT:
     
    library network, 'network.obj'
    import  network,        \
            getaddrinfo,    'getaddrinfo'
    
    может кто-нибудь поможет найти ошибку, может чтото упустил


    ------------------------------------------



    Thanks for the answer a little clarified the situation,
    In the debugger paced program, brakes on the loaded function, or rather it is not there, probably something in the boot did not tak.Vot boot code function

    Code: Select all

     
    stdcall dll.Load,IMPORT
             test eax, eax
             jnz exit
    
    
    IMPORT:
     
    library network, 'network.obj'
    import network, \
             getaddrinfo, 'getaddrinfo'
    
    can anyone help find the error may have missed something
  • Can you provide full code please?

    Perhaps you forgot to init heap (mcall 68, 11)
    "Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." Albert Einstein
  • Spoiler:format binary as "" ; Binary file format without extension

    use32 ; Tell compiler to use 32 bit instructions

    org 0x0 ; the base address of code, always 0x0

    ; The header

    db 'MENUET01'
    dd 0x01
    dd START
    dd I_END
    dd 0x100000
    dd 0x7fff0
    dd 0, 0

    ; The code area

    include 'macros.inc'
    include 'proc32.inc'
    include 'dll.inc'
    ;purge mov
    socket fix 75,0
    SOCK_STREAM =1
    AF_INETV4 =2
    getsockopt fix 75,9
    START: ; start of execution
    stdcall dll.Load,@IMPORT

    call draw_window ; draw the window

    ; After the window is drawn, it's practical to have the main loop.
    ; Events are distributed from here.

    event_wait:
    mov eax, 10 ; function 10 : wait until event
    mcall ; event type is returned in eax

    cmp eax, 1 ; Event redraw request ?
    je red ; Expl.: there has been activity on screen and
    ; parts of the applications has to be redrawn.

    cmp eax, 2 ; Event key in buffer ?
    je key ; Expl.: User has pressed a key while the
    ; app is at the top of the window stack.

    cmp eax, 3 ; Event button in buffer ?
    je button ; Expl.: User has pressed one of the
    ; applications buttons.

    jmp event_wait

    ; The next section reads the event and processes data.

    red: ; Redraw event handler
    call draw_window ; We call the window_draw function and
    jmp event_wait ; jump back to event_wait

    key: ; Keypress event handler
    mov eax, 2 ; The key is returned in ah. The key must be
    mcall ; read and cleared from the system queue.
    jmp event_wait ; Just read the key, ignore it and jump to event_wait.

    button: ; Buttonpress event handler
    mov eax,17 ; The button number defined in window_draw
    mcall ; is returned to ah.

    cmp ah,1 ; button id=1 ?
    jne noclose
    mov eax,-1 ; Function -1 : close this program
    mcall

    noclose:
    jmp event_wait ; This is for ignored events, useful at development

    ; *********************************************
    ; ****** WINDOW DEFINITIONS AND DRAW ********
    ; *********************************************
    ;
    ; The static window parts are drawn in this function. The window canvas can
    ; be accessed later from any parts of this code (thread) for displaying
    ; processes or recorded data, for example.
    ;
    ; The static parts *must* be placed within the fn 12 , ebx = 1 and ebx = 2.

    draw_window:
    mov eax, 12 ; function 12: tell os about windowdraw
    mov ebx, 1 ; 1, start of draw
    mcall

    mov eax, 0 ; function 0 : define and draw window
    mov ebx, 100 * 65536 + 300 ; [x start] *65536 + [x size]
    mov ecx, 100 * 65536 + 120 ; [y start] *65536 + [y size]
    mov edx, 0x14ffffff ; color of work area RRGGBB
    ; 0x02000000 = window type 4 (fixed size, skinned window)
    mov esi, 0x808899ff ; color of grab bar RRGGBB
    ; 0x80000000 = color glide
    mov edi, title
    mcall
    call connect

    mov ebx, 25 * 65536 + 35 ; draw info text with function 4
    mov ecx, 0x224466
    mov edx, text
    mov esi, 40
    mov eax, 4

    .newline: ; text from the DATA AREA
    mcall

    add ebx, 10
    add edx, 40
    cmp byte[edx], 0
    jne .newline


    mov eax, 12 ; function 12:tell os about windowdraw
    mov ebx, 2 ; 2, end of draw
    mcall
    ret


    connect:
    invoke getaddrinfo url 0 0 request
    cmp eax,-1
    je .error


    mcall socket,AF_INETV4,SOCK_STREAM,0
    cmp eax,-1
    je .error

    mov [socketnum],eax
    mov ebx, 25 * 65536 + 75 ; draw info text with function 4
    mov ecx, 0x224466
    mov edx, ok
    mov esi, 2
    mov eax, 4
    mcall
    ret

    .error:

    mov ebx, 25 * 65536 + 75 ; draw info text with function 4
    mov ecx, 0x224466
    mov edx, error
    mov esi, 5
    mov eax, 4
    mcall
    ret

    ; *********************************************
    ; ************* DATA AREA *****************
    ; *********************************************
    ;
    ; Data can be freely mixed with code to any parts of the image.
    ; Only the header information is required at the beginning of the image.

    text db "It looks like you have just compiled "
    db "your first program for KolibriOS. "
    db " "
    db "Congratulations! ", 0

    title db "Example application", 0
    error db "error",0

    ok db "ok",0
    url db "http://www.yandex.ru",0


    socketnum dd ?
    sockaddr:
    dw AF_INETV4
    .port dw 80
    .ip dd 0
    rb 0
    align 4
    @IMPORT:
    library network,"network.obj"
    import network, \
    getaddrinfo,'getaddrinfo'


    I_END:
  • 1. You forgot to init heap ( system function 68, 11) which is necessary when working with libraries.

    2. The code you provided did not compile because 'request' is undefined, and you forgot commas between arguments of getaddrinfo function.

    3. For getaddrinfo function to work, you still lack some code.
    Basically, you tell getaddrinfo where it should write result pointer.
    (In most applications this is done on the stack)
    Getaddrinfo does not return IP address but it returns a pointer to a structure.
    The first answer will be located at [address_to_returned_structure+addrinfo.ai_addr].
    If we mov this into eax, we can now you find the IP address of this first answer in [eax + sockaddr_in.sin_addr]
    When done working with this struct, you must free it using freeaddrinfo function from the library.
    "Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." Albert Einstein
  • Who is online

    Users browsing this forum: No registered users and 22 guests