Network library

From KolibriOS wiki
Jump to: navigation, search

Network Library

The KolibriOS network library implements some network related functions similar to those found in Unix/Windows.
Their function and API closely resembles these functions on other platforms.
Because of this, more information about these functions can be found in other guides suchs as Beej's guide to network programming.

All structures and error codes you need for these functions can be found in (in programs folder on SVN).


Convert the string from standard IPv4 dotted notation to integer IP addr.
Input: ptr to ASCIIZ string containing standard dotted IPv4 address.
Output: eax = converted IP address / -1 on error


; Code section:
        invoke inet_addr ip_address
; eax should now be 0x0100A8C0
; Data section:
        ip_address db '', 0


Convert the Internet host address to standard IPv4 dotted notation.
Input: in_addr struct (see for struct)
Output: eax = pointer to resulting string (in static buffer)

; Code section:
        invoke ntoa sockaddr1
; eax will now point to following data: db "", 0
; Data section:
        dw ?           ; address family
        dw ?           ; port
        dd 0x0100A8C0  ; IP address
        rb 8           ; zero


Get a list of IP addresses and port numbers for given host and service

  • ptr to hostname (optional)
  • ptr to servname (optional)
  • ptr to addrinfo struct hints (optional)
  • ptr to result addrinfo struct

Output: eax = 0 on success / one of EAI codes on error.
On success, the function will write the pointer to the addrinfo structure at the given address.
Structure definitions and error codes can be found in

; Code section
; resolve name
        invoke  getaddrinfo, hostname, 0, 0, result
; test for error
        test    eax, eax
        jnz     fail
; convert IP address to decimal notation
        mov     edi, [result]
        mov     eax, [edi+addrinfo.ai_addr] 
        invoke  inet_ntoa, [eax+sockaddr_in.sin_addr]
; write result
        invoke  con_write_asciiz, eax
; advance to next item
        mov     edi, [edi+addrinfo.ai_next]
        test    edi, edi
        jnz     addrloop
; free allocated memory
        invoke  freeaddrinfo, [result]
; Data section:
        hostname db '', 0
;        hostname db '', 0
        result   dd ?


Free one or more addrinfo structures returned by getaddrinfo.
Input: ptr to addrinfo struct
Output: /